Skip to content

Commit

Permalink
feat(api): modified tests to take into account the fact that multiple…
Browse files Browse the repository at this point in the history
…sendingassessment is now a by default feature
  • Loading branch information
alicegoarnisson committed Mar 7, 2025
1 parent dee8906 commit a8a643f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
databaseBuilder,
expect,
generateAuthenticatedUserRequestHeaders,
insertMultipleSendingFeatureForNewOrganization,
insertUserWithRoleSuperAdmin,
knex,
sinon,
Expand All @@ -24,6 +25,7 @@ describe('Acceptance | Application | organization-controller', function () {
beforeEach(async function () {
server = await createServer();
await insertUserWithRoleSuperAdmin();
await insertMultipleSendingFeatureForNewOrganization();
});

describe('POST /api/admin/organizations', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { OrganizationForAdmin } from '../../../../src/organizational-entities/do
import * as dataProtectionOfficerRepository from '../../../../src/organizational-entities/infrastructure/repositories/data-protection-officer.repository.js';
import { organizationForAdminRepository } from '../../../../src/organizational-entities/infrastructure/repositories/organization-for-admin.repository.js';
import * as schoolRepository from '../../../../src/school/infrastructure/repositories/school-repository.js';
import { databaseBuilder, expect } from '../../../test-helper.js';
import { databaseBuilder, expect, insertMultipleSendingFeatureForNewOrganization } from '../../../test-helper.js';

describe('Integration | UseCases | create-organization', function () {
it('returns newly created organization', async function () {
// given
const superAdminUserId = databaseBuilder.factory.buildUser().id;
await insertMultipleSendingFeatureForNewOrganization();
await databaseBuilder.commit();

const organization = new OrganizationForAdmin({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ import { Membership } from '../../../../src/shared/domain/models/Membership.js';
import * as organizationRepository from '../../../../src/shared/infrastructure/repositories/organization-repository.js';
import { organizationInvitationService } from '../../../../src/team/domain/services/organization-invitation.service.js';
import { organizationInvitationRepository } from '../../../../src/team/infrastructure/repositories/organization-invitation.repository.js';
import { catchErr, databaseBuilder, expect, knex } from '../../../test-helper.js';
import {
catchErr,
databaseBuilder,
expect,
insertMultipleSendingFeatureForNewOrganization,
knex,
} from '../../../test-helper.js';

const { omit } = lodash;

describe('Integration | UseCases | create-organizations-with-tags-and-target-profiles', function () {
let missionFeature, oralizationFeature, importStudentsFeature, ondeImportFormat, userId;
let missionFeature, oralizationFeature, importStudentsFeature, ondeImportFormat, userId, byDefaultFeatureId;

beforeEach(async function () {
databaseBuilder.factory.buildFeature(ORGANIZATION_FEATURE.COMPUTE_ORGANIZATION_LEARNER_CERTIFICABILITY);
Expand All @@ -34,6 +40,7 @@ describe('Integration | UseCases | create-organizations-with-tags-and-target-pro
ondeImportFormat = databaseBuilder.factory.buildOrganizationLearnerImportFormat({
name: ORGANIZATION_FEATURE.LEARNER_IMPORT.FORMAT.ONDE,
});
byDefaultFeatureId = await insertMultipleSendingFeatureForNewOrganization();

userId = databaseBuilder.factory.buildUser().id;
await databaseBuilder.commit();
Expand Down Expand Up @@ -739,7 +746,7 @@ describe('Integration | UseCases | create-organizations-with-tags-and-target-pro
});

// then
const savedOrganizationFeatures = await knex('organization-features');
const savedOrganizationFeatures = await knex('organization-features').whereNot({ featureId: byDefaultFeatureId });
expect(savedOrganizationFeatures).to.have.lengthOf(3);
const organizationId = createdOrganizations[0].id;
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
databaseBuilder,
expect,
generateAuthenticatedUserRequestHeaders,
insertMultipleSendingFeatureForNewOrganization,
insertUserWithRoleSuperAdmin,
knex,
} from '../../../../test-helper.js';
Expand All @@ -19,6 +20,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O

beforeEach(async function () {
admin = await insertUserWithRoleSuperAdmin();
await insertMultipleSendingFeatureForNewOrganization();
await databaseBuilder.commit();

server = await createServer();
Expand Down Expand Up @@ -65,7 +67,6 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O
});
const tag = databaseBuilder.factory.buildTag({ id: 7, name: 'AEFE' });
databaseBuilder.factory.buildOrganizationTag({ tagId: tag.id, organizationId: organization.id });
databaseBuilder.factory.buildFeature(ORGANIZATION_FEATURE.MULTIPLE_SENDING_ASSESSMENT);
await databaseBuilder.commit();

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@ import { organizationForAdminRepository } from '../../../../../src/organizationa
import { ORGANIZATION_FEATURE } from '../../../../../src/shared/domain/constants.js';
import { MissingAttributesError, NotFoundError } from '../../../../../src/shared/domain/errors.js';
import { OrganizationInvitation } from '../../../../../src/team/domain/models/OrganizationInvitation.js';
import { catchErr, databaseBuilder, domainBuilder, expect, knex, sinon } from '../../../../test-helper.js';
import {
catchErr,
databaseBuilder,
domainBuilder,
expect,
insertMultipleSendingFeatureForNewOrganization,
knex,
sinon,
} from '../../../../test-helper.js';

describe('Integration | Organizational Entities | Infrastructure | Repository | organization-for-admin', function () {
let clock;
let clock, byDefaultFeatureId;
const now = new Date('2022-02-02');

beforeEach(function () {
beforeEach(async function () {
clock = sinon.useFakeTimers({ now, toFake: ['Date'] });
await databaseBuilder.commit();
});

afterEach(function () {
Expand Down Expand Up @@ -424,6 +433,7 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
creatorLastName: 'Encieux',
identityProviderForCampaigns: 'genericOidcProviderCode',
features: {
[ORGANIZATION_FEATURE.MULTIPLE_SENDING_ASSESSMENT.key]: { active: true, params: null },
[ORGANIZATION_FEATURE.LEARNER_IMPORT.key]: { active: false, params: null },
},
parentOrganizationId: null,
Expand Down Expand Up @@ -485,7 +495,6 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
archivedBy: archivist.id,
archivedAt,
});
databaseBuilder.factory.buildFeature(ORGANIZATION_FEATURE.MULTIPLE_SENDING_ASSESSMENT);

await databaseBuilder.commit();

Expand Down Expand Up @@ -522,9 +531,7 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
creatorFirstName: superAdminUser.firstName,
creatorLastName: superAdminUser.lastName,
identityProviderForCampaigns: null,
features: {
[ORGANIZATION_FEATURE.MULTIPLE_SENDING_ASSESSMENT.key]: { active: false, params: null },
},
features: {},
parentOrganizationId: null,
parentOrganizationName: null,
});
Expand All @@ -537,6 +544,8 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
it('saves the given organization', async function () {
// given
const superAdminUserId = databaseBuilder.factory.buildUser.withRole().id;
await insertMultipleSendingFeatureForNewOrganization();

await databaseBuilder.commit();

const organization = new OrganizationForAdmin({
Expand Down Expand Up @@ -568,6 +577,7 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
const organizationLearnerImportOndeFormat = databaseBuilder.factory.buildOrganizationLearnerImportFormat({
name: 'ONDE',
});
byDefaultFeatureId = await insertMultipleSendingFeatureForNewOrganization();

await databaseBuilder.commit();

Expand All @@ -579,9 +589,11 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |

const savedOrganization = await organizationForAdminRepository.save(organization);

const savedOrganizationFeatures = await knex('organization-features').where({
organizationId: savedOrganization.id,
});
const savedOrganizationFeatures = await knex('organization-features')
.where({
organizationId: savedOrganization.id,
})
.whereNot({ featureId: byDefaultFeatureId });

expect(savedOrganizationFeatures).to.have.lengthOf(3);
const savedOrganizationFeatureIds = savedOrganizationFeatures.map(
Expand All @@ -603,6 +615,10 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
});

describe('#update', function () {
beforeEach(async function () {
byDefaultFeatureId = await insertMultipleSendingFeatureForNewOrganization();
});

it('updates organization detail', async function () {
// given
const parentOrganizationId = databaseBuilder.factory.buildOrganization({ name: 'Parent Organization' }).id;
Expand All @@ -627,8 +643,7 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
name: 'super orga',
createdBy: userId,
});

const featureId = databaseBuilder.factory.buildFeature(ORGANIZATION_FEATURE.MULTIPLE_SENDING_ASSESSMENT).id;
const featureId = databaseBuilder.factory.buildFeature(ORGANIZATION_FEATURE.MISSIONS_MANAGEMENT).id;
await databaseBuilder.commit();

// when
Expand All @@ -637,13 +652,15 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
documentationUrl: 'https://pix.fr/',
features: {
[ORGANIZATION_FEATURE.LEARNER_IMPORT.key]: { active: false },
[ORGANIZATION_FEATURE.MULTIPLE_SENDING_ASSESSMENT.key]: { active: true },
[ORGANIZATION_FEATURE.MISSIONS_MANAGEMENT.key]: { active: true },
},
});
await organizationForAdminRepository.update(organizationToUpdate);

// then
const enabledFeatures = await knex('organization-features').where({ organizationId: organization.id });
const enabledFeatures = await knex('organization-features')
.where({ organizationId: organization.id, featureId })
.whereNot({ featureId: byDefaultFeatureId });
expect(enabledFeatures).to.have.lengthOf(1);
expect(enabledFeatures[0].featureId).to.equal(featureId);
});
Expand All @@ -656,7 +673,8 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
createdBy: userId,
});

const featureId = databaseBuilder.factory.buildFeature(ORGANIZATION_FEATURE.MULTIPLE_SENDING_ASSESSMENT).id;
const featureId = databaseBuilder.factory.buildFeature(ORGANIZATION_FEATURE.MISSIONS_MANAGEMENT).id;

databaseBuilder.factory.buildOrganizationFeature({ organizationId: organization.id, featureId });
await databaseBuilder.commit();

Expand All @@ -665,14 +683,16 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
id: organization.id,
documentationUrl: 'https://pix.fr/',
features: {
[ORGANIZATION_FEATURE.MULTIPLE_SENDING_ASSESSMENT.key]: { active: true },
[ORGANIZATION_FEATURE.MISSIONS_MANAGEMENT.key]: { active: true },
},
});

await organizationForAdminRepository.update(organizationToUpdate);

// then
const enabledFeatures = await knex('organization-features').where({ organizationId: organization.id });
const enabledFeatures = await knex('organization-features')
.where({ organizationId: organization.id })
.whereNot({ featureId: byDefaultFeatureId });
expect(enabledFeatures).to.have.lengthOf(1);
expect(enabledFeatures[0].featureId).to.equal(featureId);
});
Expand All @@ -690,7 +710,7 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
createdBy: userId,
});

const featureId = databaseBuilder.factory.buildFeature(ORGANIZATION_FEATURE.MULTIPLE_SENDING_ASSESSMENT).id;
const featureId = databaseBuilder.factory.buildFeature(ORGANIZATION_FEATURE.MISSIONS_MANAGEMENT).id;
databaseBuilder.factory.buildOrganizationFeature({ organizationId: organization.id, featureId });
databaseBuilder.factory.buildOrganizationFeature({ organizationId: otherOrganization.id, featureId });

Expand All @@ -701,13 +721,13 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
id: organization.id,
documentationUrl: 'https://pix.fr/',
features: {
[ORGANIZATION_FEATURE.MULTIPLE_SENDING_ASSESSMENT.key]: { active: false },
[ORGANIZATION_FEATURE.MISSIONS_MANAGEMENT.key]: { active: false },
},
});
await organizationForAdminRepository.update(organizationToUpdate);

//then
const enabledFeatures = await knex('organization-features');
const enabledFeatures = await knex('organization-features').whereNot({ featureId: byDefaultFeatureId });
expect(enabledFeatures).to.have.lengthOf(1);
expect(enabledFeatures[0].organizationId).to.equal(otherOrganization.id);
});
Expand Down Expand Up @@ -750,6 +770,7 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
name: 'super orga',
createdBy: userId,
});

databaseBuilder.factory.buildDataProtectionOfficer.withOrganizationId({
organizationId: organization.id,
firstName: 'Tony',
Expand Down Expand Up @@ -785,6 +806,7 @@ describe('Integration | Organizational Entities | Infrastructure | Repository |
const organizationId = databaseBuilder.factory.buildOrganization().id;
const tagId = databaseBuilder.factory.buildTag({ name: 'myTag' }).id;
const otherTagId = databaseBuilder.factory.buildTag({ name: 'myOtherTag' }).id;

await databaseBuilder.commit();
const tagsToAdd = [
{ tagId, organizationId },
Expand Down

0 comments on commit a8a643f

Please sign in to comment.