-
Notifications
You must be signed in to change notification settings - Fork 524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add request(), hasNextPage(), and requestNextPage() #887
Changes from 1 commit
677a710
911ee09
df69565
4f06d7d
af0cfab
affc7cf
3571f32
50801aa
8833442
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,54 @@ describe('RippleAPI', function () { | |
assert.strictEqual(error.inspect(), '[RippleError(mess, { data: 1 })]'); | ||
}); | ||
|
||
describe('pagination', function () { | ||
|
||
describe('hasNextPage', function () { | ||
|
||
it('returns true when there is another page', function () { | ||
return this.api.request('ledger_data').then(response => { | ||
assert(this.api.hasNextPage(response)); | ||
} | ||
); | ||
}); | ||
|
||
it('returns false when there are no more pages', function () { | ||
return this.api.request('ledger_data').then(response => { | ||
return this.api.requestNextPage('ledger_data', {}, response); | ||
}).then(response => { | ||
assert(!this.api.hasNextPage(response)); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
describe('requestNextPage', function () { | ||
|
||
it('requests the next page', function () { | ||
return this.api.request('ledger_data').then(response => { | ||
return this.api.requestNextPage('ledger_data', {}, response); | ||
}).then(response => { | ||
assert.equal(response.state[0].index, '000B714B790C3C79FEE00D17C4DEB436B375466F29679447BA64F265FD63D731') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this instead use the fixture to compare? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the value comes from the fixture, I think we want to compare with this hardcoded value in order to test that the next page of data was actually retrieved. |
||
}); | ||
}); | ||
|
||
it('rejects when there are no more pages', function () { | ||
return this.api.request('ledger_data').then(response => { | ||
return this.api.requestNextPage('ledger_data', {}, response); | ||
}).then(response => { | ||
return this.api.requestNextPage('ledger_data', {}, response); | ||
}).then(() => { | ||
assert(false, 'Should reject'); | ||
}).catch(error => { | ||
assert(error instanceof Error); | ||
assert.equal(error.message, 'response does not have a next page') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be nice to see (either here or in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
describe('preparePayment', function () { | ||
|
||
it('normal', function () { | ||
|
@@ -1213,15 +1261,15 @@ describe('RippleAPI', function () { | |
}); | ||
|
||
it('request account_objects', function () { | ||
return this.api._request('account_objects', { | ||
return this.api.request('account_objects', { | ||
account: address | ||
}).then(response => | ||
checkResult(responses.getAccountObjects, 'AccountObjectsResponse', response)); | ||
}); | ||
|
||
it('request account_objects - invalid options', function () { | ||
// Intentionally no local validation of these options | ||
return this.api._request('account_objects', { | ||
return this.api.request('account_objects', { | ||
account: address, | ||
invalid: 'options' | ||
}).then(response => | ||
|
@@ -1528,12 +1576,12 @@ describe('RippleAPI', function () { | |
_.partial(checkResult, responses.getLedger.header, 'getLedger')); | ||
}); | ||
|
||
// New in > 0.21.0 | ||
// future ledger versions are allowed, and passed to rippled as-is. | ||
it('getLedger - future ledger version', function () { | ||
return this.api.getLedger({ ledgerVersion: 14661789 }).then(() => { | ||
assert(false, 'Should throw LedgerVersionError'); | ||
}).catch(error => { | ||
assert(error instanceof this.api.errors.LedgerVersionError); | ||
}); | ||
return this.api.getLedger({ ledgerVersion: 14661789 }).then(response => { | ||
assert(response) | ||
}) | ||
}); | ||
|
||
it('getLedger - with state as hashes', function () { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"id": 0, | ||
"status": "success", | ||
"type": "response", | ||
"result": { | ||
"ledger_hash": | ||
"102A6E70FFB18C18E97BB56E3047B0E45EA1BCC90BFCCB8CBB0D07BF0E2AB449", | ||
"ledger_index": 38202000, | ||
"marker": | ||
"000B714B790C3C79FEE00D17C4DEB436B375466F29679447BA64F265FD63D730", | ||
"state": [ | ||
{ | ||
"Flags": 0, | ||
"Indexes": [ | ||
"B32769DB3BE790E959A96CF37A62414479E3EB20A5AEC7156B2BF8FD816DBFF8" | ||
], | ||
"LedgerEntryType": "DirectoryNode", | ||
"Owner": "rwt5iiE1mRbBgNhH6spU4nKgHcE7xK9joN", | ||
"RootIndex": | ||
"0005C961C890079D3C4CC8317F9735D388C3CE3D9BCDC152D3C9A7C08F508D1B", | ||
"index": | ||
"0005C961C890079D3C4CC8317F9735D388C3CE3D9BCDC152D3C9A7C08F508D1B" | ||
}, | ||
{ | ||
"Account": "rpzpyUjdWKmz7yyMvirk3abcaNvSPmDpJn", | ||
"Balance": "91508000", | ||
"Flags": 0, | ||
"LedgerEntryType": "AccountRoot", | ||
"OwnerCount": 0, | ||
"PreviousTxnID": | ||
"F62A5A5EC92DE4E52663B9C7B44A2B76DAB1371737C83A5A81127CBDA84DFE9E", | ||
"PreviousTxnLgrSeq": 35672898, | ||
"Sequence": 1, | ||
"index": | ||
"000B6A1287DB6174F61B1BF987E630CF41DA2A2131CFEB6C5C8143A8F539E9D1" | ||
} | ||
], | ||
"validated": true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_request
->request