Skip to content

Commit 9a18049

Browse files
committed
tests: adding seek tests for getClaims
[ci skip]
1 parent 1cb6f12 commit 9a18049

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

src/sigchain/Sigchain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class Sigchain {
284284
): AsyncGenerator<[ClaimId, Claim]> {
285285
if (tran == null) {
286286
return yield* this.db.withTransactionG((tran) =>
287-
this.getClaims({ order, seek }, tran),
287+
this.getClaims({ order, seek, limit }, tran),
288288
);
289289
}
290290
const orderOptions =

tests/sigchain/Sigchain.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import * as sigchainErrors from '@/sigchain/errors';
1616
import * as keysUtils from '@/keys/utils';
1717
import * as claimsUtils from '@/claims/utils';
1818
import * as utils from '@/utils';
19+
import * as testsNodesUtils from '../nodes/utils';
1920

2021
describe(Sigchain.name, () => {
2122
const password = keysUtils.getRandomBytes(10).toString('utf-8');
@@ -317,4 +318,62 @@ describe(Sigchain.name, () => {
317318
await sigchain.stop();
318319
},
319320
);
321+
test('getClaims with seek ascending', async () => {
322+
const sigchain = await Sigchain.createSigchain({
323+
keyRing,
324+
db,
325+
logger,
326+
fresh: true,
327+
});
328+
const claims: Array<[ClaimId, SignedClaim]> = [];
329+
for (let i = 0; i < 3; i++) {
330+
claims.push(await sigchain.addClaim({}));
331+
}
332+
const claimsAsc = await AsyncIterable.as(
333+
sigchain.getClaims({ seek: claims[1][0], order: 'asc' }),
334+
).toArray();
335+
expect(claimsAsc).toHaveLength(2);
336+
// The claim we seeked to is included
337+
expect(claimsAsc[0][0].equals(claims[1][0])).toBeTrue();
338+
// And the claim after
339+
expect(claimsAsc[1][0].equals(claims[2][0])).toBeTrue();
340+
});
341+
test('getClaims with seek descending', async () => {
342+
const sigchain = await Sigchain.createSigchain({
343+
keyRing,
344+
db,
345+
logger,
346+
fresh: true,
347+
});
348+
const claims: Array<[ClaimId, SignedClaim]> = [];
349+
for (let i = 0; i < 3; i++) {
350+
claims.push(await sigchain.addClaim({}));
351+
}
352+
const claimsAsc = await AsyncIterable.as(
353+
sigchain.getClaims({ seek: claims[1][0], order: 'desc' }),
354+
).toArray();
355+
expect(claimsAsc).toHaveLength(2);
356+
// The claim we seeked to is included
357+
expect(claimsAsc[0][0].equals(claims[1][0])).toBeTrue();
358+
// And the claim after
359+
expect(claimsAsc[1][0].equals(claims[0][0])).toBeTrue();
360+
});
361+
test('getClaims with seek with limit', async () => {
362+
const sigchain = await Sigchain.createSigchain({
363+
keyRing,
364+
db,
365+
logger,
366+
fresh: true,
367+
});
368+
const claims: Array<[ClaimId, SignedClaim]> = [];
369+
for (let i = 0; i < 3; i++) {
370+
claims.push(await sigchain.addClaim({}));
371+
}
372+
const claimsAsc = await AsyncIterable.as(
373+
sigchain.getClaims({ seek: claims[1][0], limit: 1 }),
374+
).toArray();
375+
expect(claimsAsc).toHaveLength(1);
376+
// The claim we seeked to is included
377+
expect(claimsAsc[0][0].equals(claims[1][0])).toBeTrue();
378+
});
320379
});

0 commit comments

Comments
 (0)