@@ -79,8 +79,8 @@ describe('Create User for Contacts Transition', () => {
79
79
chtDatasourceService = {
80
80
bind : sinon . stub ( )
81
81
} ;
82
- chtDatasourceService . bind . withArgs ( Person . v1 . get ) . resolves ( getPerson ) ;
83
- chtDatasourceService . bind . withArgs ( Place . v1 . get ) . resolves ( getPlace ) ;
82
+ chtDatasourceService . bind . withArgs ( Person . v1 . get ) . returns ( getPerson ) ;
83
+ chtDatasourceService . bind . withArgs ( Place . v1 . get ) . returns ( getPlace ) ;
84
84
createUserForContactsService = {
85
85
isBeingReplaced : sinon . stub ( ) ,
86
86
setReplaced : sinon . stub ( ) ,
@@ -103,10 +103,8 @@ describe('Create User for Contacts Transition', () => {
103
103
} ) ;
104
104
105
105
afterEach ( ( ) => {
106
- if ( chtDatasourceService . bind . notCalled ) {
107
- expect ( getPerson . notCalled ) . to . be . true ;
108
- expect ( getPlace . notCalled ) . to . be . true ;
109
- }
106
+ expect ( chtDatasourceService . bind . args ) . to . deep . equal ( [ [ Place . v1 . get ] , [ Person . v1 . get ] ] ) ;
107
+ sinon . restore ( ) ;
110
108
} ) ;
111
109
112
110
describe ( 'init' , ( ) => {
@@ -116,7 +114,10 @@ describe('Create User for Contacts Transition', () => {
116
114
consoleWarn = sinon . stub ( console , 'warn' ) ;
117
115
} ) ;
118
116
119
- afterEach ( ( ) => sinon . restore ( ) ) ;
117
+ afterEach ( ( ) => {
118
+ expect ( getPerson . notCalled ) . to . be . true ;
119
+ expect ( getPlace . notCalled ) . to . be . true ;
120
+ } ) ;
120
121
121
122
it ( 'returns true when replace forms have been configured' , ( ) => {
122
123
const settings = { create_user_for_contacts : { replace_forms : [ 'replace_user' ] } } ;
@@ -145,6 +146,11 @@ describe('Create User for Contacts Transition', () => {
145
146
} ) ;
146
147
147
148
describe ( 'filter' , ( ) => {
149
+ afterEach ( ( ) => {
150
+ expect ( getPerson . notCalled ) . to . be . true ;
151
+ expect ( getPlace . notCalled ) . to . be . true ;
152
+ } ) ;
153
+
148
154
[
149
155
[ { type : 'data_record' } ] ,
150
156
[ { type : 'person' } , { type : 'user-settings' } , { type : 'data_record' } ] ,
@@ -181,7 +187,8 @@ describe('Create User for Contacts Transition', () => {
181
187
182
188
expect ( docs ) . to . be . empty ;
183
189
expect ( userContactService . get . callCount ) . to . equal ( 0 ) ;
184
- expect ( chtDatasourceService . bind . notCalled ) . to . be . true ;
190
+ expect ( getPerson . notCalled ) . to . be . true ;
191
+ expect ( getPlace . notCalled ) . to . be . true ;
185
192
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 0 ) ;
186
193
expect ( createUserForContactsService . isBeingReplaced . callCount ) . to . equal ( 0 ) ;
187
194
} ) ;
@@ -193,7 +200,8 @@ describe('Create User for Contacts Transition', () => {
193
200
194
201
expect ( docs ) . to . deep . equal ( [ REPLACE_USER_DOC ] ) ;
195
202
expect ( userContactService . get . callCount ) . to . equal ( 1 ) ;
196
- expect ( chtDatasourceService . bind . notCalled ) . to . be . true ;
203
+ expect ( getPerson . notCalled ) . to . be . true ;
204
+ expect ( getPlace . notCalled ) . to . be . true ;
197
205
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 0 ) ;
198
206
expect ( createUserForContactsService . isBeingReplaced . callCount ) . to . equal ( 0 ) ;
199
207
} ) ;
@@ -208,7 +216,8 @@ describe('Create User for Contacts Transition', () => {
208
216
209
217
expect ( docs ) . to . deep . equal ( [ submittedDocs [ 0 ] , submittedDocs [ 2 ] , submittedDocs [ 3 ] ] ) ;
210
218
expect ( userContactService . get . callCount ) . to . equal ( 1 ) ;
211
- expect ( chtDatasourceService . bind . notCalled ) . to . be . true ;
219
+ expect ( getPerson . notCalled ) . to . be . true ;
220
+ expect ( getPlace . notCalled ) . to . be . true ;
212
221
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 0 ) ;
213
222
expect ( createUserForContactsService . isBeingReplaced . callCount ) . to . equal ( 1 ) ;
214
223
expect ( createUserForContactsService . isBeingReplaced . args [ 0 ] ) . to . deep . equal ( [ ORIGINAL_CONTACT ] ) ;
@@ -232,7 +241,6 @@ describe('Create User for Contacts Transition', () => {
232
241
}
233
242
} ] ) ;
234
243
expect ( userContactService . get . callCount ) . to . equal ( 1 ) ;
235
- expect ( chtDatasourceService . bind . args ) . to . deep . equal ( [ [ Person . v1 . get ] , [ Place . v1 . get ] ] ) ;
236
244
expect ( getPerson . calledOnceWithExactly ( Qualifier . byUuid ( NEW_CONTACT . _id ) ) ) . to . be . true ;
237
245
expect ( getPlace . calledOnceWithExactly ( Qualifier . byUuid ( parentPlace . _id ) ) ) . to . be . true ;
238
246
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 1 ) ;
@@ -256,7 +264,7 @@ describe('Create User for Contacts Transition', () => {
256
264
}
257
265
} ] ) ;
258
266
expect ( userContactService . get . callCount ) . to . equal ( 1 ) ;
259
- expect ( chtDatasourceService . bind . args ) . to . deep . equal ( [ [ Place . v1 . get ] ] ) ;
267
+ expect ( getPerson . notCalled ) . to . be . true ;
260
268
expect ( getPlace . calledOnceWithExactly ( Qualifier . byUuid ( parentPlace . _id ) ) ) . to . be . true ;
261
269
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 1 ) ;
262
270
expect ( createUserForContactsService . setReplaced . args [ 0 ] ) . to . deep . equal ( [ originalUser , NEW_CONTACT ] ) ;
@@ -311,10 +319,13 @@ describe('Create User for Contacts Transition', () => {
311
319
expect ( createUserForContactsService . getReplacedBy . args ) . to . deep . equal ( [ [ originalUser ] , [ originalUser ] ] ) ;
312
320
// User replaced again
313
321
expect ( userContactService . get . callCount ) . to . equal ( 1 ) ;
314
- expect ( chtDatasourceService . bind . args ) . to . deep . equal ( [ [ Place . v1 . get ] ] ) ;
322
+ expect ( getPerson . notCalled ) . to . be . true ;
315
323
expect ( getPlace . calledOnceWithExactly ( Qualifier . byUuid ( parentPlace . _id ) ) ) . to . be . true ;
316
324
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 1 ) ;
317
325
expect ( createUserForContactsService . setReplaced . args [ 0 ] ) . to . deep . equal ( [ originalUser , secondNewContact ] ) ;
326
+ // Hack to keep the afterEach assertion happy since we called resetHistory
327
+ chtDatasourceService . bind ( Place . v1 . get ) ;
328
+ chtDatasourceService . bind ( Person . v1 . get ) ;
318
329
} ) ;
319
330
320
331
it ( 'does not assign new contact as primary contact when original contact was not primary' , async ( ) => {
@@ -329,7 +340,6 @@ describe('Create User for Contacts Transition', () => {
329
340
expect ( docs ) . to . deep . equal ( [ REPLACE_USER_DOC , originalUser ] ) ;
330
341
expect ( parentPlace . contact ) . to . deep . equal ( { _id : 'different-contact' , } ) ;
331
342
expect ( userContactService . get . callCount ) . to . equal ( 1 ) ;
332
- expect ( chtDatasourceService . bind . args ) . to . deep . equal ( [ [ Person . v1 . get ] , [ Place . v1 . get ] ] ) ;
333
343
expect ( getPerson . calledOnceWithExactly ( Qualifier . byUuid ( NEW_CONTACT . _id ) ) ) . to . be . true ;
334
344
expect ( getPlace . calledOnceWithExactly ( Qualifier . byUuid ( parentPlace . _id ) ) ) . to . be . true ;
335
345
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 1 ) ;
@@ -347,7 +357,6 @@ describe('Create User for Contacts Transition', () => {
347
357
348
358
expect ( docs ) . to . deep . equal ( [ REPLACE_USER_DOC , originalUser ] ) ;
349
359
expect ( userContactService . get . callCount ) . to . equal ( 1 ) ;
350
- expect ( chtDatasourceService . bind . args ) . to . deep . equal ( [ [ Person . v1 . get ] , [ Place . v1 . get ] ] ) ;
351
360
expect ( getPerson . calledOnceWithExactly ( Qualifier . byUuid ( NEW_CONTACT . _id ) ) ) . to . be . true ;
352
361
expect ( getPlace . calledOnceWithExactly ( Qualifier . byUuid ( PARENT_PLACE . _id ) ) ) . to . be . true ;
353
362
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 1 ) ;
@@ -369,8 +378,8 @@ describe('Create User for Contacts Transition', () => {
369
378
370
379
expect ( docs ) . to . deep . equal ( [ REPLACE_USER_DOC , originalUser ] ) ;
371
380
expect ( userContactService . get . callCount ) . to . equal ( 1 ) ;
372
- expect ( chtDatasourceService . bind . args ) . to . deep . equal ( [ [ Person . v1 . get ] ] ) ;
373
381
expect ( getPerson . calledOnceWithExactly ( Qualifier . byUuid ( newContact . _id ) ) ) . to . be . true ;
382
+ expect ( getPlace . notCalled ) . to . be . true ;
374
383
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 1 ) ;
375
384
expect ( createUserForContactsService . setReplaced . args [ 0 ] ) . to . deep . equal ( [ originalUser , newContact ] ) ;
376
385
expect ( createUserForContactsService . isBeingReplaced . callCount ) . to . equal ( 2 ) ;
@@ -392,7 +401,8 @@ describe('Create User for Contacts Transition', () => {
392
401
}
393
402
394
403
expect ( userContactService . get . callCount ) . to . equal ( 1 ) ;
395
- expect ( chtDatasourceService . bind . notCalled ) . to . be . true ;
404
+ expect ( getPerson . notCalled ) . to . be . true ;
405
+ expect ( getPlace . notCalled ) . to . be . true ;
396
406
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 0 ) ;
397
407
expect ( createUserForContactsService . isBeingReplaced . callCount ) . to . equal ( 2 ) ;
398
408
} ) ;
@@ -412,7 +422,8 @@ describe('Create User for Contacts Transition', () => {
412
422
}
413
423
414
424
expect ( userContactService . get . callCount ) . to . equal ( 1 ) ;
415
- expect ( chtDatasourceService . bind . notCalled ) . to . be . true ;
425
+ expect ( getPerson . notCalled ) . to . be . true ;
426
+ expect ( getPlace . notCalled ) . to . be . true ;
416
427
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 0 ) ;
417
428
expect ( createUserForContactsService . isBeingReplaced . callCount ) . to . equal ( 1 ) ;
418
429
} ) ;
@@ -430,8 +441,8 @@ describe('Create User for Contacts Transition', () => {
430
441
}
431
442
432
443
expect ( userContactService . get . callCount ) . to . equal ( 1 ) ;
433
- expect ( chtDatasourceService . bind . args ) . to . deep . equal ( [ [ Person . v1 . get ] ] ) ;
434
444
expect ( getPerson . calledOnceWithExactly ( Qualifier . byUuid ( NEW_CONTACT . _id ) ) ) . to . be . true ;
445
+ expect ( getPlace . notCalled ) . to . be . true ;
435
446
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 0 ) ;
436
447
expect ( createUserForContactsService . isBeingReplaced . callCount ) . to . equal ( 2 ) ;
437
448
} ) ;
@@ -448,8 +459,8 @@ describe('Create User for Contacts Transition', () => {
448
459
}
449
460
450
461
expect ( userContactService . get . callCount ) . to . equal ( 1 ) ;
451
- expect ( chtDatasourceService . bind . args ) . to . deep . equal ( [ [ Person . v1 . get ] ] ) ;
452
462
expect ( getPerson . calledOnceWithExactly ( Qualifier . byUuid ( NEW_CONTACT . _id ) ) ) . to . be . true ;
463
+ expect ( getPlace . notCalled ) . to . be . true ;
453
464
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 0 ) ;
454
465
expect ( createUserForContactsService . isBeingReplaced . callCount ) . to . equal ( 2 ) ;
455
466
} ) ;
@@ -468,7 +479,8 @@ describe('Create User for Contacts Transition', () => {
468
479
}
469
480
470
481
expect ( userContactService . get . callCount ) . to . equal ( 1 ) ;
471
- expect ( chtDatasourceService . bind . notCalled ) . to . be . true ;
482
+ expect ( getPerson . notCalled ) . to . be . true ;
483
+ expect ( getPlace . notCalled ) . to . be . true ;
472
484
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 0 ) ;
473
485
expect ( createUserForContactsService . isBeingReplaced . callCount ) . to . equal ( 1 ) ;
474
486
} ) ;
@@ -477,7 +489,8 @@ describe('Create User for Contacts Transition', () => {
477
489
describe ( `when the reports submitted do not include a replace user report, but the user is replaced` , ( ) => {
478
490
afterEach ( ( ) => {
479
491
// Functions from the user replace flow should not be called
480
- expect ( chtDatasourceService . bind . notCalled ) . to . be . true ;
492
+ expect ( getPerson . notCalled ) . to . be . true ;
493
+ expect ( getPlace . notCalled ) . to . be . true ;
481
494
expect ( createUserForContactsService . setReplaced . callCount ) . to . equal ( 0 ) ;
482
495
} ) ;
483
496
0 commit comments