@@ -5,14 +5,23 @@ import { organizationForAdminRepository } from '../../../../../src/organizationa
5
5
import { ORGANIZATION_FEATURE } from '../../../../../src/shared/domain/constants.js' ;
6
6
import { MissingAttributesError , NotFoundError } from '../../../../../src/shared/domain/errors.js' ;
7
7
import { OrganizationInvitation } from '../../../../../src/team/domain/models/OrganizationInvitation.js' ;
8
- import { catchErr , databaseBuilder , domainBuilder , expect , knex , sinon } from '../../../../test-helper.js' ;
8
+ import {
9
+ catchErr ,
10
+ databaseBuilder ,
11
+ domainBuilder ,
12
+ expect ,
13
+ insertMultipleSendingFeatureForNewOrganization ,
14
+ knex ,
15
+ sinon ,
16
+ } from '../../../../test-helper.js' ;
9
17
10
18
describe ( 'Integration | Organizational Entities | Infrastructure | Repository | organization-for-admin' , function ( ) {
11
- let clock ;
19
+ let clock , byDefaultFeatureId ;
12
20
const now = new Date ( '2022-02-02' ) ;
13
21
14
- beforeEach ( function ( ) {
22
+ beforeEach ( async function ( ) {
15
23
clock = sinon . useFakeTimers ( { now, toFake : [ 'Date' ] } ) ;
24
+ await databaseBuilder . commit ( ) ;
16
25
} ) ;
17
26
18
27
afterEach ( function ( ) {
@@ -424,6 +433,7 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
424
433
creatorLastName : 'Encieux' ,
425
434
identityProviderForCampaigns : 'genericOidcProviderCode' ,
426
435
features : {
436
+ [ ORGANIZATION_FEATURE . MULTIPLE_SENDING_ASSESSMENT . key ] : { active : true , params : null } ,
427
437
[ ORGANIZATION_FEATURE . LEARNER_IMPORT . key ] : { active : false , params : null } ,
428
438
} ,
429
439
parentOrganizationId : null ,
@@ -485,7 +495,6 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
485
495
archivedBy : archivist . id ,
486
496
archivedAt,
487
497
} ) ;
488
- databaseBuilder . factory . buildFeature ( ORGANIZATION_FEATURE . MULTIPLE_SENDING_ASSESSMENT ) ;
489
498
490
499
await databaseBuilder . commit ( ) ;
491
500
@@ -522,9 +531,7 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
522
531
creatorFirstName : superAdminUser . firstName ,
523
532
creatorLastName : superAdminUser . lastName ,
524
533
identityProviderForCampaigns : null ,
525
- features : {
526
- [ ORGANIZATION_FEATURE . MULTIPLE_SENDING_ASSESSMENT . key ] : { active : false , params : null } ,
527
- } ,
534
+ features : { } ,
528
535
parentOrganizationId : null ,
529
536
parentOrganizationName : null ,
530
537
} ) ;
@@ -537,6 +544,8 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
537
544
it ( 'saves the given organization' , async function ( ) {
538
545
// given
539
546
const superAdminUserId = databaseBuilder . factory . buildUser . withRole ( ) . id ;
547
+ await insertMultipleSendingFeatureForNewOrganization ( ) ;
548
+
540
549
await databaseBuilder . commit ( ) ;
541
550
542
551
const organization = new OrganizationForAdmin ( {
@@ -568,6 +577,7 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
568
577
const organizationLearnerImportOndeFormat = databaseBuilder . factory . buildOrganizationLearnerImportFormat ( {
569
578
name : 'ONDE' ,
570
579
} ) ;
580
+ byDefaultFeatureId = await insertMultipleSendingFeatureForNewOrganization ( ) ;
571
581
572
582
await databaseBuilder . commit ( ) ;
573
583
@@ -579,9 +589,11 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
579
589
580
590
const savedOrganization = await organizationForAdminRepository . save ( organization ) ;
581
591
582
- const savedOrganizationFeatures = await knex ( 'organization-features' ) . where ( {
583
- organizationId : savedOrganization . id ,
584
- } ) ;
592
+ const savedOrganizationFeatures = await knex ( 'organization-features' )
593
+ . where ( {
594
+ organizationId : savedOrganization . id ,
595
+ } )
596
+ . whereNot ( { featureId : byDefaultFeatureId } ) ;
585
597
586
598
expect ( savedOrganizationFeatures ) . to . have . lengthOf ( 3 ) ;
587
599
const savedOrganizationFeatureIds = savedOrganizationFeatures . map (
@@ -603,6 +615,10 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
603
615
} ) ;
604
616
605
617
describe ( '#update' , function ( ) {
618
+ beforeEach ( async function ( ) {
619
+ byDefaultFeatureId = await insertMultipleSendingFeatureForNewOrganization ( ) ;
620
+ } ) ;
621
+
606
622
it ( 'updates organization detail' , async function ( ) {
607
623
// given
608
624
const parentOrganizationId = databaseBuilder . factory . buildOrganization ( { name : 'Parent Organization' } ) . id ;
@@ -627,8 +643,7 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
627
643
name : 'super orga' ,
628
644
createdBy : userId ,
629
645
} ) ;
630
-
631
- const featureId = databaseBuilder . factory . buildFeature ( ORGANIZATION_FEATURE . MULTIPLE_SENDING_ASSESSMENT ) . id ;
646
+ const featureId = databaseBuilder . factory . buildFeature ( ORGANIZATION_FEATURE . MISSIONS_MANAGEMENT ) . id ;
632
647
await databaseBuilder . commit ( ) ;
633
648
634
649
// when
@@ -637,13 +652,15 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
637
652
documentationUrl : 'https://pix.fr/' ,
638
653
features : {
639
654
[ ORGANIZATION_FEATURE . LEARNER_IMPORT . key ] : { active : false } ,
640
- [ ORGANIZATION_FEATURE . MULTIPLE_SENDING_ASSESSMENT . key ] : { active : true } ,
655
+ [ ORGANIZATION_FEATURE . MISSIONS_MANAGEMENT . key ] : { active : true } ,
641
656
} ,
642
657
} ) ;
643
658
await organizationForAdminRepository . update ( organizationToUpdate ) ;
644
659
645
660
// then
646
- const enabledFeatures = await knex ( 'organization-features' ) . where ( { organizationId : organization . id } ) ;
661
+ const enabledFeatures = await knex ( 'organization-features' )
662
+ . where ( { organizationId : organization . id , featureId } )
663
+ . whereNot ( { featureId : byDefaultFeatureId } ) ;
647
664
expect ( enabledFeatures ) . to . have . lengthOf ( 1 ) ;
648
665
expect ( enabledFeatures [ 0 ] . featureId ) . to . equal ( featureId ) ;
649
666
} ) ;
@@ -656,7 +673,8 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
656
673
createdBy : userId ,
657
674
} ) ;
658
675
659
- const featureId = databaseBuilder . factory . buildFeature ( ORGANIZATION_FEATURE . MULTIPLE_SENDING_ASSESSMENT ) . id ;
676
+ const featureId = databaseBuilder . factory . buildFeature ( ORGANIZATION_FEATURE . MISSIONS_MANAGEMENT ) . id ;
677
+
660
678
databaseBuilder . factory . buildOrganizationFeature ( { organizationId : organization . id , featureId } ) ;
661
679
await databaseBuilder . commit ( ) ;
662
680
@@ -665,14 +683,16 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
665
683
id : organization . id ,
666
684
documentationUrl : 'https://pix.fr/' ,
667
685
features : {
668
- [ ORGANIZATION_FEATURE . MULTIPLE_SENDING_ASSESSMENT . key ] : { active : true } ,
686
+ [ ORGANIZATION_FEATURE . MISSIONS_MANAGEMENT . key ] : { active : true } ,
669
687
} ,
670
688
} ) ;
671
689
672
690
await organizationForAdminRepository . update ( organizationToUpdate ) ;
673
691
674
692
// then
675
- const enabledFeatures = await knex ( 'organization-features' ) . where ( { organizationId : organization . id } ) ;
693
+ const enabledFeatures = await knex ( 'organization-features' )
694
+ . where ( { organizationId : organization . id } )
695
+ . whereNot ( { featureId : byDefaultFeatureId } ) ;
676
696
expect ( enabledFeatures ) . to . have . lengthOf ( 1 ) ;
677
697
expect ( enabledFeatures [ 0 ] . featureId ) . to . equal ( featureId ) ;
678
698
} ) ;
@@ -690,7 +710,7 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
690
710
createdBy : userId ,
691
711
} ) ;
692
712
693
- const featureId = databaseBuilder . factory . buildFeature ( ORGANIZATION_FEATURE . MULTIPLE_SENDING_ASSESSMENT ) . id ;
713
+ const featureId = databaseBuilder . factory . buildFeature ( ORGANIZATION_FEATURE . MISSIONS_MANAGEMENT ) . id ;
694
714
databaseBuilder . factory . buildOrganizationFeature ( { organizationId : organization . id , featureId } ) ;
695
715
databaseBuilder . factory . buildOrganizationFeature ( { organizationId : otherOrganization . id , featureId } ) ;
696
716
@@ -701,17 +721,42 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
701
721
id : organization . id ,
702
722
documentationUrl : 'https://pix.fr/' ,
703
723
features : {
704
- [ ORGANIZATION_FEATURE . MULTIPLE_SENDING_ASSESSMENT . key ] : { active : false } ,
724
+ [ ORGANIZATION_FEATURE . MISSIONS_MANAGEMENT . key ] : { active : false } ,
705
725
} ,
706
726
} ) ;
707
727
await organizationForAdminRepository . update ( organizationToUpdate ) ;
708
728
709
729
//then
710
- const enabledFeatures = await knex ( 'organization-features' ) ;
730
+ const enabledFeatures = await knex ( 'organization-features' ) . whereNot ( { featureId : byDefaultFeatureId } ) ;
711
731
expect ( enabledFeatures ) . to . have . lengthOf ( 1 ) ;
712
732
expect ( enabledFeatures [ 0 ] . organizationId ) . to . equal ( otherOrganization . id ) ;
713
733
} ) ;
714
734
735
+ it ( 'should disable the "by default" feature for a given organization' , async function ( ) {
736
+ // given
737
+ const userId = databaseBuilder . factory . buildUser ( { firstName : 'Anne' , lastName : 'Héantie' } ) . id ;
738
+ const organization = databaseBuilder . factory . buildOrganization ( {
739
+ name : 'super orga' ,
740
+ createdBy : userId ,
741
+ } ) ;
742
+
743
+ await databaseBuilder . commit ( ) ;
744
+
745
+ // when
746
+ const organizationToUpdate = new OrganizationForAdmin ( {
747
+ id : organization . id ,
748
+ documentationUrl : 'https://pix.fr/' ,
749
+ features : {
750
+ [ ORGANIZATION_FEATURE . MULTIPLE_SENDING_ASSESSMENT . key ] : { active : false } ,
751
+ } ,
752
+ } ) ;
753
+ await organizationForAdminRepository . update ( organizationToUpdate ) ;
754
+
755
+ //then
756
+ const enabledFeatures = await knex ( 'organization-features' ) ;
757
+ expect ( enabledFeatures ) . to . have . lengthOf ( 0 ) ;
758
+ } ) ;
759
+
715
760
it ( 'should create data protection officer' , async function ( ) {
716
761
// given
717
762
const userId = databaseBuilder . factory . buildUser ( { firstName : 'Spider' , lastName : 'Man' } ) . id ;
@@ -750,6 +795,7 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
750
795
name : 'super orga' ,
751
796
createdBy : userId ,
752
797
} ) ;
798
+
753
799
databaseBuilder . factory . buildDataProtectionOfficer . withOrganizationId ( {
754
800
organizationId : organization . id ,
755
801
firstName : 'Tony' ,
@@ -785,6 +831,7 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
785
831
const organizationId = databaseBuilder . factory . buildOrganization ( ) . id ;
786
832
const tagId = databaseBuilder . factory . buildTag ( { name : 'myTag' } ) . id ;
787
833
const otherTagId = databaseBuilder . factory . buildTag ( { name : 'myOtherTag' } ) . id ;
834
+
788
835
await databaseBuilder . commit ( ) ;
789
836
const tagsToAdd = [
790
837
{ tagId, organizationId } ,
0 commit comments