Skip to content
This repository was archived by the owner on Nov 29, 2021. It is now read-only.

Commit 02811eb

Browse files
Guillaume NicolasNigui
authored andcommitted
test: add did helpers coverage
1 parent 9fab165 commit 02811eb

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

__tests__/functions/delegate/functions.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,15 @@ describe("Delegate functions", () => {
121121
const unikname = await getCurrentVote(voterInfo.unik.id, http);
122122
expect(unikname).toBeUndefined();
123123
});
124+
125+
it("Should throw if delegate api returns invalid type", () => {
126+
const delegate = activeIndividualDelegates[0];
127+
delegate.type = "invalidType";
128+
mockDelegate(delegate.username, delegate);
129+
const voterInfo = voter(delegate.username);
130+
mockUnik(voterInfo.unik.id, voterInfo.unik);
131+
mockWallet(voterInfo.wallet.address, voterInfo.wallet);
132+
return expect(getCurrentVote(voterInfo.unik.id, http)).rejects.toThrowError(/invalid\ type/);
133+
});
124134
});
125135
});

__tests__/types/did.test.ts

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,77 @@ describe("DID types", () => {
77
expect(DIDHelpers.codes).toBeDefined();
88
expect(DIDHelpers.fromLabel).toBeDefined();
99
expect(DIDHelpers.fromCode).toBeDefined();
10-
const t: DIDType | undefined = DIDHelpers.fromCode(DIDTypes.INDIVIDUAL);
11-
expect(t).toBe("INDIVIDUAL");
10+
expect(DIDHelpers.parseType).toBeDefined();
11+
expect(DIDHelpers.isDIDType).toBeDefined();
12+
});
13+
14+
describe("DIDHelpers.fromCode", () => {
15+
it("Should get label from code", () => {
16+
const t: DIDType | undefined = DIDHelpers.fromCode(DIDTypes.INDIVIDUAL);
17+
expect(t).toBe("INDIVIDUAL");
18+
});
19+
});
20+
21+
describe("DIDHelpers.isDIDType", () => {
22+
it("Should be valid from number", () => {
23+
expect(DIDHelpers.isDIDType(1)).toBe(true);
24+
expect(DIDHelpers.isDIDType(2)).toBe(true);
25+
expect(DIDHelpers.isDIDType(3)).toBe(true);
26+
});
27+
it("Should be invalid from number", () => {
28+
expect(DIDHelpers.isDIDType(-1)).toBe(false);
29+
expect(DIDHelpers.isDIDType(20909)).toBe(false);
30+
expect(DIDHelpers.isDIDType(11000)).toBe(false);
31+
});
32+
33+
it("Should be valid from string", () => {
34+
expect(DIDHelpers.isDIDType("individual")).toBe(true);
35+
expect(DIDHelpers.isDIDType("INDIVIDUAL")).toBe(true);
36+
expect(DIDHelpers.isDIDType("INDiVIDuAL")).toBe(true);
37+
expect(DIDHelpers.isDIDType("organization")).toBe(true);
38+
expect(DIDHelpers.isDIDType("ORGANIZATION")).toBe(true);
39+
expect(DIDHelpers.isDIDType("ORGaNIZATiON")).toBe(true);
40+
expect(DIDHelpers.isDIDType("network")).toBe(true);
41+
expect(DIDHelpers.isDIDType("NETWORK")).toBe(true);
42+
expect(DIDHelpers.isDIDType("netWorK")).toBe(true);
43+
});
44+
45+
it("Should be invalid from string", () => {
46+
expect(DIDHelpers.isDIDType("foo")).toBe(false);
47+
expect(DIDHelpers.isDIDType("bar")).toBe(false);
48+
expect(DIDHelpers.isDIDType("2")).toBe(false);
49+
expect(DIDHelpers.isDIDType("-1")).toBe(false);
50+
});
51+
});
52+
describe("DIDHelpers.parseType", () => {
53+
it("Should be valid from number", () => {
54+
expect(DIDHelpers.parseType(1)).toBe(DIDTypes.INDIVIDUAL);
55+
expect(DIDHelpers.parseType(2)).toBe(DIDTypes.ORGANIZATION);
56+
expect(DIDHelpers.parseType(3)).toBe(DIDTypes.NETWORK);
57+
});
58+
it("Should be invalid from number", () => {
59+
expect(DIDHelpers.parseType(-1)).toBeUndefined();
60+
expect(DIDHelpers.parseType(20909)).toBeUndefined();
61+
expect(DIDHelpers.parseType(11000)).toBeUndefined();
62+
});
63+
64+
it("Should be valid from string", () => {
65+
expect(DIDHelpers.parseType("individual")).toBe(DIDTypes.INDIVIDUAL);
66+
expect(DIDHelpers.parseType("INDIVIDUAL")).toBe(DIDTypes.INDIVIDUAL);
67+
expect(DIDHelpers.parseType("INDiVIDuAL")).toBe(DIDTypes.INDIVIDUAL);
68+
expect(DIDHelpers.parseType("organization")).toBe(DIDTypes.ORGANIZATION);
69+
expect(DIDHelpers.parseType("ORGANIZATION")).toBe(DIDTypes.ORGANIZATION);
70+
expect(DIDHelpers.parseType("ORGaNIZATiON")).toBe(DIDTypes.ORGANIZATION);
71+
expect(DIDHelpers.parseType("network")).toBe(DIDTypes.NETWORK);
72+
expect(DIDHelpers.parseType("NETWORK")).toBe(DIDTypes.NETWORK);
73+
expect(DIDHelpers.parseType("netWorK")).toBe(DIDTypes.NETWORK);
74+
});
75+
76+
it("Should be invalid from string", () => {
77+
expect(DIDHelpers.parseType("foo")).toBeUndefined();
78+
expect(DIDHelpers.parseType("bar")).toBeUndefined();
79+
expect(DIDHelpers.parseType("2")).toBeUndefined();
80+
expect(DIDHelpers.parseType("-1")).toBeUndefined();
81+
});
1282
});
1383
});

0 commit comments

Comments
 (0)