1
|
|
|
package domain_test |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"testing" |
5
|
|
|
|
6
|
|
|
"github.com/memnix/memnix-rest/domain" |
7
|
|
|
) |
8
|
|
|
|
9
|
|
|
func TestCard_String(t *testing.T) { |
10
|
|
|
card := &domain.Card{ |
11
|
|
|
Question: "What is the capital of France?", |
12
|
|
|
Answer: "Paris", |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
expected := "What is the capital of France? Paris" |
16
|
|
|
result := card.String() |
17
|
|
|
|
18
|
|
|
if result != expected { |
19
|
|
|
t.Errorf("Expected result to be %q, but got %q", expected, result) |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
func TestCard_TableName(t *testing.T) { |
24
|
|
|
card := &domain.Card{} |
25
|
|
|
expected := "cards" |
26
|
|
|
result := card.TableName() |
27
|
|
|
|
28
|
|
|
if result != expected { |
29
|
|
|
t.Errorf("Expected result to be %q, but got %q", expected, result) |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
func TestCard_IsBlankType(t *testing.T) { |
34
|
|
|
testCases := []struct { |
35
|
|
|
name string |
36
|
|
|
cardType domain.CardType |
37
|
|
|
expected bool |
38
|
|
|
}{ |
39
|
|
|
{ |
40
|
|
|
name: "CardTypeBlankOnly", |
41
|
|
|
cardType: domain.CardTypeBlankOnly, |
42
|
|
|
expected: true, |
43
|
|
|
}, |
44
|
|
|
{ |
45
|
|
|
name: "CardTypeBlankProgressive", |
46
|
|
|
cardType: domain.CardTypeBlankProgressive, |
47
|
|
|
expected: true, |
48
|
|
|
}, |
49
|
|
|
{ |
50
|
|
|
name: "CardTypeBlankMCQ", |
51
|
|
|
cardType: domain.CardTypeBlankMCQ, |
52
|
|
|
expected: true, |
53
|
|
|
}, |
54
|
|
|
{ |
55
|
|
|
name: "CardTypeQAOnly", |
56
|
|
|
cardType: domain.CardTypeQAOnly, |
57
|
|
|
expected: false, |
58
|
|
|
}, |
59
|
|
|
{ |
60
|
|
|
name: "CardTypeMCQOnly", |
61
|
|
|
cardType: domain.CardTypeMCQOnly, |
62
|
|
|
expected: false, |
63
|
|
|
}, |
64
|
|
|
{ |
65
|
|
|
name: "CardTypeQAProgressive", |
66
|
|
|
cardType: domain.CardTypeQAProgressive, |
67
|
|
|
expected: false, |
68
|
|
|
}, |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
for _, tc := range testCases { |
72
|
|
|
t.Run(tc.name, func(t *testing.T) { |
73
|
|
|
card := &domain.Card{ |
74
|
|
|
CardType: tc.cardType, |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
result := card.IsBlankType() |
78
|
|
|
|
79
|
|
|
if result != tc.expected { |
80
|
|
|
t.Errorf("Expected result to be %v, but got %v", tc.expected, result) |
81
|
|
|
} |
82
|
|
|
}) |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
func TestCard_HasMcqType(t *testing.T) { |
87
|
|
|
testCases := []struct { |
88
|
|
|
name string |
89
|
|
|
cardType domain.CardType |
90
|
|
|
expected bool |
91
|
|
|
}{ |
92
|
|
|
{ |
93
|
|
|
name: "CardTypeBlankOnly", |
94
|
|
|
cardType: domain.CardTypeBlankOnly, |
95
|
|
|
expected: false, |
96
|
|
|
}, |
97
|
|
|
{ |
98
|
|
|
name: "CardTypeBlankProgressive", |
99
|
|
|
cardType: domain.CardTypeBlankProgressive, |
100
|
|
|
expected: true, |
101
|
|
|
}, |
102
|
|
|
{ |
103
|
|
|
name: "CardTypeBlankMCQ", |
104
|
|
|
cardType: domain.CardTypeBlankMCQ, |
105
|
|
|
expected: true, |
106
|
|
|
}, |
107
|
|
|
{ |
108
|
|
|
name: "CardTypeQAOnly", |
109
|
|
|
cardType: domain.CardTypeQAOnly, |
110
|
|
|
expected: false, |
111
|
|
|
}, |
112
|
|
|
{ |
113
|
|
|
name: "CardTypeMCQOnly", |
114
|
|
|
cardType: domain.CardTypeMCQOnly, |
115
|
|
|
expected: true, |
116
|
|
|
}, |
117
|
|
|
{ |
118
|
|
|
name: "CardTypeQAProgressive", |
119
|
|
|
cardType: domain.CardTypeQAProgressive, |
120
|
|
|
expected: true, |
121
|
|
|
}, |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
for _, tc := range testCases { |
125
|
|
|
t.Run(tc.name, func(t *testing.T) { |
126
|
|
|
card := &domain.Card{ |
127
|
|
|
CardType: tc.cardType, |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
result := card.HasMcqType() |
131
|
|
|
|
132
|
|
|
if result != tc.expected { |
133
|
|
|
t.Errorf("Expected result to be %v, but got %v", tc.expected, result) |
134
|
|
|
} |
135
|
|
|
}) |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
func TestCard_IsMcqType(t *testing.T) { |
140
|
|
|
testCases := []struct { |
141
|
|
|
name string |
142
|
|
|
cardType domain.CardType |
143
|
|
|
expected bool |
144
|
|
|
}{ |
145
|
|
|
{ |
146
|
|
|
name: "CardTypeBlankOnly", |
147
|
|
|
cardType: domain.CardTypeBlankOnly, |
148
|
|
|
expected: false, |
149
|
|
|
}, |
150
|
|
|
{ |
151
|
|
|
name: "CardTypeBlankProgressive", |
152
|
|
|
cardType: domain.CardTypeBlankProgressive, |
153
|
|
|
expected: false, |
154
|
|
|
}, |
155
|
|
|
{ |
156
|
|
|
name: "CardTypeBlankMCQ", |
157
|
|
|
cardType: domain.CardTypeBlankMCQ, |
158
|
|
|
expected: true, |
159
|
|
|
}, |
160
|
|
|
{ |
161
|
|
|
name: "CardTypeQAOnly", |
162
|
|
|
cardType: domain.CardTypeQAOnly, |
163
|
|
|
expected: false, |
164
|
|
|
}, |
165
|
|
|
{ |
166
|
|
|
name: "CardTypeMCQOnly", |
167
|
|
|
cardType: domain.CardTypeMCQOnly, |
168
|
|
|
expected: true, |
169
|
|
|
}, |
170
|
|
|
{ |
171
|
|
|
name: "CardTypeQAProgressive", |
172
|
|
|
cardType: domain.CardTypeQAProgressive, |
173
|
|
|
expected: false, |
174
|
|
|
}, |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
for _, tc := range testCases { |
178
|
|
|
t.Run(tc.name, func(t *testing.T) { |
179
|
|
|
card := &domain.Card{ |
180
|
|
|
CardType: tc.cardType, |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
result := card.IsMcqType() |
184
|
|
|
|
185
|
|
|
if result != tc.expected { |
186
|
|
|
t.Errorf("Expected result to be %v, but got %v", tc.expected, result) |
187
|
|
|
} |
188
|
|
|
}) |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
func TestCard_IsQAOnlyType(t *testing.T) { |
193
|
|
|
testCases := []struct { |
194
|
|
|
name string |
195
|
|
|
cardType domain.CardType |
196
|
|
|
expected bool |
197
|
|
|
}{ |
198
|
|
|
{ |
199
|
|
|
name: "CardTypeBlankOnly", |
200
|
|
|
cardType: domain.CardTypeBlankOnly, |
201
|
|
|
expected: false, |
202
|
|
|
}, |
203
|
|
|
{ |
204
|
|
|
name: "CardTypeBlankProgressive", |
205
|
|
|
cardType: domain.CardTypeBlankProgressive, |
206
|
|
|
expected: false, |
207
|
|
|
}, |
208
|
|
|
{ |
209
|
|
|
name: "CardTypeBlankMCQ", |
210
|
|
|
cardType: domain.CardTypeBlankMCQ, |
211
|
|
|
expected: false, |
212
|
|
|
}, |
213
|
|
|
{ |
214
|
|
|
name: "CardTypeQAOnly", |
215
|
|
|
cardType: domain.CardTypeQAOnly, |
216
|
|
|
expected: true, |
217
|
|
|
}, |
218
|
|
|
{ |
219
|
|
|
name: "CardTypeMCQOnly", |
220
|
|
|
cardType: domain.CardTypeMCQOnly, |
221
|
|
|
expected: false, |
222
|
|
|
}, |
223
|
|
|
{ |
224
|
|
|
name: "CardTypeQAProgressive", |
225
|
|
|
cardType: domain.CardTypeQAProgressive, |
226
|
|
|
expected: false, |
227
|
|
|
}, |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
for _, tc := range testCases { |
231
|
|
|
t.Run(tc.name, func(t *testing.T) { |
232
|
|
|
card := &domain.Card{ |
233
|
|
|
CardType: tc.cardType, |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
result := card.IsQAOnlyType() |
237
|
|
|
|
238
|
|
|
if result != tc.expected { |
239
|
|
|
t.Errorf("Expected result to be %v, but got %v", tc.expected, result) |
240
|
|
|
} |
241
|
|
|
}) |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
func TestCardType_cardTypeNames(t *testing.T) { |
246
|
|
|
expected := map[domain.CardType]string{ |
247
|
|
|
domain.CardTypeQAOnly: "QAOnly", |
248
|
|
|
domain.CardTypeMCQOnly: "MCQOnly", |
249
|
|
|
domain.CardTypeQAProgressive: "QAProgressive", |
250
|
|
|
domain.CardTypeBlankOnly: "BlankOnly", |
251
|
|
|
domain.CardTypeBlankProgressive: "BlankProgressive", |
252
|
|
|
domain.CardTypeBlankMCQ: "BlankMCQ", |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
for k, v := range expected { |
256
|
|
|
result := k.String() |
257
|
|
|
if result != v { |
258
|
|
|
t.Errorf("Expected result to be %q, but got %q", v, result) |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|