Skip to content

Commit

Permalink
test: add test for credetial router
Browse files Browse the repository at this point in the history
  • Loading branch information
ldhyen99 committed Jul 30, 2024
1 parent 55ad20a commit c37d301
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
48 changes: 48 additions & 0 deletions packages/credential-router/__tests__/action-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {

import { CredentialRouter } from '../src/action-handler';
import {
ENVELOPING_PROOF_JOSE,
RAW_CREDENTIAL,
SIGNED_WRAPPED_DOCUMENT_JWT,
SIGNED_WRAPPED_DOCUMENT_MERKLE_DISCLOSURE,
Expand Down Expand Up @@ -91,6 +92,30 @@ describe('CredentialRouter', () => {
expect(result).toEqual(SIGNED_WRAPPED_DOCUMENT_JWT);
});

it('should throw error when create a credential router with proofFormat is EnvelopingProof', async () => {
const mockIssuerAgentContext = {
agent: {
createVerifiableCredential: jest
.fn()
.mockReturnValue(ENVELOPING_PROOF_JOSE),
},
} as unknown as IssuerAgentContext;

const credentialPlugin = new CredentialRouter();
const args: ICreateVerifiableCredentialArgs = {
credential: RAW_CREDENTIAL,
proofFormat: 'EnvelopingProof',
};

const result = await credentialPlugin.routeCreationVerifiableCredential(
args,
mockIssuerAgentContext,
);

expect(result).not.toBeNull();
expect(result).toEqual(ENVELOPING_PROOF_JOSE);
});

it(`should throw error when create a credential router with proofFormat is OpenAttestationMerkleProofSignature2018`, async () => {
const mockIssuerAgentContext = {
agent: {
Expand Down Expand Up @@ -159,6 +184,29 @@ describe('CredentialRouter', () => {
'invalid_setup: your agent does not seem to have CredentialW3c plugin installed',
);
});

it(`should throw error when create a credential router with proofFormat is EnvelopingProof`, async () => {
const mockIssuerAgentContext = {
agent: {
createVerifiableCredential: undefined,
},
} as unknown as IssuerAgentContext;

const credentialPlugin = new CredentialRouter();
const args: ICreateVerifiableCredentialArgs = {
credential: RAW_CREDENTIAL,
proofFormat: 'EnvelopingProof',
};

await expect(
credentialPlugin.routeCreationVerifiableCredential(
args,
mockIssuerAgentContext,
),
).rejects.toThrow(
'invalid_setup: your agent does not seem to have CredentialW3c plugin installed',
);
});
});

describe('routeVerifyCredential', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/credential-router/__tests__/mocks/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,6 @@ export const SIGNED_WRAPPED_DOCUMENT_JWT = {
...RAW_CREDENTIAL,
...JWT_PROOF,
};

export const ENVELOPING_PROOF_JOSE =
'eyJhbGciOiJFZERTQSIsImlzcyI6ImRpZDp3ZWI6N2Y1Mi0yNDAyLTgwMC02MzE1LWZlYjQtZDVlOC0xMzg3LTc2ODUtZThhNi5uZ3Jvay1mcmVlLmFwcCIsInR5cCI6InZjLWxkK2p3dCJ9.eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvbnMvY3JlZGVudGlhbHMvdjIiLCJodHRwczovL3d3dy53My5vcmcvbnMvY3JlZGVudGlhbHMvZXhhbXBsZXMvdjIiXSwiaWQiOiJodHRwOi8vdW5pdmVyc2l0eS5leGFtcGxlL2NyZWRlbnRpYWxzLzE4NzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiRXhhbXBsZUFsdW1uaUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiZGlkOndlYjo3ZjUyLTI0MDItODAwLTYzMTUtZmViNC1kNWU4LTEzODctNzY4NS1lOGE2Lm5ncm9rLWZyZWUuYXBwIiwidmFsaWRGcm9tIjoiMjAxMC0wMS0wMVQxOToyMzoyNFoiLCJjcmVkZW50aWFsU2NoZW1hIjp7ImlkIjoiaHR0cHM6Ly9leGFtcGxlLm9yZy9leGFtcGxlcy9kZWdyZWUuanNvbiIsInR5cGUiOiJKc29uU2NoZW1hIn0sImNyZWRlbnRpYWxTdWJqZWN0Ijp7ImlkIjoiZGlkOmV4YW1wbGU6MTIzIiwiZGVncmVlIjp7InR5cGUiOiJCYWNoZWxvckRlZ3JlZSIsIm5hbWUiOiJCY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