forked from tab/smartid
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathidentity_test.go
More file actions
182 lines (174 loc) · 3.42 KB
/
identity_test.go
File metadata and controls
182 lines (174 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package smartid
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/proDeveloperGuru/smartid/internal/errors"
)
func Test_Identity_String(t *testing.T) {
tests := []struct {
name string
kind string
country string
id string
expected string
}{
{
name: "IDC",
kind: TypeIDC,
country: "EE",
id: "30303039914",
expected: "IDCEE-30303039914",
},
{
name: "PAS",
kind: TypePAS,
country: "EE",
id: "30303039914",
expected: "PASEE-30303039914",
},
{
name: "PNO",
kind: TypePNO,
country: "EE",
id: "30303039914",
expected: "PNOEE-30303039914",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
identity := NewIdentity(tt.kind, tt.country, tt.id)
assert.Equal(t, tt.expected, identity)
})
}
}
func Test_Identity_Parse(t *testing.T) {
tests := []struct {
name string
input string
valid bool
expect *Identity
err error
}{
{
name: "Success: PNOEE-30303039914",
input: "PNOEE-30303039914",
valid: true,
expect: &Identity{
Type: TypePNO,
Country: "EE",
ID: "30303039914",
},
},
{
name: "Success: PASEE-30303039914",
input: "PASEE-30303039914",
valid: true,
expect: &Identity{
Type: TypePAS,
Country: "EE",
ID: "30303039914",
},
},
{
name: "Success: IDCEE-30303039914",
input: "IDCEE-30303039914",
valid: true,
expect: &Identity{
Type: TypeIDC,
Country: "EE",
ID: "30303039914",
},
},
{
name: "Success: PNOLT-40504040001",
input: "PNOLT-40504040001",
valid: true,
expect: &Identity{
Type: TypePNO,
Country: "LT",
ID: "40504040001",
},
},
{
name: "Success: PNOLV-050405-10009",
input: "PNOLV-050405-10009",
valid: true,
expect: &Identity{
Type: TypePNO,
Country: "LV",
ID: "050405-10009",
},
},
{
name: "Success: PNOBE-05040400032",
input: "PNOBE-05040400032",
valid: true,
expect: &Identity{
Type: TypePNO,
Country: "BE",
ID: "05040400032",
},
},
{
name: "Error: invalid identity",
input: "PNOEE-30303039914#",
valid: false,
expect: nil,
err: errors.ErrInvalidIdentityNumber,
},
{
name: "Error: missing identifier",
input: "PNOEE-",
valid: false,
expect: nil,
err: errors.ErrInvalidIdentityNumber,
},
{
name: "Error: missing hyphen",
input: "PNOEE30303039914",
valid: false,
expect: nil,
err: errors.ErrInvalidIdentityNumber,
},
{
name: "Error: missing type",
input: "EE-30303039914",
valid: false,
expect: nil,
err: errors.ErrInvalidIdentityNumber,
},
{
name: "Error: missing country",
input: "PNO-30303039914",
valid: false,
expect: nil,
err: errors.ErrInvalidIdentityNumber,
},
{
name: "Error: missing country and type",
input: "30303039914",
valid: false,
expect: nil,
err: errors.ErrInvalidIdentityNumber,
},
{
name: "Error: empty",
input: "",
valid: false,
expect: nil,
err: errors.ErrEmptyIdentityNumber,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
identity, err := Parse(tt.input)
if tt.valid {
assert.NoError(t, err)
assert.Equal(t, tt.expect, identity)
} else {
assert.Error(t, err)
assert.Equal(t, tt.err, err)
}
})
}
}