-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TECH] Migrer les participation avec un statut TO_SHARE et une date d…
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
api/db/migrations/20241210103623_delete-shared-when-participation-is-to-share.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
56 changes: 56 additions & 0 deletions
56
...integration/migration/20241210103623_delete-shared-when-participation-is-to-share_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |