Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Autoriser l'affichage des campagnes de type EXAM sur le dashboard d'un utilisateur (PIX-16821) #11607

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const findByUserIdWithFilters = async function ({ userId, states, page }) {
}

const { results, pagination } = await fetchPage(queryBuilder, page);

return {
campaignParticipationOverviews: results.map(
(campaignParticipationOverview) => new CampaignParticipationOverview(campaignParticipationOverview),
Expand Down Expand Up @@ -46,13 +45,22 @@ function _findByUserId({ userId }) {
campaignId: 'campaigns.id',
})
.from('campaign-participations')
.innerJoin('campaigns', 'campaign-participations.campaignId', 'campaigns.id')
.innerJoin('organizations', 'organizations.id', 'campaigns.organizationId')
.whereNot('organizations.id', constants.AUTONOMOUS_COURSES_ORGANIZATION_ID)
.join('campaigns', function () {
this.on('campaign-participations.campaignId', 'campaigns.id').andOnVal(
'campaigns.isForAbsoluteNovice',
false,
);
})
.join('organizations', function () {
this.on('organizations.id', 'campaigns.organizationId').andOnVal(
'organizations.id',
knex.raw('!='),
constants.AUTONOMOUS_COURSES_ORGANIZATION_ID,
);
})
.whereIn('campaigns.type', [CampaignTypes.ASSESSMENT, CampaignTypes.EXAM])
.where('campaign-participations.userId', userId)
.where('campaign-participations.isImproved', false)
.where('campaigns.type', CampaignTypes.ASSESSMENT)
.whereNot('campaigns.isForAbsoluteNovice', true);
.where('campaign-participations.isImproved', false);
})
.from('campaign-participation-overviews')
.orderByRaw(_computeCampaignParticipationOrder())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,5 +634,61 @@ describe('Integration | Repository | Campaign Participation Overview', function
expect(campaignParticipationOverviews).to.have.lengthOf(0);
});
});

context('when there is an campaign of PROFILE_COLLECTION', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of type

it('should not keep the autonomous course from the campaign participations list', async function () {
// given
const { id: organizationId } = databaseBuilder.factory.buildOrganization({ ownerOrganizationId: userId });
const { id: campaignId } = databaseBuilder.factory.buildCampaign({
organizationId,
type: CampaignTypes.PROFILES_COLLECTION,
targetProfileId: null,
});
const organizationLearnerId =
databaseBuilder.factory.prescription.organizationLearners.buildOrganizationLearner({ userId }).id;
databaseBuilder.factory.buildCampaignParticipation({
userId,
organizationLearnerId,
campaignId,
});

await databaseBuilder.commit();

// when
const { campaignParticipationOverviews } =
await campaignParticipationOverviewRepository.findByUserIdWithFilters({ userId });

// then
expect(campaignParticipationOverviews).to.have.lengthOf(0);
});
});

context('when there is an campaign of EXAM', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of type

it('should not keep the autonomous course from the campaign participations list', async function () {
// given
const { id: organizationId } = databaseBuilder.factory.buildOrganization({ ownerOrganizationId: userId });
const { id: campaignId } = databaseBuilder.factory.buildCampaign({
organizationId,
type: CampaignTypes.EXAM,
targetProfileId: null,
});
const organizationLearnerId =
databaseBuilder.factory.prescription.organizationLearners.buildOrganizationLearner({ userId }).id;
databaseBuilder.factory.buildCampaignParticipation({
userId,
organizationLearnerId,
campaignId,
});

await databaseBuilder.commit();

// when
const { campaignParticipationOverviews } =
await campaignParticipationOverviewRepository.findByUserIdWithFilters({ userId });

// then
expect(campaignParticipationOverviews).to.have.lengthOf(1);
});
});
});
});