You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: features/finances/impl/src/test/kotlin/br/com/mob1st/features/finances/impl/data/repositories/suggestions/SelectSuggestionsMapperTest.kt
@@ -94,57 +104,229 @@ class SelectSuggestionsMapperTest {
94
104
fun`GIVEN a list of suggestions And a linked category with nullable name WHEN map THEN assert suggestion is discarded And error is logged`() {
95
105
val discardedSuggestion = fixture<SelectSuggestions>().copy(
96
106
sug_id =1,
97
-
sug_name ="night_clubs",
107
+
sug_name =allSuggestionsNames.random().first,
98
108
cat_name =null,
99
109
cat_id =1,
100
110
cat_is_expense =true,
101
111
cat_amount =300_000,
102
112
cat_linked_suggestion_id =1,
103
113
vrc_day_of_week =3,
104
114
)
115
+
val name = allSuggestionsNames.random()
105
116
val persistedSuggestion = fixture<SelectSuggestions>().copy(
106
117
sug_id =2,
107
-
sug_name ="bars",
118
+
sug_name =name.first,
108
119
cat_id =null,
109
120
)
110
121
val actual = mapper.map(CategoryType.Variable, listOf(discardedSuggestion, persistedSuggestion))
111
122
val expected =listOf(
112
123
CategorySuggestion(
113
124
id =RowId(2),
114
-
name =CategorySuggestion.Name.Bars,
125
+
name =name.second,
115
126
linkedCategory =null,
116
127
),
117
128
)
118
129
assertEquals(expected, actual)
130
+
assertTrue(timberTree.logs[0].isError)
119
131
}
120
132
121
133
@Test
122
134
fun`GIVEN a list of suggestions And a linked category with nullable is_expense WHEN map THEN assert suggestion is discarded And error is logged`() {
135
+
val discardedSuggestion = fixture<SelectSuggestions>().copy(
136
+
sug_id =1,
137
+
sug_name = allSuggestionsNames.random().first,
138
+
cat_id =1,
139
+
cat_is_expense =null,
140
+
cat_amount =1000_00,
141
+
cat_linked_suggestion_id =1,
142
+
src_month =1,
143
+
src_day =12,
144
+
)
145
+
val name = allSuggestionsNames.random()
146
+
val persistedSuggestion = fixture<SelectSuggestions>().copy(
147
+
sug_id =2,
148
+
sug_name = name.first,
149
+
cat_id =null,
150
+
)
151
+
val actual = mapper.map(CategoryType.Seasonal, listOf(discardedSuggestion, persistedSuggestion))
152
+
val expected =listOf(
153
+
CategorySuggestion(
154
+
id =RowId(2),
155
+
name = name.second,
156
+
linkedCategory =null,
157
+
),
158
+
)
159
+
assertEquals(expected, actual)
160
+
assertTrue(timberTree.logs[0].isError)
123
161
}
124
162
125
163
@Test
126
164
fun`GIVEN a list of suggestions And a linked category with nullable amount WHEN map THEN assert suggestion is discarded And error is logged`() {
127
-
}
128
-
129
-
@Test
130
-
fun`GIVEN a list of suggestions And a linked category with nullable created_at WHEN map THEN assert empty is used as placeholder for created_at`() {
165
+
val discardedSuggestion = fixture<SelectSuggestions>().copy(
166
+
sug_id =1,
167
+
sug_name = allSuggestionsNames.random().first,
168
+
cat_id =1,
169
+
cat_is_expense =true,
170
+
cat_amount =null,
171
+
cat_linked_suggestion_id =1,
172
+
vrc_day_of_week =3,
173
+
)
174
+
val name = allSuggestionsNames.random()
175
+
val persistedSuggestion = fixture<SelectSuggestions>().copy(
176
+
sug_id =2,
177
+
sug_name = name.first,
178
+
cat_id =null,
179
+
)
180
+
val actual = mapper.map(CategoryType.Variable, listOf(discardedSuggestion, persistedSuggestion))
181
+
val expected =listOf(
182
+
CategorySuggestion(
183
+
id =RowId(2),
184
+
name = name.second,
185
+
linkedCategory =null,
186
+
),
187
+
)
188
+
assertEquals(expected, actual)
189
+
assertTrue(timberTree.logs[0].isError)
131
190
}
132
191
133
192
@Test
134
193
fun`GIVEN a list of suggestions And a linked category with different linked suggestion WHEN map THEN assert suggestion is discarded And error is logged`() {
194
+
val discardedSuggestion = fixture<SelectSuggestions>().copy(
195
+
sug_id =1,
196
+
sug_name = allSuggestionsNames.random().first,
197
+
cat_id =1,
198
+
cat_is_expense =true,
199
+
cat_amount =1000_00,
200
+
cat_linked_suggestion_id =2,
201
+
src_month =1,
202
+
src_day =12,
203
+
)
204
+
val name = allSuggestionsNames.random()
205
+
val persistedSuggestion = fixture<SelectSuggestions>().copy(
206
+
sug_id =2,
207
+
sug_name = name.first,
208
+
cat_id =null,
209
+
)
210
+
val actual = mapper.map(CategoryType.Seasonal, listOf(discardedSuggestion, persistedSuggestion))
211
+
val expected =listOf(
212
+
CategorySuggestion(
213
+
id =RowId(2),
214
+
name = name.second,
215
+
linkedCategory =null,
216
+
),
217
+
)
218
+
assertEquals(expected, actual)
219
+
assertTrue(timberTree.logs[0].isError)
135
220
}
136
221
137
222
@Test
138
-
fun`GIVEN a list of suggestions And a unknown name WHEN map THEN assert suggestion is discarded And message is logged`() {
223
+
fun`GIVEN a list of suggestions And a unknown name WHEN map THEN assert suggestion is discarded And warning is logged`() {
224
+
val discardedSuggestion = fixture<SelectSuggestions>().copy(
225
+
sug_id =1,
226
+
sug_name ="unknown_name",
227
+
cat_id =1,
228
+
cat_is_expense =true,
229
+
cat_amount =1000_00,
230
+
cat_linked_suggestion_id =1,
231
+
src_month =1,
232
+
src_day =12,
233
+
)
234
+
val name = allSuggestionsNames.random()
235
+
val persistedSuggestion = fixture<SelectSuggestions>().copy(
236
+
sug_id =2,
237
+
sug_name = name.first,
238
+
cat_id =null,
239
+
)
240
+
val actual = mapper.map(CategoryType.Seasonal, listOf(discardedSuggestion, persistedSuggestion))
241
+
val expected =listOf(
242
+
CategorySuggestion(
243
+
id =RowId(2),
244
+
name = name.second,
245
+
linkedCategory =null,
246
+
),
247
+
)
248
+
assertEquals(expected, actual)
249
+
assertTrue(timberTree.logs[0].isWarning)
139
250
}
140
251
141
252
@Test
142
-
fun`GIVEN a list of suggestions And two categories are linked to the same suggestion WHEN map THEN assert that only the first category is used And a log message is added`() {
253
+
fun`GIVEN a list of suggestions And two categories are linked to the same suggestion WHEN map THEN assert that only the first category is used And a warning is logged`() {
254
+
val firstSuggestionName = allSuggestionsNames.random()
255
+
val secondSuggestionName = allSuggestionsNames.random()
256
+
val firstSuggestionWithCategory = fixture<SelectSuggestions>().copy(
257
+
sug_id =1,
258
+
sug_name = firstSuggestionName.first,
259
+
cat_id =1,
260
+
cat_name ="any1",
261
+
cat_is_expense =true,
262
+
cat_amount =1000_00,
263
+
cat_linked_suggestion_id =1,
264
+
vrc_day_of_week =4,
265
+
)
266
+
val secondSuggestionWithCategory = fixture<SelectSuggestions>().copy(
267
+
sug_id =1,
268
+
sug_name = firstSuggestionName.first,
269
+
cat_id =2,
270
+
cat_name ="any2",
271
+
cat_is_expense =true,
272
+
cat_amount =2000_00,
273
+
cat_linked_suggestion_id =1,
274
+
vrc_day_of_week =3,
275
+
)
276
+
val suggestionWithoutLinkedCategory = fixture<SelectSuggestions>().copy(
0 commit comments