Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: v0.9.9 - offers aggregation and service type #95

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/sample-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@fastify/autoload": "~5.7.1",
"env-var": "~7.3.0",
"fastify": "~4.15.0",
"@velocitycareerlabs/vnf-nodejs-wallet-sdk": "^0.9.8"
"@velocitycareerlabs/vnf-nodejs-wallet-sdk": "^0.9.9"
},
"devDependencies": {
"@jest/globals": "~29.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@velocitycareerlabs/vnf-nodejs-wallet-sdk",
"version": "0.9.8",
"version": "0.9.9",
"description": "VNF Wallet SDK Nodejs",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/api/entities/VCLOffers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class VCLOffers {
if (payload) {
if (Array.isArray(payload)) {
return new VCLOffers(
payload,
{ [VCLOffers.CodingKeys.KeyOffers]: payload },
VCLOffers.offersFromJsonArray(payload),
responseCode,
sessionToken
Expand Down
39 changes: 28 additions & 11 deletions packages/sdk/src/api/entities/VCLServiceType.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
enum VCLServiceType {
Inspector = "Inspector",
Issuer = "Issuer",
IdentityIssuer = "IdentityIssuer",
NotaryIssuer = "NotaryIssuer",
CareerIssuer = "CareerIssuer",
Undefined = "Undefined",
Inspector = 'Inspector',
Issuer = 'Issuer',
NotaryIssuer = 'NotaryIssuer',
CareerIssuer = 'CareerIssuer',
// Identity issuer types:
IdentityIssuer = 'IdentityIssuer',
IdDocumentIssuer = 'IdDocumentIssuer',
NotaryIdDocumentIssuer = 'NotaryIdDocumentIssuer',
ContactIssuer = 'ContactIssuer',
NotaryContactIssuer = 'NotaryContactIssuer',
Undefined = 'Undefined',
}
export default VCLServiceType;

export const serviceTypeFromString = (value: string): VCLServiceType => {
if (value.includes(VCLServiceType.Inspector)) {
if (value.includes(VCLServiceType.Inspector.toString())) {
return VCLServiceType.Inspector;
}
if (value.includes(VCLServiceType.NotaryIssuer)) {
if (value.includes(VCLServiceType.NotaryIssuer.toString())) {
return VCLServiceType.NotaryIssuer;
}
if (value.includes(VCLServiceType.IdentityIssuer)) {
if (value.includes(VCLServiceType.IdentityIssuer.toString())) {
return VCLServiceType.IdentityIssuer;
}
if (value.includes(VCLServiceType.CareerIssuer)) {
if (value.includes(VCLServiceType.CareerIssuer.toString())) {
return VCLServiceType.CareerIssuer;
}
if (value.includes(VCLServiceType.Issuer)) {
if (value.includes(VCLServiceType.NotaryIdDocumentIssuer.toString())) {
return VCLServiceType.NotaryIdDocumentIssuer;
}
if (value.includes(VCLServiceType.IdDocumentIssuer.toString())) {
return VCLServiceType.IdDocumentIssuer;
}
if (value.includes(VCLServiceType.NotaryContactIssuer.toString())) {
return VCLServiceType.NotaryContactIssuer;
}
if (value.includes(VCLServiceType.ContactIssuer.toString())) {
return VCLServiceType.ContactIssuer;
}
if (value.includes(VCLServiceType.Issuer.toString())) {
return VCLServiceType.Issuer;
}
return VCLServiceType.Undefined;
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/test/entities/VCLOffers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ describe("VCLOffers tests", () => {
);

test("VCLOffers from array test", async () => {
expect(subject1.payload).toEqual(JSON.parse(OffersMocks.offersJsonArrayStr));
expect(subject1.payload[VCLOffers.CodingKeys.KeyOffers]).toStrictEqual(JSON.parse(OffersMocks.offersJsonArrayStr));
testExpectations(subject1);
expect(subject1.challenge).toBe(null);
expect(subject1.all.map((offer) => offer.payload)).toStrictEqual(JSON.parse(OffersMocks.offersJsonArrayStr));
})

test("VCLOffers from object test", async () => {
expect(subject2.payload).toEqual(JSON.parse(OffersMocks.offersJsonObjectStr));
expect(subject2.payload).toStrictEqual(JSON.parse(OffersMocks.offersJsonObjectStr));
testExpectations(subject2);
expect(subject2.challenge).toBe(OffersMocks.challenge);
expect(subject2.all.map((offer) => offer.payload)).toStrictEqual(JSON.parse(OffersMocks.offersJsonArrayStr));
})

test("VCLOffers from emprty array test", async () => {
expect(subject3.payload).toEqual(JSON.parse(OffersMocks.offersJsonEmptyArrayStr));
expect(subject3.payload[VCLOffers.CodingKeys.KeyOffers]).toStrictEqual(JSON.parse(OffersMocks.offersJsonEmptyArrayStr));
testExpectations(subject1);
expect(subject3.challenge).toBe(null);
expect(subject3.all.map((offer) => offer.payload)).toStrictEqual(JSON.parse(OffersMocks.offersJsonEmptyArrayStr));
})

test("VCLOffers from empty object test", async () => {
expect(subject4.payload).toEqual(JSON.parse(OffersMocks.offersJsonEmptyObjectStr));
expect(subject4.payload).toStrictEqual(JSON.parse(OffersMocks.offersJsonEmptyObjectStr));
testExpectations(subject2);
expect(subject4.challenge).toBe(OffersMocks.challenge);
expect(subject4.all.map((offer) => offer.payload)).toStrictEqual(JSON.parse(OffersMocks.offersJsonEmptyArrayStr));
Expand Down
48 changes: 40 additions & 8 deletions packages/sdk/test/entities/VCLServiceType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import VCLServiceType, {

describe("VCLServiceType Tests", () => {
test("testFromExactString", () => {
expect(serviceTypeFromString("Issuer")).toBe(VCLServiceType.Issuer);
expect(serviceTypeFromString("Inspector")).toBe(
VCLServiceType.Inspector
);
Expand All @@ -17,6 +16,24 @@ describe("VCLServiceType Tests", () => {
expect(serviceTypeFromString("IdentityIssuer")).toBe(
VCLServiceType.IdentityIssuer
);
expect(serviceTypeFromString("CareerIssuer")).toBe(
VCLServiceType.CareerIssuer
);
expect(serviceTypeFromString("IdDocumentIssuer")).toBe(
VCLServiceType.IdDocumentIssuer
);
expect(serviceTypeFromString("NotaryIdDocumentIssuer")).toBe(
VCLServiceType.NotaryIdDocumentIssuer
);
expect(serviceTypeFromString("NotaryContactIssuer")).toBe(
VCLServiceType.NotaryContactIssuer
);
expect(serviceTypeFromString("ContactIssuer")).toBe(
VCLServiceType.ContactIssuer
);
expect(serviceTypeFromString("Issuer")).toBe(
VCLServiceType.Issuer
);
expect(serviceTypeFromString("OtherService")).toBe(
VCLServiceType.Undefined
);
Expand All @@ -26,21 +43,36 @@ describe("VCLServiceType Tests", () => {
});

test("testFromNonExactString", () => {
expect(serviceTypeFromString("11_Issuer6_2")).toBe(
VCLServiceType.Issuer
);
expect(serviceTypeFromString("hyre_8Inspector09_nf")).toBe(
expect(serviceTypeFromString(",dfm%InspectorGH*(T")).toBe(
VCLServiceType.Inspector
);
expect(serviceTypeFromString("9jfCareerIssuer@#$%")).toBe(
expect(serviceTypeFromString("234CareerIssuer95R")).toBe(
VCLServiceType.CareerIssuer
);
expect(serviceTypeFromString(")64fhsNotaryIssuer")).toBe(
expect(serviceTypeFromString("*%$NotaryIssuer3k42j2n4")).toBe(
VCLServiceType.NotaryIssuer
);
expect(serviceTypeFromString("IdentityIssuer05%#Rg&*")).toBe(
expect(serviceTypeFromString("9834RFIdentityIssuer^3&^")).toBe(
VCLServiceType.IdentityIssuer
);
expect(serviceTypeFromString("iu34CareerIssuer^#4f")).toBe(
VCLServiceType.CareerIssuer
);
expect(serviceTypeFromString("398%IdDocumentIssuer^DDd3")).toBe(
VCLServiceType.IdDocumentIssuer
);
expect(serviceTypeFromString("3kjnke9@NotaryIdDocumentIssuer@%^")).toBe(
VCLServiceType.NotaryIdDocumentIssuer
);
expect(serviceTypeFromString("03fNotaryContactIssuer04gvd")).toBe(
VCLServiceType.NotaryContactIssuer
);
expect(serviceTypeFromString("0fhe3ContactIssuer43f")).toBe(
VCLServiceType.ContactIssuer
);
expect(serviceTypeFromString("eskld#Issuerdkdf")).toBe(
VCLServiceType.Issuer
);
expect(serviceTypeFromString("ksdjhkD#OtherService959)%")).toBe(
VCLServiceType.Undefined
);
Expand Down
Loading