Skip to content

Commit

Permalink
Add unit and integration tests for presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Nikitin committed Nov 28, 2023
1 parent 2f7da09 commit fbaa097
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"start:local": "npm run build:app && npm run start",
"format": "prettier --write 'src/**/*.{js,ts,cjs,mjs}' 'tests/**/*.{js,ts,cjs,mjs}'",
"lint": "eslint --max-warnings=0 src && prettier --check '*.{json,js}' 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'",
"test": "npm run test:e2e",
"test": "npm run test:unit && npm run test:e2e",
"test:unit": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest --verbose",
"test:e2e": "npx playwright test -c playwright.config.ts",
"typeorm": "typeorm-ts-node-esm -d ./dist/database/ormconfig.js",
Expand Down
17 changes: 12 additions & 5 deletions src/test/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { JWT_PROOF_TYPE } from "../types/constants";
// CREDENTIAL
// ------------------

export const CREDENTIAL_JWT = 'eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkaWQ6Y2hlcWQ6dGVzdG5ldDo3YmY4MWEyMC02MzNjLTRjYzctYmM0YS01YTQ1ODAxMDA1ZTAiLCJuYmYiOjE2ODYyMzIxNjgsInN1YiI6ImRpZDprZXk6ejZNa2hhWGdCWkR2b3REa0w1MjU3ZmFpenRpR2lDMlF0S0xHcGJubkVHdGEyZG9LIiwidmMiOnsiQGNvbnRleHQiOlsiaHR0cHM6Ly93d3cudzMub3JnLzIwMTgvY3JlZGVudGlhbHMvdjEiLCJodHRwczovL3NjaGVtYS5vcmciLCJodHRwczovL3ZlcmFtby5pby9jb250ZXh0cy9wcm9maWxlL3YxIl0sImNyZWRlbnRpYWxTdWJqZWN0Ijp7ImdlbmRlciI6Im1hbGUiLCJ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cyI6ImRpZDpjaGVxZDp0ZXN0bmV0OjkwZDVjMTQxLTcyNGYtNDdhZC05YWU3LWE3YzMzYTllNTY0MyJ9.-14Ril1pZEy2HEEo48gTJr2yOtGxBhUGTFmzVdjAtyhFRsW5zZg9onHt6V9JQ8BaiYBlTkP9GzTnJ-O6hdiyCw';
export const CREDENTIAL_SUBJECT_ID = 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK';
export const ISSUIER_DID = 'did:cheqd:testnet:7bf81a20-633c-4cc7-bc4a-5a45801005e0';
export const ISSUIER_DID = 'did:cheqd:testnet:90d5c141-724f-47ad-9ae7-a7c33a9e5643';
export const CREDENTIAL_STATUS_ID = 'https://resolver.cheqd.net/1.0/identifiers/did:cheqd:testnet:90d5c141-724f-47ad-9ae7-a7c33a9e5643?resourceName=suspensionEn&resourceType=StatusList2021Suspension#13338';

