Skip to content

Commit

Permalink
Add accredit & attest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran committed Sep 30, 2024
1 parent 3bf97e9 commit 022639b
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 21 deletions.
94 changes: 87 additions & 7 deletions tests/e2e/parallel/accreditation/issue-verify-flow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { CONTENT_TYPE, PAYLOADS_PATH } from '../../constants';

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

test(' Issue and verify a accreditation', async ({ request }) => {
const credentialData = JSON.parse(
fs.readFileSync(`${PAYLOADS_PATH.ACCREDITATION}/accreditation-issue-jwt.json`, 'utf-8')
);
test(' Issue and verify a authorize accreditation', async ({ request }) => {
const credentialData = JSON.parse(fs.readFileSync(`${PAYLOADS_PATH.ACCREDITATION}/authorize-jwt.json`, 'utf-8'));
const issueResponse = await request.post(`/accreditation/issue?accreditationType=authorize`, {
data: JSON.stringify(credentialData),
headers: {
Expand Down Expand Up @@ -50,9 +48,7 @@ test(' Issue and verify a accreditation', async ({ request }) => {
});

test(' Issue accreditation [Negative]', async ({ request }) => {
const credentialData = JSON.parse(
fs.readFileSync(`${PAYLOADS_PATH.ACCREDITATION}/accreditation-issue-jwt.json`, 'utf-8')
);
const credentialData = JSON.parse(fs.readFileSync(`${PAYLOADS_PATH.ACCREDITATION}/accredit.json`, 'utf-8'));

Check failure on line 51 in tests/e2e/parallel/accreditation/issue-verify-flow.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Parallel Logged In User Tests] › parallel/accreditation/issue-verify-flow.spec.ts:50:1 › Issue accreditation [Negative]

2) [Parallel Logged In User Tests] › parallel/accreditation/issue-verify-flow.spec.ts:50:1 › Issue accreditation [Negative] Error: ENOENT: no such file or directory, open './tests/e2e/payloads/accreditation/accredit.json' 49 | 50 | test(' Issue accreditation [Negative]', async ({ request }) => { > 51 | const credentialData = JSON.parse(fs.readFileSync(`${PAYLOADS_PATH.ACCREDITATION}/accredit.json`, 'utf-8')); | ^ 52 | const issueResponse = await request.post(`/accreditation/issue`, { 53 | data: JSON.stringify(credentialData), 54 | headers: { at /home/runner/work/studio/studio/tests/e2e/parallel/accreditation/issue-verify-flow.spec.ts:51:39

Check failure on line 51 in tests/e2e/parallel/accreditation/issue-verify-flow.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Parallel Logged In User Tests] › parallel/accreditation/issue-verify-flow.spec.ts:50:1 › Issue accreditation [Negative]

2) [Parallel Logged In User Tests] › parallel/accreditation/issue-verify-flow.spec.ts:50:1 › Issue accreditation [Negative] Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: ENOENT: no such file or directory, open './tests/e2e/payloads/accreditation/accredit.json' 49 | 50 | test(' Issue accreditation [Negative]', async ({ request }) => { > 51 | const credentialData = JSON.parse(fs.readFileSync(`${PAYLOADS_PATH.ACCREDITATION}/accredit.json`, 'utf-8')); | ^ 52 | const issueResponse = await request.post(`/accreditation/issue`, { 53 | data: JSON.stringify(credentialData), 54 | headers: { at /home/runner/work/studio/studio/tests/e2e/parallel/accreditation/issue-verify-flow.spec.ts:51:39

Check failure on line 51 in tests/e2e/parallel/accreditation/issue-verify-flow.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Parallel Logged In User Tests] › parallel/accreditation/issue-verify-flow.spec.ts:50:1 › Issue accreditation [Negative]

2) [Parallel Logged In User Tests] › parallel/accreditation/issue-verify-flow.spec.ts:50:1 › Issue accreditation [Negative] Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: ENOENT: no such file or directory, open './tests/e2e/payloads/accreditation/accredit.json' 49 | 50 | test(' Issue accreditation [Negative]', async ({ request }) => { > 51 | const credentialData = JSON.parse(fs.readFileSync(`${PAYLOADS_PATH.ACCREDITATION}/accredit.json`, 'utf-8')); | ^ 52 | const issueResponse = await request.post(`/accreditation/issue`, { 53 | data: JSON.stringify(credentialData), 54 | headers: { at /home/runner/work/studio/studio/tests/e2e/parallel/accreditation/issue-verify-flow.spec.ts:51:39
const issueResponse = await request.post(`/accreditation/issue`, {
data: JSON.stringify(credentialData),
headers: {
Expand All @@ -70,3 +66,87 @@ test(' Verify accreditation [Negative]', async ({ request }) => {
});
expect(verifyResponse.status()).toBe(400);
});

test(' Issue and verify a accredit accreditation', async ({ request }) => {
const credentialData = JSON.parse(fs.readFileSync(`${PAYLOADS_PATH.ACCREDITATION}/accredit-jwt.json`, 'utf-8'));
const issueResponse = await request.post(`/accreditation/issue?accreditationType=authorize`, {
data: JSON.stringify(credentialData),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
},
});
const { didUrls, accreditation } = await issueResponse.json();
expect(issueResponse).toBeOK();
expect(issueResponse.status()).toBe(StatusCodes.OK);
expect(accreditation.proof.type).toBe('JwtProof2020');
expect(accreditation.proof).toHaveProperty('jwt');
expect(typeof accreditation.issuer === 'string' ? accreditation.issuer : accreditation.issuer.id).toBe(
credentialData.issuerDid
);
expect(accreditation.type).toContain('VerifiableCredential');
expect(accreditation.credentialSubject).toMatchObject({
...credentialData.attributes,
id: credentialData.subjectDid,
});
expect(didUrls).toHaveLength(2);
expect(didUrls).toContain(
`did:cheqd:testnet:15b74787-6e48-4fd5-8020-eab24e990578?resourceName=accreditAccreditation&resourceType=VerifiableAccreditationToAccredit`
);

const verifyResponse = await request.post(`/accreditation/verify`, {
data: JSON.stringify({
subjectDid: `${credentialData.subjectDid}`,
accreditation: `did:cheqd:testnet:15b74787-6e48-4fd5-8020-eab24e990578?resourceName=accreditAccreditation&resourceType=VerifiableAccreditationToAccredit`,
}),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
},
});
const result = await verifyResponse.json();
expect(verifyResponse).toBeOK();
expect(verifyResponse.status()).toBe(StatusCodes.OK);
expect(result.error).toBe(undefined);
expect(result.verified).toBe(true);
});

test(' Issue and verify a attest accreditation', async ({ request }) => {
const credentialData = JSON.parse(fs.readFileSync(`${PAYLOADS_PATH.ACCREDITATION}/accredit-jwt.json`, 'utf-8'));
const issueResponse = await request.post(`/accreditation/issue?accreditationType=authorize`, {
data: JSON.stringify(credentialData),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
},
});
const { didUrls, accreditation } = await issueResponse.json();
expect(issueResponse).toBeOK();

Check failure on line 121 in tests/e2e/parallel/accreditation/issue-verify-flow.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Parallel Logged In User Tests] › parallel/accreditation/issue-verify-flow.spec.ts:112:1 › Issue and verify a attest accreditation

3) [Parallel Logged In User Tests] › parallel/accreditation/issue-verify-flow.spec.ts:112:1 › Issue and verify a attest accreditation Error: expect(received).toBeOK() Call log: - → POST http://localhost:3000/accreditation/issue?accreditationType=authorize - user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.6613.18 Safari/537.36 - accept: */* - accept-encoding: gzip,deflate,br - x-api-key: *** - Content-Type: application/json - content-length: 549 - ← 500 Internal Server Error - content-security-policy: default-src 'self';base-uri 'self';font-src 'self' https: data:;form-action 'self';frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests - cross-origin-opener-policy: same-origin - cross-origin-resource-policy: same-origin - origin-agent-cluster: ?1 - referrer-policy: no-referrer - strict-transport-security: max-age=15552000; includeSubDomains - x-content-type-options: nosniff - x-dns-prefetch-control: off - x-download-options: noopen - x-frame-options: SAMEORIGIN - x-permitted-cross-domain-policies: none - x-xss-protection: 0 - vary: Origin - content-type: application/json; charset=utf-8 - content-length: 188 - etag: W/"bc-zzMUocEciwDg2nB6sNMwISzp/U0" - date: Mon, 30 Sep 2024 06:45:20 GMT - connection: keep-alive - keep-alive: timeout=5 Response text: {"error":"Internal error: Error: Error: Broadcasting transaction failed with code 32 (codespace: sdk). Log: account sequence mismatch, expected 1647, got 1646: incorrect account sequence"} 119 | }); 120 | const { didUrls, accreditation } = await issueResponse.json(); > 121 | expect(issueResponse).toBeOK(); | ^ 122 | expect(issueResponse.status()).toBe(StatusCodes.OK); 123 | expect(accreditation.proof.type).toBe('JwtProof2020'); 124 | expect(accreditation.proof).toHaveProperty('jwt'); at /home/runner/work/studio/studio/tests/e2e/parallel/accreditation/issue-verify-flow.spec.ts:121:24
expect(issueResponse.status()).toBe(StatusCodes.OK);

Check failure on line 122 in tests/e2e/parallel/accreditation/issue-verify-flow.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Parallel Logged In User Tests] › parallel/accreditation/issue-verify-flow.spec.ts:112:1 › Issue and verify a attest accreditation

3) [Parallel Logged In User Tests] › parallel/accreditation/issue-verify-flow.spec.ts:112:1 › Issue and verify a attest accreditation Error: expect(received).toBe(expected) // Object.is equality Expected: 200 Received: 500 120 | const { didUrls, accreditation } = await issueResponse.json(); 121 | expect(issueResponse).toBeOK(); > 122 | expect(issueResponse.status()).toBe(StatusCodes.OK); | ^ 123 | expect(accreditation.proof.type).toBe('JwtProof2020'); 124 | expect(accreditation.proof).toHaveProperty('jwt'); 125 | expect(typeof accreditation.issuer === 'string' ? accreditation.issuer : accreditation.issuer.id).toBe( at /home/runner/work/studio/studio/tests/e2e/parallel/accreditation/issue-verify-flow.spec.ts:122:33
expect(accreditation.proof.type).toBe('JwtProof2020');
expect(accreditation.proof).toHaveProperty('jwt');
expect(typeof accreditation.issuer === 'string' ? accreditation.issuer : accreditation.issuer.id).toBe(
credentialData.issuerDid
);
expect(accreditation.type).toContain('VerifiableCredential');
expect(accreditation.credentialSubject).toMatchObject({
...credentialData.attributes,
id: credentialData.subjectDid,
});
expect(didUrls).toHaveLength(2);
expect(didUrls).toContain(
`did:cheqd:testnet:BjS4Nv8bVdxm2WW28MCfXA?resourceName=attestAccreditation&resourceType=VerifiableAccreditationToAttest`
);

const verifyResponse = await request.post(`/accreditation/verify`, {
data: JSON.stringify({
subjectDid: `${credentialData.subjectDid}`,
accreditation: `did:cheqd:testnet:BjS4Nv8bVdxm2WW28MCfXA?resourceName=attestAccreditation&resourceType=VerifiableAccreditationToAttest`,
}),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
},
});
const result = await verifyResponse.json();
expect(verifyResponse).toBeOK();
expect(verifyResponse.status()).toBe(StatusCodes.OK);
expect(result.error).toBe(undefined);
expect(result.verified).toBe(true);
});
14 changes: 14 additions & 0 deletions tests/e2e/payloads/accreditation/accredit-jwt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"issuerDid": "did:cheqd:testnet:15b74787-6e48-4fd5-8020-eab24e990578",
"subjectDid": "did:cheqd:testnet:BjS4Nv8bVdxm2WW28MCfXA",
"schemas": [
{
"url": "https://schema.org/Person",
"type": "Person"
}
],
"format": "jwt",
"accreditationName": "accreditAccreditation",
"parentAccreditation": "did:cheqd:testnet:5RpEg66jhhbmASWPXJRWrA?resourceName=authorizeAccreditation&resourceType=VerifiableAuthorisationForTrustChain",
"rootAuthroization": "did:cheqd:testnet:5RpEg66jhhbmASWPXJRWrA?resourceName=authorizeAccreditation&resourceType=VerifiableAuthorisationForTrustChain"
}
12 changes: 0 additions & 12 deletions tests/e2e/payloads/accreditation/accreditation-accredit-jwt.json

This file was deleted.

14 changes: 14 additions & 0 deletions tests/e2e/payloads/accreditation/attest-jwt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"issuerDid": "did:cheqd:testnet:BjS4Nv8bVdxm2WW28MCfXA",
"subjectDid": "did:cheqd:testnet:33c96aca-9c65-4ebf-8807-b40b0fa928f4",
"schemas": [
{
"url": "https://schema.org/Person",
"type": "Person"
}
],
"format": "jwt",
"accreditationName": "accreditAccreditation",
"parentAccreditation": "did:cheqd:testnet:BjS4Nv8bVdxm2WW28MCfXA?resourceName=accreditAuthorization&resoourceType=",
"rootAuthroization": "did:cheqd:testnet:5RpEg66jhhbmASWPXJRWrA?resourceName=authorizeAccreditation&resourceType=VerifiableAuthorisationForTrustChain"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
}
],
"format": "jwt",
"accreditationName": "accreditAccreditation",
"rootAuthroization": "did:cheqd:testnet:5RpEg66jhhbmASWPXJRWrA?resourceName=rootAccreditation&resourceType=VerifiableAuthorisationForTrustChain"
"accreditationName": "authorizeAccreditation"
}

0 comments on commit 022639b

Please sign in to comment.