@@ -7,7 +7,77 @@ describe("DID types", () => {
7
7
expect ( DIDHelpers . codes ) . toBeDefined ( ) ;
8
8
expect ( DIDHelpers . fromLabel ) . toBeDefined ( ) ;
9
9
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
+ } ) ;
12
82
} ) ;
13
83
} ) ;
0 commit comments