Skip to content

Commit

Permalink
[TECH] Rendre les seeds de learners déterministes (PIX-15156)
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Nov 7, 2024
2 parents 148c06d + 1729d0f commit 75fe625
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
9 changes: 8 additions & 1 deletion api/db/seeds/data/common/tooling/campaign-tooling.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ function _buildCampaign({
return { realCampaignId, realOrganizationId, realCreatedAt };
}

let emailIndex = 0;
const emailIndexesByOrganizationId = new Map();

function _createAnonymousParticipation(databaseBuilder, organizationId, campaignId, createdAt) {
const createdDate = dayjs(createdAt)
Expand Down Expand Up @@ -541,6 +541,12 @@ function _createAnonymousParticipation(databaseBuilder, organizationId, campaign
async function _createOrRetrieveUsersAndLearners(databaseBuilder, organizationId, requiredParticipantCount) {
const userAndLearnerIds = [];

if (!emailIndexesByOrganizationId.has(organizationId)) {
emailIndexesByOrganizationId.set(organizationId, 0);
}

let emailIndex = emailIndexesByOrganizationId.get(organizationId);

const result = await databaseBuilder
.knex('organizations')
.select('type', 'isManagingStudents')
Expand Down Expand Up @@ -605,6 +611,7 @@ async function _createOrRetrieveUsersAndLearners(databaseBuilder, organizationId
userAndLearnerIds.push({ userId, organizationLearnerId });
emailIndex++;
}
emailIndexesByOrganizationId.set(organizationId, emailIndex);
return userAndLearnerIds;
}

Expand Down
8 changes: 4 additions & 4 deletions api/db/seeds/data/team-devcomp/build-campaigns.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { SCO_ORGANIZATION_ID, USER_ID_ADMIN_ORGANIZATION } from '../common/constants.js';
import { USER_ID_ADMIN_ORGANIZATION } from '../common/constants.js';
import { createAssessmentCampaign } from '../common/tooling/campaign-tooling.js';
import { PIX_EDU_SMALL_TARGET_PROFILE_ID } from './constants.js';
import { PIX_EDU_SMALL_TARGET_PROFILE_ID, TEAM_DEVCOMP_ORGANIZATION_ID } from './constants.js';

async function _createScoCampaigns(databaseBuilder, trainingIds) {
await createAssessmentCampaign({
databaseBuilder,
organizationId: SCO_ORGANIZATION_ID,
organizationId: TEAM_DEVCOMP_ORGANIZATION_ID,
ownerId: USER_ID_ADMIN_ORGANIZATION,
name: 'PIX+ EDU - SCO - envoi simple',
code: 'EDUSIMPLE',
Expand All @@ -19,7 +19,7 @@ async function _createScoCampaigns(databaseBuilder, trainingIds) {
});
await createAssessmentCampaign({
databaseBuilder,
organizationId: SCO_ORGANIZATION_ID,
organizationId: TEAM_DEVCOMP_ORGANIZATION_ID,
ownerId: USER_ID_ADMIN_ORGANIZATION,
name: 'PIX+ EDU - SCO- envoi multiple',
code: 'EDUMULTIP',
Expand Down
25 changes: 25 additions & 0 deletions api/db/seeds/data/team-devcomp/build-organization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
FEATURE_COMPUTE_ORGANIZATION_LEARNER_CERTIFICABILITY_ID,
FEATURE_MULTIPLE_SENDING_ASSESSMENT_ID,
USER_ID_ADMIN_ORGANIZATION,
USER_ID_MEMBER_ORGANIZATION,
} from '../common/constants.js';
import { organization } from '../common/tooling/index.js';
import { TEAM_DEVCOMP_ORGANIZATION_ID } from './constants.js';

export async function createDevcompOrganization(databaseBuilder) {
await organization.createOrganization({
databaseBuilder,
organizationId: TEAM_DEVCOMP_ORGANIZATION_ID,
type: 'SCO',
name: 'DevComp',
isManagingStudents: true,
externalId: 'SCO_DEVCOMP',
adminIds: [USER_ID_ADMIN_ORGANIZATION],
memberIds: [USER_ID_MEMBER_ORGANIZATION],
features: [
{ id: FEATURE_COMPUTE_ORGANIZATION_LEARNER_CERTIFICABILITY_ID },
{ id: FEATURE_MULTIPLE_SENDING_ASSESSMENT_ID },
],
});
}
9 changes: 6 additions & 3 deletions api/db/seeds/data/team-devcomp/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ const DEFAULT_PASSWORD = 'pix123';

const TEAM_DEVCOMP_OFFSET_ID = 8000;

let nextId = TEAM_DEVCOMP_OFFSET_ID;
const nextId = TEAM_DEVCOMP_OFFSET_ID;

// TARGET PROFILES
const PIX_EDU_SMALL_TARGET_PROFILE_ID = nextId++;
const PIX_EDU_SMALL_TARGET_PROFILE_ID = nextId;

export { DEFAULT_PASSWORD, PIX_EDU_SMALL_TARGET_PROFILE_ID };
// ORGANIZATIONS
const TEAM_DEVCOMP_ORGANIZATION_ID = nextId;

export { DEFAULT_PASSWORD, PIX_EDU_SMALL_TARGET_PROFILE_ID, TEAM_DEVCOMP_ORGANIZATION_ID };
2 changes: 2 additions & 0 deletions api/db/seeds/data/team-devcomp/data-builder.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { buildCampaigns } from './build-campaigns.js';
import { createDevcompOrganization } from './build-organization.js';
import { buildTargetProfiles } from './build-target-profiles.js';
import { buildTrainings } from './build-trainings.js';

async function teamDevcompDataBuilder({ databaseBuilder }) {
await buildTargetProfiles(databaseBuilder);
await createDevcompOrganization(databaseBuilder);
const trainingsIds = await buildTrainings(databaseBuilder);
await buildCampaigns(databaseBuilder, trainingsIds);
}
Expand Down

0 comments on commit 75fe625

Please sign in to comment.