Skip to content

Commit

Permalink
[TECH] Migrer les participation avec un statut TO_SHARE et une date d…
Browse files Browse the repository at this point in the history
…e participation (PIX-15647).

 #10773
  • Loading branch information
pix-service-auto-merge authored Dec 12, 2024
2 parents de89c8c + 909353d commit 9ebd2c0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CampaignParticipationStatuses } from '../../src/prescription/shared/domain/constants.js';

const up = async function (knex) {
await knex('campaign-participations')
.update({ sharedAt: null })
.where({ status: CampaignParticipationStatuses.TO_SHARE })
.whereNotNull('sharedAt');
};

const down = function () {
return;
};

export { down, up };
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { up as migrationToTest } from '../../../db/migrations/20241210103623_delete-shared-when-participation-is-to-share.js';
import { CampaignParticipationStatuses } from '../../../src/prescription/shared/domain/constants.js';
import { databaseBuilder, expect, knex } from '../../test-helper.js';

describe('Integration | Migration | delete-shared-when-participation-is-to-share', function () {
let buggyParticipation, sharedParticipation, sharedAt;

beforeEach(async function () {
sharedAt = new Date(2024, 10, 1);
const user = databaseBuilder.factory.buildUser();
const learner = databaseBuilder.factory.prescription.organizationLearners.buildOrganizationLearner({
userId: user.id,
});
const user2 = databaseBuilder.factory.buildUser();
const learner2 = databaseBuilder.factory.prescription.organizationLearners.buildOrganizationLearner({
userId: user2.id,
});
const campaign = databaseBuilder.factory.buildCampaign();
buggyParticipation = databaseBuilder.factory.buildCampaignParticipation({
campaignId: campaign.id,
organizationLearnerId: learner.id,
userId: user.id,
status: CampaignParticipationStatuses.TO_SHARE,
sharedAt,
});

sharedParticipation = databaseBuilder.factory.buildCampaignParticipation({
campaignId: campaign.id,
organizationLearnerId: learner2.id,
userId: user2.id,
status: CampaignParticipationStatuses.SHARED,
sharedAt,
});

await databaseBuilder.commit();
});

it('should set sharedAt at null for participation with sharedAt and status is TO_SHARE', async function () {
// when
await migrationToTest(knex);
// then
const patchedParticipation = await knex('campaign-participations').where('id', buggyParticipation.id).first();

expect(patchedParticipation.sharedAt).is.null;
});

it('should not update SHARED participation', async function () {
// when
await migrationToTest(knex);

// then
const participation = await knex('campaign-participations').where('id', sharedParticipation.id).first();

expect(participation.sharedAt).deep.equal(sharedAt);
});
});

0 comments on commit 9ebd2c0

Please sign in to comment.