@@ -386,7 +386,7 @@ describe(CourseSyncService.name, () => {
386
386
} ;
387
387
388
388
it ( 'should synchronize with the new group' , async ( ) => {
389
- const { course, newGroup, studentId, teacherId, substituteTeacherId } = setup ( ) ;
389
+ const { course, newGroup, studentId, teacherId } = setup ( ) ;
390
390
391
391
await service . synchronizeCourseWithGroup ( newGroup ) ;
392
392
@@ -398,22 +398,93 @@ describe(CourseSyncService.name, () => {
398
398
untilDate : newGroup . validPeriod ?. until ,
399
399
studentIds : [ studentId ] ,
400
400
teacherIds : [ teacherId ] ,
401
+ substitutionTeacherIds : [ ] ,
401
402
classIds : [ ] ,
402
403
groupIds : [ ] ,
404
+ } ) ,
405
+ ] ) ;
406
+ } ) ;
407
+ } ) ;
408
+
409
+ describe ( 'when synchronizing with a new group with substitute teacher' , ( ) => {
410
+ const setup = ( ) => {
411
+ const studentId : string = new ObjectId ( ) . toHexString ( ) ;
412
+ const teacherId : string = new ObjectId ( ) . toHexString ( ) ;
413
+ const substituteTeacherId : string = new ObjectId ( ) . toHexString ( ) ;
414
+ const studentRoleId : string = new ObjectId ( ) . toHexString ( ) ;
415
+ const teacherRoleId : string = new ObjectId ( ) . toHexString ( ) ;
416
+ const substituteTeacherRoleId : string = new ObjectId ( ) . toHexString ( ) ;
417
+ const studentRole : RoleDto = roleDtoFactory . build ( { id : studentRoleId } ) ;
418
+ const teacherRole : RoleDto = roleDtoFactory . build ( { id : teacherRoleId } ) ;
419
+ const substituteTeacherRole : RoleDto = roleDtoFactory . build ( { id : substituteTeacherRoleId } ) ;
420
+ const newGroup : Group = groupFactory . build ( {
421
+ users : [
422
+ {
423
+ userId : studentId ,
424
+ roleId : studentRoleId ,
425
+ } ,
426
+ {
427
+ userId : teacherId ,
428
+ roleId : teacherRoleId ,
429
+ } ,
430
+ {
431
+ userId : substituteTeacherId ,
432
+ roleId : substituteTeacherRoleId ,
433
+ } ,
434
+ {
435
+ userId : teacherId ,
436
+ roleId : substituteTeacherRoleId ,
437
+ } ,
438
+ ] ,
439
+ } ) ;
440
+ const course : Course = courseFactory . build ( {
441
+ classIds : [ new ObjectId ( ) . toHexString ( ) ] ,
442
+ groupIds : [ new ObjectId ( ) . toHexString ( ) ] ,
443
+ substitutionTeacherIds : [ ] ,
444
+ } ) ;
445
+
446
+ courseRepo . findBySyncedGroup . mockResolvedValueOnce ( [ new Course ( course . getProps ( ) ) ] ) ;
447
+ roleService . findByName
448
+ . mockResolvedValueOnce ( studentRole )
449
+ . mockResolvedValueOnce ( teacherRole )
450
+ . mockResolvedValueOnce ( substituteTeacherRole ) ;
451
+
452
+ return {
453
+ course,
454
+ newGroup,
455
+ studentId,
456
+ teacherId,
457
+ substituteTeacherId,
458
+ } ;
459
+ } ;
460
+
461
+ it ( 'should synchronize the substitution teachers, without creating duplicates in teacherIds' , async ( ) => {
462
+ const { course, newGroup, studentId, teacherId, substituteTeacherId } = setup ( ) ;
463
+
464
+ await service . synchronizeCourseWithGroup ( newGroup ) ;
465
+
466
+ expect ( courseRepo . saveAll ) . toHaveBeenCalledWith < [ Course [ ] ] > ( [
467
+ new Course ( {
468
+ ...course . getProps ( ) ,
469
+ syncedWithGroup : newGroup . id ,
470
+ startDate : newGroup . validPeriod ?. from ,
471
+ untilDate : newGroup . validPeriod ?. until ,
472
+ studentIds : [ studentId ] ,
473
+ teacherIds : [ teacherId ] ,
403
474
substitutionTeacherIds : [ substituteTeacherId ] ,
475
+ classIds : [ ] ,
476
+ groupIds : [ ] ,
404
477
} ) ,
405
478
] ) ;
406
479
} ) ;
407
480
} ) ;
408
481
409
482
describe ( 'when the course name is the same as the old group name' , ( ) => {
410
483
const setup = ( ) => {
411
- const substituteTeacherId = new ObjectId ( ) . toHexString ( ) ;
412
484
const course : Course = courseFactory . build ( {
413
485
name : 'Course Name' ,
414
486
classIds : [ new ObjectId ( ) . toHexString ( ) ] ,
415
487
groupIds : [ new ObjectId ( ) . toHexString ( ) ] ,
416
- substitutionTeacherIds : [ substituteTeacherId ] ,
417
488
} ) ;
418
489
const studentRole : RoleDto = roleDtoFactory . build ( ) ;
419
490
const teacherRole : RoleDto = roleDtoFactory . build ( ) ;
@@ -431,12 +502,11 @@ describe(CourseSyncService.name, () => {
431
502
course,
432
503
newGroup,
433
504
oldGroup,
434
- substituteTeacherId,
435
505
} ;
436
506
} ;
437
507
438
508
it ( 'should synchronize the group name' , async ( ) => {
439
- const { course, newGroup, oldGroup, substituteTeacherId } = setup ( ) ;
509
+ const { course, newGroup, oldGroup } = setup ( ) ;
440
510
441
511
await service . synchronizeCourseWithGroup ( newGroup , oldGroup ) ;
442
512
expect ( courseRepo . saveAll ) . toHaveBeenCalledWith < [ Course [ ] ] > ( [
@@ -450,20 +520,18 @@ describe(CourseSyncService.name, () => {
450
520
teacherIds : [ ] ,
451
521
classIds : [ ] ,
452
522
groupIds : [ ] ,
453
- substitutionTeacherIds : [ substituteTeacherId ] ,
523
+ substitutionTeacherIds : [ ] ,
454
524
} ) ,
455
525
] ) ;
456
526
} ) ;
457
527
} ) ;
458
528
459
529
describe ( 'when the course name is different from the old group name' , ( ) => {
460
530
const setup = ( ) => {
461
- const substituteTeacherId = new ObjectId ( ) . toHexString ( ) ;
462
531
const course : Course = courseFactory . build ( {
463
532
name : 'Custom Course Name' ,
464
533
classIds : [ new ObjectId ( ) . toHexString ( ) ] ,
465
534
groupIds : [ new ObjectId ( ) . toHexString ( ) ] ,
466
- substitutionTeacherIds : [ substituteTeacherId ] ,
467
535
} ) ;
468
536
const studentRole : RoleDto = roleDtoFactory . build ( ) ;
469
537
const teacherRole : RoleDto = roleDtoFactory . build ( ) ;
@@ -481,12 +549,11 @@ describe(CourseSyncService.name, () => {
481
549
course,
482
550
newGroup,
483
551
oldGroup,
484
- substituteTeacherId,
485
552
} ;
486
553
} ;
487
554
488
555
it ( 'should keep the old course name' , async ( ) => {
489
- const { course, newGroup, oldGroup, substituteTeacherId } = setup ( ) ;
556
+ const { course, newGroup, oldGroup } = setup ( ) ;
490
557
491
558
await service . synchronizeCourseWithGroup ( newGroup , oldGroup ) ;
492
559
expect ( courseRepo . saveAll ) . toHaveBeenCalledWith < [ Course [ ] ] > ( [
@@ -500,15 +567,14 @@ describe(CourseSyncService.name, () => {
500
567
teacherIds : [ ] ,
501
568
classIds : [ ] ,
502
569
groupIds : [ ] ,
503
- substitutionTeacherIds : [ substituteTeacherId ] ,
570
+ substitutionTeacherIds : [ ] ,
504
571
} ) ,
505
572
] ) ;
506
573
} ) ;
507
574
} ) ;
508
575
509
576
describe ( 'when the teachers are not synced from group' , ( ) => {
510
577
const setup = ( ) => {
511
- const substituteTeacherId = new ObjectId ( ) . toHexString ( ) ;
512
578
const studentUserId = new ObjectId ( ) . toHexString ( ) ;
513
579
const teacherUserId = new ObjectId ( ) . toHexString ( ) ;
514
580
const studentRoleId : string = new ObjectId ( ) . toHexString ( ) ;
@@ -526,7 +592,6 @@ describe(CourseSyncService.name, () => {
526
592
527
593
const course : Course = courseFactory . build ( {
528
594
syncedWithGroup : newGroup . id ,
529
- substitutionTeacherIds : [ substituteTeacherId ] ,
530
595
teacherIds : [ teacherUserId ] ,
531
596
excludeFromSync : [ ] ,
532
597
} ) ;
@@ -538,13 +603,12 @@ describe(CourseSyncService.name, () => {
538
603
course,
539
604
newGroup,
540
605
teacherUserId,
541
- substituteTeacherId,
542
606
studentUserId,
543
607
} ;
544
608
} ;
545
609
546
610
it ( 'should not sync group students' , async ( ) => {
547
- const { course, newGroup, teacherUserId, substituteTeacherId } = setup ( ) ;
611
+ const { course, newGroup, teacherUserId } = setup ( ) ;
548
612
549
613
await service . synchronizeCourseWithGroup ( newGroup ) ;
550
614
expect ( courseRepo . saveAll ) . toHaveBeenCalledWith < [ Course [ ] ] > ( [
@@ -559,7 +623,7 @@ describe(CourseSyncService.name, () => {
559
623
classIds : [ ] ,
560
624
groupIds : [ ] ,
561
625
excludeFromSync : [ ] ,
562
- substitutionTeacherIds : [ substituteTeacherId ] ,
626
+ substitutionTeacherIds : [ ] ,
563
627
} ) ,
564
628
] ) ;
565
629
} ) ;
@@ -607,7 +671,7 @@ describe(CourseSyncService.name, () => {
607
671
} ;
608
672
609
673
it ( 'should not sync group teachers' , async ( ) => {
610
- const { course, newGroup, substituteTeacherId , teacherUserId, studentUserId } = setup ( ) ;
674
+ const { course, newGroup, teacherUserId, studentUserId } = setup ( ) ;
611
675
612
676
await service . synchronizeCourseWithGroup ( newGroup ) ;
613
677
expect ( courseRepo . saveAll ) . toHaveBeenCalledWith < [ Course [ ] ] > ( [
@@ -622,7 +686,7 @@ describe(CourseSyncService.name, () => {
622
686
classIds : [ ] ,
623
687
groupIds : [ ] ,
624
688
excludeFromSync : [ SyncAttribute . TEACHERS ] ,
625
- substitutionTeacherIds : [ substituteTeacherId ] ,
689
+ substitutionTeacherIds : [ ] ,
626
690
} ) ,
627
691
] ) ;
628
692
} ) ;
0 commit comments