Skip to content

Commit

Permalink
[fold] Return realistic number of items in test
Browse files Browse the repository at this point in the history
  • Loading branch information
intelliot committed Feb 14, 2018
1 parent 487de54 commit 68b334f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
9 changes: 6 additions & 3 deletions test/fixtures/responses/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'; // eslint-disable-line strict

function moreThan400Items(item) {
return new Array(401).fill(item);
function buildList(options) {
return new Array(options.count).fill(options.item);
}

module.exports = {
Expand Down Expand Up @@ -65,7 +65,10 @@ module.exports = {
},
getTrustlines: {
filtered: require('./get-trustlines.json'),
moreThan400Items: moreThan400Items(require('./trustline-item.json')),
moreThan400Items: buildList({
item: require('./trustline-item.json'),
count: 401
}),
all: require('./get-trustlines-all.json')
},
getLedger: {
Expand Down
45 changes: 30 additions & 15 deletions test/fixtures/rippled/account-lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@
const _ = require('lodash');
const BASE_LEDGER_INDEX = 8819951;

function getMarkerAndLinesFromRequest(request) {
const itemCount = 401; // Items on the ledger
const perRequestLimit = 400;
const pageCount = Math.ceil(itemCount / perRequestLimit);

// marker is the index of the next item to return
const startIndex = request.marker ? Number(request.marker) : 0;

// No minimum: there are only a certain number of results on the ledger.
// Maximum: the lowest of (perRequestLimit, itemCount - startIndex, request.limit).
const lineCount = Math.min(perRequestLimit, itemCount - startIndex, request.limit);

const trustline = {
account: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
balance: '0.3488146605801446',
currency: 'CHF',
limit: '0',
limit_peer: '0',
quality_in: 0,
quality_out: 0
};

return {
marker: itemCount - lineCount > 0 ? startIndex + lineCount : undefined,
lines: new Array(lineCount).fill(trustline)
};
}

module.exports.normal = function(request, options = {}) {
_.defaults(options, {
ledger: BASE_LEDGER_INDEX
Expand Down Expand Up @@ -327,28 +355,15 @@ module.exports.manyItems = function(request, options = {}) {
ledger: BASE_LEDGER_INDEX
});

options.marker = 'MORE_TO_COME';

let lines = [];
for(let i = 0; i < Math.max(request.limit, 10); i++) {
lines.push({
account: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
balance: '0.3488146605801446',
currency: 'CHF',
limit: '0',
limit_peer: '0',
quality_in: 0,
quality_out: 0
});
}
const {marker, lines} = getMarkerAndLinesFromRequest(request);

return JSON.stringify({
id: request.id,
status: 'success',
type: 'response',
result: {
account: request.account,
marker: options.marker,
marker: marker,

This comment has been minimized.

Copy link
@hserang

hserang Feb 14, 2018

Just an FYI, for ES6 marker, will suffice if you like that stylistically.

limit: request.limit,
ledger_index: options.ledger,
lines: lines
Expand Down

0 comments on commit 68b334f

Please sign in to comment.