Skip to content

Commit

Permalink
[TECH] Supprimer le précédent score et sa date de partage dans la rép…
Browse files Browse the repository at this point in the history
…onse de l'API pour les résultats d'une campagne de collecte de profils (PIX-15267)

 #10554
  • Loading branch information
pix-service-auto-merge authored Nov 15, 2024
2 parents 5e412e0 + 553601a commit 85684fb
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ async function _buildMultipleParticipationsForPROASSMULCampaign(databaseBuilder)
});

const secondUser = await databaseBuilder.factory.buildUser.withRawPassword({
firstName: 'Jean-Philippe',
lastName: 'Errvitemonslip',
email: 'jean-philippe-errvitemonslip@example.net',
firstName: 'Tata',
lastName: 'Yoyo',
email: 'tata-yoyo@example.net',
cgu: true,
lang: 'fr',
});

const secondOrganizationLearner = await databaseBuilder.factory.buildOrganizationLearner({
firstName: 'Jean-Philippe',
lastName: 'Errvitemonslip',
firstName: 'Tata',
lastName: 'Yoyo',
userId: secondUser.id,
organizationId: PRO_ORGANIZATION_ID,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class CampaignProfilesCollectionParticipationSummary {
#previousPixScore;

constructor({
campaignParticipationId,
firstName,
Expand All @@ -8,7 +10,6 @@ class CampaignProfilesCollectionParticipationSummary {
pixScore,
sharedProfileCount,
previousPixScore,
previousSharedAt,
certifiable,
certifiableCompetencesCount,
}) {
Expand All @@ -19,9 +20,8 @@ class CampaignProfilesCollectionParticipationSummary {
this.sharedAt = sharedAt;
this.pixScore = pixScore;
this.sharedProfileCount = sharedProfileCount;
this.previousPixScore = previousPixScore ?? null;
this.previousSharedAt = previousSharedAt ?? null;
this.evolution = this.#computeEvolution(this.pixScore, this.previousPixScore);
this.#previousPixScore = previousPixScore ?? null;
this.evolution = this.#computeEvolution(this.pixScore, this.#previousPixScore);
this.certifiable = certifiable;
this.certifiableCompetencesCount = certifiableCompetencesCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function _getParticipations(qb, campaignId, filters) {
await qb
.with('previousParticipationsInfos', (qbWith) => {
qbWith
.select('pixScore AS previousPixScore', 'sharedAt AS previousSharedAt', 'organizationLearnerId', 'id')
.select('pixScore AS previousPixScore', 'organizationLearnerId', 'id')
.from('campaign-participations')
.where({ campaignId, isImproved: true })
.whereNotNull('campaign-participations.sharedAt')
Expand All @@ -74,7 +74,6 @@ async function _getParticipations(qb, campaignId, filters) {
'campaign-participations.sharedAt',
'campaign-participations.pixScore AS pixScore',
'previousParticipationsInfos.previousPixScore',
'previousParticipationsInfos.previousSharedAt',
'participationsCount.sharedProfileCount',
)
.distinctOn('campaign-participations.organizationLearnerId')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const serialize = function ({ data, pagination }) {
'sharedAt',
'pixScore',
'sharedProfileCount',
'previousPixScore',
'previousSharedAt',
'evolution',
'certifiable',
'certifiableCompetencesCount',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ describe('Integration | Repository | Campaign Profiles Collection Participation
});
});

context('additionnal informations about previous participation and evolution', function () {
context('evolution', function () {
let userId,
organizationId,
organizationLearnerId,
Expand Down Expand Up @@ -461,7 +461,7 @@ describe('Integration | Repository | Campaign Profiles Collection Participation
});

describe('when participant has only one shared participation, and the other is not shared', function () {
it('should return null for previous participations infos and evolution', async function () {
it('should return null for evolution', async function () {
// when
const results = await campaignProfilesCollectionParticipationSummaryRepository.findPaginatedByCampaignId(
campaign.id,
Expand All @@ -470,8 +470,6 @@ describe('Integration | Repository | Campaign Profiles Collection Participation
// then
expect(results.data[0]).to.deep.include({
pixScore: recentParticipationPixScore,
previousPixScore: null,
previousSharedAt: null,
evolution: null,
});
});
Expand All @@ -481,7 +479,7 @@ describe('Integration | Repository | Campaign Profiles Collection Participation
const previousParticipationPixScore = 20;
const previousParticipationSharedAt = new Date('2024-01-04');

it('should return latest participation with previous participation pixScore, sharedAt and evolution', async function () {
it('should return correct evolution', async function () {
// given
databaseBuilder.factory.buildCampaignParticipation({
campaignId: campaign.id,
Expand All @@ -504,13 +502,11 @@ describe('Integration | Repository | Campaign Profiles Collection Participation
// then
expect(results.data[0]).to.deep.include({
pixScore: recentParticipationPixScore,
previousPixScore: previousParticipationPixScore,
previousSharedAt: previousParticipationSharedAt,
evolution: 'increase',
});
});

it('should return null for previous participations infos and evolution when previous participation is deleted', async function () {
it('should return null for evolution when previous participation is deleted', async function () {
// given
databaseBuilder.factory.buildCampaignParticipation({
campaignId: campaign.id,
Expand All @@ -534,13 +530,11 @@ describe('Integration | Repository | Campaign Profiles Collection Participation
// then
expect(results.data[0]).to.deep.include({
pixScore: recentParticipationPixScore,
previousPixScore: null,
previousSharedAt: null,
evolution: null,
});
});

it('should return null for previous participations infos and evolution when learner has 2 participations to different campaigns', async function () {
it('should return null for evolution when learner has 2 participations to different campaigns', async function () {
// given
const otherCampaign = databaseBuilder.factory.buildCampaign({
type: CampaignTypes.PROFILES_COLLECTION,
Expand Down Expand Up @@ -569,13 +563,11 @@ describe('Integration | Repository | Campaign Profiles Collection Participation
// then
expect(results.data[0]).to.deep.include({
pixScore: recentParticipationPixScore,
previousPixScore: null,
previousSharedAt: null,
evolution: null,
});
});

it('should return null for previous participations infos and evolution when participations are from different learners', async function () {
it('should return null for evolution when participations are from different learners', async function () {
// given
const otherUserId = databaseBuilder.factory.buildUser({}).id;

Expand Down Expand Up @@ -608,22 +600,18 @@ describe('Integration | Repository | Campaign Profiles Collection Participation
// then
expect(results.data[0]).to.deep.include({
pixScore: recentParticipationPixScore,
previousPixScore: null,
previousSharedAt: null,
evolution: null,
});

expect(results.data[1]).to.deep.include({
pixScore: otherOrganizationLearnerParticipation.pixScore,
previousPixScore: null,
previousSharedAt: null,
evolution: null,
});
});
});

describe('when participant has a third shared participation', function () {
it('should return latest participation and additionnal infos for participation before', async function () {
it('should return correct evolution, comparing recent and previous, ignoring old', async function () {
const oldParticipationPixScore = 20;
const oldParticipationSharedAt = new Date('2024-01-02');

Expand Down Expand Up @@ -664,8 +652,6 @@ describe('Integration | Repository | Campaign Profiles Collection Participation
// then
expect(results.data[0]).to.deep.include({
pixScore: recentParticipationPixScore,
previousPixScore: previousParticipationPixScore,
previousSharedAt: previousParticipationSharedAt,
evolution: 'decrease',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ describe('Unit | Domain | Read-Models | CampaignResults | CampaignProfilesCollec
sharedAt: '2024-10-28',
pixScore: 20,
sharedProfileCount: 2,
previousPixScore: null,
previousSharedAt: null,
certifiable: true,
certifiableCompetencesCount: 9,
};

// when
const campaignProfilesCollectionParticipationSummary = new CampaignProfilesCollectionParticipationSummary({
...inputData,
previousPixScore: null,
campaignParticipationId: 45,
});

Expand All @@ -32,7 +31,7 @@ describe('Unit | Domain | Read-Models | CampaignResults | CampaignProfilesCollec
});
});

context('previous participation and evolution', function () {
context('evolution', function () {
// given
const inputCommonData = {
campaignParticipationId: 45,
Expand All @@ -42,41 +41,35 @@ describe('Unit | Domain | Read-Models | CampaignResults | CampaignProfilesCollec
certifiable: true,
certifiableCompetencesCount: 9,
sharedProfileCount: 2,
sharedAt: '2024-10-28',
};

describe('when previous participation pixScore and shared date are undefined', function () {
it('should return null for the previous pixScore, shared date and evolution', function () {
describe('when previous participation pixScore is undefined', function () {
it('should return null for evolution', function () {
// when
const campaignProfilesCollectionParticipationSummary = new CampaignProfilesCollectionParticipationSummary({
...inputCommonData,
sharedAt: '2024-10-28',
pixScore: 20,
previousPixScore: undefined,
previousSharedAt: undefined,
});

// then
expect(campaignProfilesCollectionParticipationSummary).to.include({
previousPixScore: null,
previousSharedAt: null,
evolution: null,
});
});
});

describe('when previous participation is 0', function () {
it('should return 0 for the previous pixScore (and not null)', function () {
it('should not return null for evolution', function () {
const campaignProfilesCollectionParticipationSummary = new CampaignProfilesCollectionParticipationSummary({
...inputCommonData,
sharedAt: '2024-10-28',

pixScore: 0,
previousPixScore: 0,
previousSharedAt: '2024-10-27',
});

expect(campaignProfilesCollectionParticipationSummary).to.include({
previousPixScore: 0,
});
expect(campaignProfilesCollectionParticipationSummary.evolution).to.not.be.null;
});
});

Expand All @@ -88,7 +81,6 @@ describe('Unit | Domain | Read-Models | CampaignResults | CampaignProfilesCollec
sharedAt: '2024-10-28',
pixScore: 20,
previousPixScore: 10,
previousSharedAt: '2024-10-27',
});

expect(campaignProfilesCollectionParticipationSummary).to.include({
Expand All @@ -104,7 +96,6 @@ describe('Unit | Domain | Read-Models | CampaignResults | CampaignProfilesCollec
sharedAt: '2024-10-28',
pixScore: 30,
previousPixScore: 50,
previousSharedAt: '2024-10-27',
});

expect(campaignProfilesCollectionParticipationSummary).to.include({
Expand All @@ -120,7 +111,6 @@ describe('Unit | Domain | Read-Models | CampaignResults | CampaignProfilesCollec
sharedAt: '2024-10-28',
pixScore: 30,
previousPixScore: 30,
previousSharedAt: '2024-10-27',
});

expect(campaignProfilesCollectionParticipationSummary).to.include({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('Unit | Serializer | JSONAPI | campaign-profiles-collection-participati
pixScore: 1024,
sharedProfileCount: 1,
previousPixScore: 512,
previousSharedAt: new Date(2024, 10, 29),
certifiable: true,
certifiableCompetencesCount: 8,
});
Expand All @@ -31,8 +30,6 @@ describe('Unit | Serializer | JSONAPI | campaign-profiles-collection-participati
'shared-at': new Date(2020, 2, 2),
'pix-score': 1024,
'shared-profile-count': 1,
'previous-pix-score': 512,
'previous-shared-at': new Date(2024, 10, 29),
evolution: 'increase',
certifiable: true,
'certifiable-competences-count': 8,
Expand Down

0 comments on commit 85684fb

Please sign in to comment.