refactor: move hasNextPage from Client to utils (#1715)

* add hasNextPage

* remove unused util

* add tests

* remove hasNextPage from client
This commit is contained in:
Mayukha Vadari
2021-10-12 16:39:57 -04:00
committed by GitHub
parent 75e56ca927
commit 1a8bbfa43e
6 changed files with 39 additions and 74 deletions

View File

@@ -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))
})
})

View File

@@ -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,

View File

@@ -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
View 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))
})
})