Skip to content

Commit

Permalink
Merge pull request #77 from velocitycareerlabs/VL-7723
Browse files Browse the repository at this point in the history
presentation submission tests
  • Loading branch information
michaelavoyan authored May 23, 2024
2 parents dcf45c9 + b8caa04 commit 71e9940
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/test/NetworkServiceSuccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Response from "../src/impl/data/infrastructure/network/Response";
import { Dictionary, Nullish } from "../../sdk//src/api/VCLTypes";

export default class NetworkServiceSuccess implements NetworkService {
constructor(private readonly validResponse: string) {}
constructor(private readonly validResponse: any) {}

sendRequestRaw(params: Request): Promise<VCLResult<Response>> {
throw new Error("not implemented");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import VCLResult from "../../../../src/api/entities/VCLResult";
import VCLJwt from "../../../../src/api/entities/VCLJwt";

export class JwtSignServiceMock implements VCLJwtSignService {
constructor(readonly successValue: string) {
constructor(readonly successValue: Nullish<string> = null) {
}
sign(
jwtDescriptor: VCLJwtDescriptor,
didJwk: VCLDidJwk,
nonce: Nullish<string>
): Promise<VCLResult<VCLJwt>> {
return Promise.resolve(new VCLResult.Success(VCLJwt.fromEncodedJwt(this.successValue)));
return Promise.resolve(new VCLResult.Success(VCLJwt.fromEncodedJwt(this.successValue || '')));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ class PresentationSubmissionMocks {
"https://devservices.velocitycareerlabs.io/api/push-gateway",
"if0123asd129smw321"
);
static PresentationSubmissionResultJson =
static PresentationSubmissionResultStr =
'{"token":"u7yLD8KS2eTEqkg9aRQE","exchange":{"id":"64131231","type":"DISCLOSURE","disclosureComplete":true,"exchangeComplete":true}}';
static PresentationSubmissionResultJson =
{
"token": "u7yLD8KS2eTEqkg9aRQE",
"exchange": {
"id": "64131231",
"type": "DISCLOSURE",
"disclosureComplete": true,
"exchangeComplete": true
}
}
static PresentationRequest = new VCLPresentationRequest(
JwtServiceMocks.JWT,
new VCLVerifiedProfile({}),
Expand All @@ -28,6 +38,8 @@ class PresentationSubmissionMocks {
),
new VCLVerifiableCredential("Email", JwtServiceMocks.AdamSmithEmailJwt),
];

static JwtEncodedSubmission = 'eyJraWQiOiJkaWQ6andrOmV5SnJkSGtpT2lKRlF5SXNJblZ6WlNJNkluTnBaeUlzSW1OeWRpSTZJbEF0TWpVMklpd2lhMmxrSWpvaU5qRXhZVGs1TmprdFlqWmpNeTAwWXpJeExXSTFZell0T0dRd01qa3dZMlkwTlRabElpd2llQ0k2SWtacVVsOHhVelZ2WVRkblIydElSRlJsYkhKVGIydHJjMjF0ZEZSa1VFNXRkbTFUVWtSc1FtZHBXVlVpTENKNUlqb2lTRWs0T0hOTFZ6UndlbmxWU0ZSMFFsaGtPR3RQYVZwemVGZGhUSGhxUkVWZlEwdEhWR05GVkRCUU1DSjkjMCIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2IiwiandrIjp7Imt0eSI6IkVDIiwidXNlIjoic2lnIiwiY3J2IjoiUC0yNTYiLCJraWQiOiI2MTFhOTk2OS1iNmMzLTRjMjEtYjVjNi04ZDAyOTBjZjQ1NmUiLCJ4IjoiRmpSXzFTNW9hN2dHa0hEVGVsclNva2tzbW10VGRQTm12bVNSRGxCZ2lZVSIsInkiOiJISTg4c0tXNHB6eVVIVHRCWGQ4a09pWnN4V2FMeGpERV9DS0dUY0VUMFAwIn19.eyJzdWIiOiJlSWZXUmhqSkNMIiwibmJmIjoxNzE2NDUwMDExLCJpc3MiOiJkaWQ6andrOmV5SnJkSGtpT2lKRlF5SXNJblZ6WlNJNkluTnBaeUlzSW1OeWRpSTZJbEF0TWpVMklpd2lhMmxrSWpvaU5qRXhZVGs1TmprdFlqWmpNeTAwWXpJeExXSTFZell0T0dRd01qa3dZMlkwTlRabElpd2llQ0k2SWtacVVsOHhVelZ2WVRkblIydElSRlJsYkhKVGIydHJjMjF0ZEZSa1VFNXRkbTFUVWtSc1FtZHBXVlVpTENKNUlqb2lTRWs0T0hOTFZ6UndlbmxWU0ZSMFFsaGtPR3RQYVZwemVGZGhUSGhxUkVWZlEwdEhWR05GVkRCUU1DSjkiLCJ2cCI6eyJ0eXBlIjoiVmVyaWZpYWJsZVByZXNlbnRhdGlvbiIsInByZXNlbnRhdGlvbl9zdWJtaXNzaW9uIjp7ImlkIjoiN2U0NjM3MzktZGRlMC00OTU2LWFlNTYtMjk4MDQ5YmY3MzVlIiwiZGVmaW5pdGlvbl9pZCI6IiIsImRlc2NyaXB0b3JfbWFwIjpbXX0sInZlcmlmaWFibGVDcmVkZW50aWFsIjpbXX0sImV4cCI6MTcxNzA1NDgxMSwiaWF0IjoxNzE2NDUwMDExLCJqdGkiOiIxOTllOWRiMC1mNDg5LTQ1MjAtOGYyNy1hYjM4N2NjMzQ4MWQifQ';
}

export { PresentationSubmissionMocks };
5 changes: 3 additions & 2 deletions packages/sdk/test/usecases/PresentationRequestUseCase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import {
} from "../../src";
import { DeepLinkMocks } from "../infrastructure/resources/valid/DeepLinkMocks";
import { DidJwkMocks } from "../infrastructure/resources/valid/DidJwkMocks";
import PresentationRequestUseCase from "../../src/impl/domain/usecases/PresentationRequestUseCase";

describe("PresentationRequestUseCase Tests", () => {
let subject1: PresentationRequestUseCaseImpl
let subject2: PresentationRequestUseCaseImpl
let subject1: PresentationRequestUseCase
let subject2: PresentationRequestUseCase

test("testGetPresentationRequestSuccess", async () => {
const pushUrl = "push_url"
Expand Down
86 changes: 86 additions & 0 deletions packages/sdk/test/usecases/PresentationSubmissionUseCase.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import PresentationRequestUseCaseImpl from "../../src/impl/data/usecases/PresentationRequestUseCaseImpl";
import PresentationRequestRepositoryImpl from "../../src/impl/data/repositories/PresentationRequestRepositoryImpl";
import NetworkServiceSuccess from "../NetworkServiceSuccess";
import { PresentationRequestMocks } from "../infrastructure/resources/valid/PresentationRequestMocks";
import ResolveKidRepositoryImpl from "../../src/impl/data/repositories/ResolveKidRepositoryImpl";
import JwtServiceRepositoryImpl from "../../src/impl/data/repositories/JwtServiceRepositoryImpl";
import { JwtSignServiceMock } from "../infrastructure/resources/jwt/JwtSignServiceMock";
import { JwtVerifyServiceMock } from "../infrastructure/resources/jwt/JwtVerifyServiceMock";
import {
Dictionary,
VCLDeepLink,
VCLErrorCode, VCLExchange, VCLPresentationRequest,
VCLPresentationRequestDescriptor, VCLPresentationSubmission,
VCLPushDelegate, VCLSubmissionResult,
VCLToken,
VCLVerifiedProfile
} from "../../src";
import { DeepLinkMocks } from "../infrastructure/resources/valid/DeepLinkMocks";
import { DidJwkMocks } from "../infrastructure/resources/valid/DidJwkMocks";
import PresentationSubmissionUseCase from "../../src/impl/domain/usecases/PresentationSubmissionUseCase";
import { beforeAll, expect } from "@jest/globals";
import PresentationSubmissionUseCaseImpl from "../../src/impl/data/usecases/PresentationSubmissionUseCaseImpl";
import { PresentationSubmissionMocks } from "../infrastructure/resources/valid/PresentationSubmissionMocks";
import SubmissionRepositoryImpl from "../../src/impl/data/repositories/SubmissionRepositoryImpl";
import { CommonMocks } from "../infrastructure/resources/CommonMocks";

describe("PresentationSubmission Tests", () => {
const subject = new PresentationSubmissionUseCaseImpl(
new SubmissionRepositoryImpl(
new NetworkServiceSuccess(PresentationSubmissionMocks.PresentationSubmissionResultJson)
),
new JwtServiceRepositoryImpl(
new JwtSignServiceMock(PresentationSubmissionMocks.JwtEncodedSubmission),
new JwtVerifyServiceMock()
)

)
const didJwk = DidJwkMocks.DidJwk
const presentationSubmission = new VCLPresentationSubmission(
new VCLPresentationRequest(
CommonMocks.JWT,
new VCLVerifiedProfile({}),
new VCLDeepLink(""),
null,
didJwk
),
[],
)
const expectedExchange = (exchangeJsonObj: Dictionary<any>): VCLExchange => {
return new VCLExchange(
exchangeJsonObj[VCLExchange.KeyId],
exchangeJsonObj[VCLExchange.KeyType],
exchangeJsonObj[VCLExchange.KeyDisclosureComplete],
exchangeJsonObj[VCLExchange.KeyExchangeComplete]
);
}
const generatePresentationSubmissionResult = (
jsonObj: Dictionary<any>,
jti: string,
submissionId: string
): VCLSubmissionResult => {
const exchangeJsonObj = jsonObj[VCLSubmissionResult.KeyExchange];
return new VCLSubmissionResult(
new VCLToken(jsonObj[VCLSubmissionResult.KeyToken]),
expectedExchange(exchangeJsonObj),
jti,
submissionId
);
}
const expectedPresentationSubmissionResult =
generatePresentationSubmissionResult(
PresentationSubmissionMocks.PresentationSubmissionResultJson,
presentationSubmission.jti,
presentationSubmission.submissionId
)
test("testGetPresentationRequestSuccess", async () => {
const result = await subject.submit(presentationSubmission)
const [error, presentationSubmissionResult] = result.handleResult()

expect(presentationSubmissionResult?.sessionToken.value).toBe(expectedPresentationSubmissionResult.sessionToken.value)
expect(presentationSubmissionResult?.exchange.id).toBe(expectedPresentationSubmissionResult.exchange.id)
expect(presentationSubmissionResult?.jti).toBe(expectedPresentationSubmissionResult.jti)
expect(presentationSubmissionResult?.submissionId).toBe(expectedPresentationSubmissionResult.submissionId)
expect(error).toBeNull()
});
});

0 comments on commit 71e9940

Please sign in to comment.