Skip to content

Commit

Permalink
feat: added a few additional tests to nodesClaimGet
Browse files Browse the repository at this point in the history
  • Loading branch information
CDeltakai committed Feb 21, 2025
1 parent ef13883 commit 77c4b32
Showing 1 changed file with 133 additions and 1 deletion.
134 changes: 133 additions & 1 deletion tests/nodes/agent/handlers/nodesClaimsGet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,137 @@ describe('nodesClaimsGet', () => {
expect(chainIds).toHaveLength(10);
});


test('Should get chain data with limit', async () => {

const srcNodeIdEncoded = nodesUtils.encodeNodeId(keyRing.getNodeId());
// Add 10 claims
for (let i = 1; i <= 5; i++) {
const node2 = nodesUtils.encodeNodeId(
testNodesUtils.generateRandomNodeId(),
);
const nodeLink = {
type: 'ClaimLinkNode',
iss: srcNodeIdEncoded,
sub: node2,
};
await sigchain.addClaim(nodeLink);
}
for (let i = 6; i <= 10; i++) {
const identityLink = {
type: 'ClaimLinkIdentity',
iss: srcNodeIdEncoded,
sub: encodeProviderIdentityId([
('ProviderId' + i.toString()) as ProviderId,
('IdentityId' + i.toString()) as IdentityId,
]),
};
await sigchain.addClaim(identityLink);
}


let limitVal = 5;

const response = await rpcClient.methods.nodesClaimsGet({
limit: limitVal,
});
const chainIds: Array<string> = [];
for await (const claim of response) {
chainIds.push(claim.claimIdEncoded ?? '');
}
expect(chainIds).toHaveLength(5);
});

test('Should get chain data with order desc', async () => {
const srcNodeIdEncoded = nodesUtils.encodeNodeId(keyRing.getNodeId());
// Add 10 claims
for (let i = 1; i <= 5; i++) {
const node2 = nodesUtils.encodeNodeId(
testNodesUtils.generateRandomNodeId(),
);
const nodeLink = {
type: 'ClaimLinkNode',
iss: srcNodeIdEncoded,
sub: node2,
};
await sigchain.addClaim(nodeLink);
}
for (let i = 6; i <= 10; i++) {
const identityLink = {
type: 'ClaimLinkIdentity',
iss: srcNodeIdEncoded,
sub: encodeProviderIdentityId([
('ProviderId' + i.toString()) as ProviderId,
('IdentityId' + i.toString()) as IdentityId,
]),
};
await sigchain.addClaim(identityLink);
}

const response = await rpcClient.methods.nodesClaimsGet({
order: 'desc',
});
const chainIds: Array<string> = [];
for await (const claim of response) {
chainIds.push(claim.claimIdEncoded ?? '');
}


//Verify that chainIds are in descending order
let isSorted = true;
for (let i = 0; i < chainIds.length - 1; i++) {
if (chainIds[i] < chainIds[i + 1]) {
isSorted = false;
break;
}
}
expect(isSorted).toBe(true);

});

test('Should get chain data with order asc', async () => {
const srcNodeIdEncoded = nodesUtils.encodeNodeId(keyRing.getNodeId());
// Add 10 claims
for (let i = 1; i <= 5; i++) {
const node2 = nodesUtils.encodeNodeId(
testNodesUtils.generateRandomNodeId(),
);
const nodeLink = {
type: 'ClaimLinkNode',
iss: srcNodeIdEncoded,
sub: node2,
};
await sigchain.addClaim(nodeLink);
}
for (let i = 6; i <= 10; i++) {
const identityLink = {
type: 'ClaimLinkIdentity',
iss: srcNodeIdEncoded,
sub: encodeProviderIdentityId([
('ProviderId' + i.toString()) as ProviderId,
('IdentityId' + i.toString()) as IdentityId,
]),
};
await sigchain.addClaim(identityLink);
}

const response = await rpcClient.methods.nodesClaimsGet({
order: 'asc',
});
const chainIds: Array<string> = [];
for await (const claim of response) {
chainIds.push(claim.claimIdEncoded ?? '');
}

//Verify that chainIds are in ascending order
let isSorted = true;
for (let i = 0; i < chainIds.length - 1; i++) {
if (chainIds[i] > chainIds[i + 1]) {
isSorted = false;
break;
}
}
expect(isSorted).toBe(true);
});


});

0 comments on commit 77c4b32

Please sign in to comment.