Skip to content

Commit

Permalink
feat(api): add SHOW_SKILLS, SHOW_NPS and IS_MANAGING_STUDENTS as feat…
Browse files Browse the repository at this point in the history
…ures in OrganizationForAdmin model
  • Loading branch information
frinyvonnick committed Jan 29, 2025
1 parent a4a5597 commit a5b1d81
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,11 @@ class OrganizationForAdmin {
this.logoUrl = logoUrl;
this.externalId = externalId;
this.provinceCode = provinceCode;
this.isManagingStudents = isManagingStudents;
this.credit = credit;
this.email = email;
this.documentationUrl = documentationUrl;
this.createdBy = createdBy;
this.createdAt = createdAt;
this.showNPS = showNPS;
this.formNPSUrl = formNPSUrl;
this.showSkills = showSkills;
this.archivedAt = archivedAt;
this.archivistFirstName = archivistFirstName;
this.archivistLastName = archivistLastName;
Expand All @@ -74,7 +70,30 @@ class OrganizationForAdmin {
this.identityProviderForCampaigns = identityProviderForCampaigns;
this.tags = tags;
this.tagIds = tagIds;

// @deprecated you should use value stored in features property
this.isManagingStudents = isManagingStudents;
// @deprecated you should use value stored in features property
this.showNPS = showNPS;
// @deprecated you should use value stored in features property
this.formNPSUrl = formNPSUrl;
// @deprecated you should use value stored in features property
this.showSkills = showSkills;

this.features = features;

this.features[ORGANIZATION_FEATURE.IS_MANAGING_STUDENTS.key] = {
active: this.isManagingStudents,
params: null,
};
this.features[ORGANIZATION_FEATURE.SHOW_SKILLS.key] = {
active: this.showSkills,
params: null,
};
this.features[ORGANIZATION_FEATURE.SHOW_NPS.key] = {
active: this.showNPS,
params: this.showNPS ? { formNPSUrl: this.formNPSUrl } : null,
};
if (this.type === 'SCO' && this.isManagingStudents) {
this.features[ORGANIZATION_FEATURE.COMPUTE_ORGANIZATION_LEARNER_CERTIFICABILITY.key] = {
active: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,14 @@ async function _disableFeatures(knexConn, features, organizationId) {
.where('organization-features.organizationId', organizationId)
.whereIn(
'features.key',
_.keys(features).filter((key) => features[key].active === false),
_.keys(
// These features does not exist in database for now.
_.omit(features, [
ORGANIZATION_FEATURE.SHOW_SKILLS.key,
ORGANIZATION_FEATURE.SHOW_NPS.key,
ORGANIZATION_FEATURE.IS_MANAGING_STUDENTS.key,
]),
).filter((key) => features[key].active === false),
)
.delete();
}
Expand All @@ -247,7 +254,14 @@ async function _enableFeatures(knexConn, featuresToEnable, organizationId) {

await knexConn(ORGANIZATION_FEATURES_TABLE_NAME)
.insert(
_.keys(featuresToEnable)
_.keys(
// These features does not exist in database for now.
_.omit(featuresToEnable, [
ORGANIZATION_FEATURE.SHOW_SKILLS.key,
ORGANIZATION_FEATURE.SHOW_NPS.key,
ORGANIZATION_FEATURE.IS_MANAGING_STUDENTS.key,
]),
)
.filter((key) => featuresToEnable[key].active)
.map((key) => ({
organizationId,
Expand Down
12 changes: 12 additions & 0 deletions api/src/shared/domain/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ const ORGANIZATION_FEATURE = {
key: 'COVER_RATE',
description: "Permet l'affichage de la page statistiques sur Pix Orga",
},
SHOW_SKILLS: {
key: 'SHOW_SKILLS',
description: "Permet l'ajout des acquis dans l'export de résultats",
},
IS_MANAGING_STUDENTS: {
key: 'IS_MANAGING_STUDENTS',
description: "Permet l'activation de l'import pour le SCO et le SUP",
},
SHOW_NPS: {
key: 'SHOW_NPS',
description: "Permet l'affichage d'un lien vers le formulaire du Net Promoter Score",
},
};

const CAMPAIGN_FEATURES = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O
features: {
[ORGANIZATION_FEATURE.MULTIPLE_SENDING_ASSESSMENT.key]: { active: false, params: null },
[ORGANIZATION_FEATURE.COMPUTE_ORGANIZATION_LEARNER_CERTIFICABILITY.key]: { active: true, params: null },
[ORGANIZATION_FEATURE.SHOW_SKILLS.key]: { active: false, params: null },
[ORGANIZATION_FEATURE.IS_MANAGING_STUDENTS.key]: { active: true, params: null },
[ORGANIZATION_FEATURE.SHOW_NPS.key]: { active: false, params: null },
},
},
id: organization.id.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ describe('Unit | Organizational Entities | Domain | Model | OrganizationForAdmin
}).to.throw();
});

context('legacy features', function () {
it('put legacy features to new feature format', function () {
// given
const expectedOrganization = domainBuilder.buildOrganizationForAdmin({
showSkills: false,
isManagingStudents: true,
showNPS: true,
formNPSUrl: 'https://some-url.com',
});

// when
const organization = new OrganizationForAdmin(expectedOrganization);

// then
expect(organization.features).to.deep.includes({
[ORGANIZATION_FEATURE.SHOW_SKILLS.key]: { active: false, params: null },
[ORGANIZATION_FEATURE.IS_MANAGING_STUDENTS.key]: { active: true, params: null },
[ORGANIZATION_FEATURE.SHOW_NPS.key]: { active: true, params: { formNPSUrl: 'https://some-url.com' } },
});
});
});

context('for sco organizations', function () {
context('when organization isManagingStudent is true', function () {
it('builds an OrganizationForAdmin with compute organization learner certificability enabled', function () {
Expand Down Expand Up @@ -42,7 +64,8 @@ describe('Unit | Organizational Entities | Domain | Model | OrganizationForAdmin
const organization = new OrganizationForAdmin(expectedOrganization);

// then
expect(organization.features).to.deep.equal({});
expect(organization.features[ORGANIZATION_FEATURE.COMPUTE_ORGANIZATION_LEARNER_CERTIFICABILITY.key]).to.be
.undefined;
});
});
});
Expand Down

0 comments on commit a5b1d81

Please sign in to comment.