export const CREDENTIAL_OBJECT = {
issuer: {
Expand All @@ -17,6 +18,12 @@ export const CREDENTIAL_OBJECT = {
name: "Bob",
id: CREDENTIAL_SUBJECT_ID
},
credentialStatus: {
id: CREDENTIAL_STATUS_ID,
statusPurpose: "suspension",
statusListIndex: "13338",
type: 'StatusList2021Entry'
},
type: ["VerifiableCredential", "Person"],
'@context': [
"https://www.w3.org/2018/credentials/v1",
Expand All @@ -35,10 +42,10 @@ export const CREDENTIAL_OBJECT = {
// PRESENTATION
// ------------------

export const PRESENTATION_JWT = 'eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJ2cCI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVQcmVzZW50YXRpb24iXSwidmVyaWZpYWJsZUNyZWRlbnRpYWwiOlsiZXlKaGJHY2lPaUpGWkVSVFFTSXNJblI1Y0NJNklrcFhWQ0o5LmV5SnBjM01pT2lKa2FXUTZZMmhsY1dRNmRHVnpkRzVsZERvM1ltW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dmMtc3RhdHVzLWxpc3QtMjAyMS92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiUGVyc29uIl0sImNyZWRlbnRpYWxTdWJqZWN0Ijp7Im5hbWUiOiJCb2IiLCJnZW5kZXIiOiJtYWxlIn0sImNyZWRlbnRpYWxTdGF0dXMiOnsiaWQiOiJodHRwczovL3Jlc29sdmVyLmNoZXFkLm5ldC8xLjAvaWRlbnRpZmllcnMvZGlkOmNoZXFkOnRlc3RuZXQ6OTBkNWMxNDEtNzI0Zi00N2FkLTlhZTctYTdjMzNhOWU1NjQzP3Jlc291cmNlTmFtZT1zdXNwZW5zaW9uRW4mcmVzb3VyY2VUeXBlPVN0YXR1c0xpc3QyMDIxU3VzcGVuc2lvbiMxMzMzOCIsInR5cGUiOiJTdGF0dXNMaXN0MjAyMUVudHJ5Iiwic3RhdHVzUHVycG9zZSI6InN1c3BlbnNpb24iLCJzdGF0dXNMaXN0SW5kZXgiOiIxMzMzOCJ9fSwic3ViIjoiZGlkOmtleTp6Nk1raGFYZ0JaRHZvdERrTDUyNTdmYWl6dGlHaUMyUXRLTEdwYm5uRUd0YTJkb0siLCJuYmYiOjE3MDA0NzM0MTYsImlzcyI6ImRpZDpjaGVxZDp0ZXN0bmV0OjkwZDVjMTQxLTcyNGYtNDdhZC05YWU3LWE3YzMzYTllNTY0MyJ9.-14Ril1pZEy2HEEo48gTJr2yOtGxBhUGTFmzVdjAtyhFRsW5zZg9onHt6V9JQ8BaiYBlTkP9GzTnJ-O6hdiyCw'
export const HOLDER_DID = 'did:cheqd:testnet:4b846d0f-2f6c-4ab6-9fe2-5b8db301c83c';
export const VERIFIER_DID = 'did:cheqd:testnet:8c71e9b6-c5a3-4250-8c58-fa591533cd22';
export const HOLDER_DID = 'did:cheqd:testnet:8c71e9b6-c5a3-4250-8c58-fa591533cd22';
export const VERIFIER_DID = 'did:cheqd:testnet:4b846d0f-2f6c-4ab6-9fe2-5b8db301c83c';

export const PRESENTATION_OBJECT_CREDENTIAL_JWT = {
'@context': [
Expand Down
26 changes: 24 additions & 2 deletions src/test/credential/credential.cheqd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, it } from "@jest/globals";
import { CheqdW3CVerifiableCredential } from "../../types/credential.js";
import { expect } from "@playwright/test";
import { JWT_PROOF_TYPE } from "../../types/constants.js";
import { CREDENTIAL_JWT, CREDENTIAL_OBJECT, CREDENTIAL_SUBJECT_ID, ISSUIER_DID } from "../constants.js";
import { CREDENTIAL_JWT, CREDENTIAL_OBJECT, CREDENTIAL_STATUS_ID, CREDENTIAL_SUBJECT_ID, ISSUIER_DID } from "../constants.js";

describe('Credential from JWT to object', () => {
const credential = new CheqdW3CVerifiableCredential(CREDENTIAL_JWT);
Expand All @@ -29,13 +29,24 @@ describe('Credential from JWT to object', () => {
id: CREDENTIAL_SUBJECT_ID
});
})
it('should have a credentialStatus', () => {
expect(credential.credentialStatus).toBeDefined();
expect(credential.credentialStatus).toEqual(
{
id: CREDENTIAL_STATUS_ID,
statusPurpose: "suspension",
statusListIndex: "13338",
type: 'StatusList2021Entry'
}
);
})
it('should have an issuer', () => {
expect(credential.issuer).toBeDefined();
expect(credential.issuer).toEqual(ISSUIER_DID);
})
it('should have an issuanceDate', () => {
expect(credential.issuanceDate).toBeDefined();
expect(credential.issuanceDate).toEqual('2023-06-08T13:49:28.000Z');
expect(credential.issuanceDate).toEqual('2023-11-20T09:43:36.000Z');
})
})

Expand Down Expand Up @@ -64,6 +75,17 @@ describe('Credential from object ', () => {
id: CREDENTIAL_SUBJECT_ID
});
})
it('should have a credentialStatus', () => {
expect(credential.credentialStatus).toBeDefined();
expect(credential.credentialStatus).toEqual(
{
id: CREDENTIAL_STATUS_ID,
statusPurpose: "suspension",
statusListIndex: "13338",
type: 'StatusList2021Entry'
}
);
})
it('should have an issuer', () => {
expect(credential.issuer).toBeDefined();
expect(credential.issuer).toEqual(ISSUIER_DID);
Expand Down
2 changes: 1 addition & 1 deletion src/test/presentation/presentation.cheqd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Presentation from JWT to object', () => {
})
it('should have issuanceDate', () => {
expect(presentation.issuanceDate).toBeDefined();
expect(presentation.issuanceDate).toEqual('2023-11-27T21:45:17.000Z');
expect(presentation.issuanceDate).toEqual('2023-11-28T12:27:02.000Z');
})
it('should have verifiableCredential', () => {
expect(presentation.verifiableCredential).toBeDefined();
Expand Down
1 change: 1 addition & 0 deletions src/types/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class CheqdW3CVerifiableCredential extends CommonReturn implements ICheqd
id: decoded.iss as string,
};
credential.issuanceDate = new Date((decoded.nbf as number) * 1000).toISOString();
credential.credentialStatus = decoded.vc.credentialStatus;
credential.credentialSubject.id = decoded.sub as string;
credential.proof = {
type: JWT_PROOF_TYPE,
Expand Down
5 changes: 0 additions & 5 deletions tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ export const NOT_SUPPORTED_VERIFICATION_METHOD_TYPE = 'not_supported_vm_type';
export const INVALID_ID = 'invalid_id';
export const INVALID_DID = 'invalid_did';

export enum NETWORK {
MAINNET = 'mainnet',
TESTNET = 'testnet',
}

export enum ID_TYPE {
UUID = 'uuid',
BASE58BTC = 'base58btc',
Expand Down
18 changes: 9 additions & 9 deletions tests/did/create.negative.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
NETWORK,
ID_TYPE,
INVALID_ID,
INVALID_DID,
Expand All @@ -12,6 +11,7 @@ import * as fs from 'fs';
import { v4 } from 'uuid';
import { test, expect } from '@playwright/test';
import { StatusCodes } from 'http-status-codes';
import { CheqdNetwork } from '@cheqd/sdk';

const PAYLOADS_BASE_PATH = './tests/payloads/did';

Expand All @@ -21,7 +21,7 @@ test('[Negative] It cannot create DID with missed verificationMethodType field i
request,
}) => {
const response = await request.post(`/did/create`, {
data: `network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}`,
data: `network=${CheqdNetwork.Testnet}&identifierFormatType=${ID_TYPE.BASE58BTC}`,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
});
expect(response.status()).toBe(StatusCodes.BAD_REQUEST);
Expand All @@ -33,7 +33,7 @@ test('[Negative] It cannot create DID with missed verificationMethodType field i
test('[Negative] It cannot create DID with not existent key in request body (Form based)', async ({ request }) => {
const response = await request.post(`/did/create`, {
data:
`network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}&` +
`network=${CheqdNetwork.Testnet}&identifierFormatType=${ID_TYPE.BASE58BTC}&` +
`verificationMethodType=${VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020}&` +
`key=${NOT_EXISTENT_KEY}`,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
Expand All @@ -46,7 +46,7 @@ test('[Negative] It cannot create DID with not existent key in request body (JSO
const did = `did:cheqd:testnet:${v4()}`;
const response = await request.post('/did/create', {
data: {
network: NETWORK.TESTNET,
network: CheqdNetwork.Testnet,
identifierFormatType: ID_TYPE.UUID,
options: {
verificationMethodType: VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020,
Expand All @@ -70,7 +70,7 @@ test('[Negative] It cannot create DID with an invalid VerificationMethodType in
const did = `did:cheqd:testnet:${v4()}`;
const response = await request.post('/did/create', {
data: {
network: NETWORK.TESTNET,
network: CheqdNetwork.Testnet,
identifierFormatType: ID_TYPE.UUID,
options: {
verificationMethodType: NOT_SUPPORTED_VERIFICATION_METHOD_TYPE,
Expand All @@ -93,7 +93,7 @@ test('[Negative] It cannot create DID with an invalid length of id in DIDDocumen
const invalidDidLength = `did:cheqd:testnet:${INVALID_ID}`;
const response = await request.post('/did/create', {
data: {
network: NETWORK.TESTNET,
network: CheqdNetwork.Testnet,
identifierFormatType: ID_TYPE.UUID,
options: {
verificationMethodType: VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2018,
Expand All @@ -117,7 +117,7 @@ test('[Negative] It cannot create DID with an invalid id format in DIDDocument i
}) => {
const response = await request.post('/did/create', {
data: {
network: NETWORK.TESTNET,
network: CheqdNetwork.Testnet,
identifierFormatType: ID_TYPE.UUID,
options: {
verificationMethodType: VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2018,
Expand All @@ -139,7 +139,7 @@ test('[Negative] It cannot create DID without VerificationMethodType in request
}) => {
const response = await request.post('/did/create', {
data: {
network: NETWORK.TESTNET,
network: CheqdNetwork.Testnet,
identifierFormatType: ID_TYPE.UUID,
didDocument: {
id: INVALID_DID,
Expand All @@ -156,7 +156,7 @@ test('[Negative] It cannot create DID without VerificationMethodType in request
test('[Negative] It cannot create DID without DidDocument in request body (JSON based)', async ({ request }) => {
const response = await request.post('/did/create', {
data: {
network: NETWORK.TESTNET,
network: CheqdNetwork.Testnet,
identifierFormatType: ID_TYPE.UUID,
options: {
verificationMethodType: VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020,
Expand Down
17 changes: 9 additions & 8 deletions tests/did/create.positive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { ID_TYPE, NETWORK, DEFAULT_CONTEXT, VERIFICATION_METHOD_TYPES } from '../constants';
import { ID_TYPE, DEFAULT_CONTEXT, VERIFICATION_METHOD_TYPES } from '../constants';
import { v4 } from 'uuid';
import { buildSimpleService } from 'helpers';
import { test, expect } from '@playwright/test';
import { StatusCodes } from 'http-status-codes';
import { MethodSpecificIdAlgo, createVerificationKeys } from '@cheqd/sdk';

import { CheqdNetwork, MethodSpecificIdAlgo, createVerificationKeys } from '@cheqd/sdk';

test.use({ storageState: 'playwright/.auth/user.json' });

test('[Positive] It can create DID with mandatory properties (Form based + Indy style)', async ({ request }) => {
// send request to create DID
let response = await request.post(`/did/create`, {
data:
`network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}&` +
`network=${CheqdNetwork.Testnet}}&identifierFormatType=${ID_TYPE.BASE58BTC}&` +
`verificationMethodType=${VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020}`,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
});
Expand All @@ -28,7 +29,7 @@ test('[Positive] It can create DID with mandatory properties (Form based + Indy
const didDocument = (await response.json()).didDocument;

// Check mandatory properties
expect(didDocument.id.split(':')[2]).toBe(NETWORK.TESTNET);
expect(didDocument.id.split(':')[2]).toBe(CheqdNetwork.Testnet);
expect(didDocument.verificationMethod[0].type).toBe(VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020);
});

Expand All @@ -47,7 +48,7 @@ test('[Positive] It can create DID with mandatory and optional properties (Form
// send request to create DID
response = await request.post(`/did/create`, {
data:
`network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}&` +
`network=${CheqdNetwork.Testnet}&identifierFormatType=${ID_TYPE.BASE58BTC}&` +
`verificationMethodType=${VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020}&` +
`service=${JSON.stringify(buildSimpleService())}&key=${kid}&@context=${DEFAULT_CONTEXT}`,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
Expand All @@ -58,7 +59,7 @@ test('[Positive] It can create DID with mandatory and optional properties (Form
const body = await response.json();

// Check mandatory properties
expect(body.did.split(':')[2]).toBe(NETWORK.TESTNET);
expect(body.did.split(':')[2]).toBe(CheqdNetwork.Testnet);
expect(body.controllerKeyId).toBe(kid);

// resolve a created DID
Expand Down Expand Up @@ -114,7 +115,7 @@ test('[Positive] It can create DID with mandatory properties (JSON based + Indy
const didDocument = (await response.json()).didDocument;

// Check mandatory properties
expect(didDocument.id.split(':')[2]).toBe(NETWORK.TESTNET);
expect(didDocument.id.split(':')[2]).toBe(CheqdNetwork.Testnet);
expect(didDocument.verificationMethod[0].type).toBe(VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020);
});

Expand All @@ -133,7 +134,7 @@ test('[Positive] It can create DID with mandatory and optional properties (JSON
const did = `did:cheqd:testnet:${v4()}`;
response = await request.post('/did/create', {
data: {
network: NETWORK.TESTNET,
network: CheqdNetwork.Testnet,
identifierFormatType: ID_TYPE.UUID,
assertionMethod: true,
options: {
Expand Down
18 changes: 16 additions & 2 deletions tests/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { APIRequestContext, expect } from '@playwright/test';
import {
DEFAULT_STATUS_LIST_ENCRYPTED_NAME,
DEFAULT_STATUS_LIST_INDICES,
DEFAULT_STATUS_LIST_PAYMENT_ADDRESS,
DEFAULT_SUBJECT_DID,
DEFAULT_TESTNET_DID,
VERIFICATION_METHOD_TYPES,
} from './constants';

export const buildSimpleCreateDID = (network = 'testnet') => {
Expand Down Expand Up @@ -33,7 +35,7 @@ export const buildUpdateSimpleDID = (
controller: did,
id: `${did}#key-1`,
publicKeyBase58: pubkey,
type: `Ed25519VerificationKey2018`,
type: VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2018,
},
],
authentication: ['string'],
Expand All @@ -44,7 +46,7 @@ export const buildUpdateSimpleDID = (
verificationMethod: [
{
id: `${did}#key-1`,
type: 'Ed25519VerificationKey2018',
type: VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2018,
controller: did,
publicKeyBase58: pubkey,
},
Expand Down Expand Up @@ -149,3 +151,15 @@ export const buildSimpleService = (
serviceEndpoint: serviceEndpoint,
};
};


export async function createDID( request: APIRequestContext, payload): Promise<string> {
const response = await request.post('/did/create', {
data: payload,
headers: { 'Content-Type': 'application/json' },
});

expect(response).toBeOK();
const reponseJson = await response.json();
return reponseJson.did as string;
}

0 comments on commit fbaa097

Please sign in to comment.