mirror of
https://github.com/Xahau/xahau.js.git
synced 2026-04-29 15:37:50 +00:00
refactor: move hasNextPage from Client to utils (#1715)
* add hasNextPage * remove unused util * add tests * remove hasNextPage from client
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
import { assert } from 'chai'
|
||||
|
||||
import { Client } from 'xrpl-local'
|
||||
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
|
||||
describe('client.hasNextPage', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
it('returns true when there is another page', async function () {
|
||||
this.mockRippled.addResponse('ledger_data', rippled.ledger_data.first_page)
|
||||
const response = await this.client.request({ command: 'ledger_data' })
|
||||
assert(Client.hasNextPage(response))
|
||||
})
|
||||
|
||||
it('returns false when there are no more pages', async function () {
|
||||
const rippledResponse = function (
|
||||
request: Request,
|
||||
): Record<string, unknown> {
|
||||
if ('marker' in request) {
|
||||
return rippled.ledger_data.last_page
|
||||
}
|
||||
return rippled.ledger_data.first_page
|
||||
}
|
||||
this.mockRippled.addResponse('ledger_data', rippledResponse)
|
||||
const response = await this.client.request({ command: 'ledger_data' })
|
||||
const responseNextPage = await this.client.requestNextPage(
|
||||
{ command: 'ledger_data' },
|
||||
response,
|
||||
)
|
||||
assert(!Client.hasNextPage(responseNextPage))
|
||||
})
|
||||
})
|
||||
@@ -1,6 +1,6 @@
|
||||
import { assert } from 'chai'
|
||||
|
||||
import { Client } from 'xrpl-local'
|
||||
import { hasNextPage } from 'xrpl-local'
|
||||
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
@@ -36,7 +36,7 @@ describe('client.requestNextPage', function () {
|
||||
{ command: 'ledger_data' },
|
||||
response,
|
||||
)
|
||||
assert(!Client.hasNextPage(responseNextPage))
|
||||
assert(!hasNextPage(responseNextPage))
|
||||
await assertRejects(
|
||||
this.client.requestNextPage({ command: 'ledger_data' }, responseNextPage),
|
||||
Error,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { assert } from 'chai'
|
||||
|
||||
import { deriveXAddress } from 'xrpl-local'
|
||||
|
||||
describe('client.deriveXAddress', function () {
|
||||
describe('deriveXAddress', function () {
|
||||
it('returns address for public key', function () {
|
||||
assert.equal(
|
||||
deriveXAddress({
|
||||
|
||||
17
test/utils/hasNextPage.ts
Normal file
17
test/utils/hasNextPage.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { assert } from 'chai'
|
||||
|
||||
import { hasNextPage } from 'xrpl-local'
|
||||
|
||||
import fixtures from '../fixtures/rippled'
|
||||
|
||||
describe('hasNextPage', function () {
|
||||
it('returns true when response has marker', function () {
|
||||
const firstPage = fixtures.ledger_data.first_page
|
||||
assert.isTrue(hasNextPage(firstPage))
|
||||
})
|
||||
|
||||
it('returns false when response does not have marker', function () {
|
||||
const lastPage = fixtures.ledger_data.last_page
|
||||
assert.isFalse(hasNextPage(lastPage))
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user