diff --git a/api/db/seeds/data/common/tooling/campaign-tooling.js b/api/db/seeds/data/common/tooling/campaign-tooling.js index 2729ecf99e2..fcadd220111 100644 --- a/api/db/seeds/data/common/tooling/campaign-tooling.js +++ b/api/db/seeds/data/common/tooling/campaign-tooling.js @@ -405,6 +405,7 @@ async function createProfilesCollectionCampaign({ userId, snappedAt: sharedAt, snapshot: JSON.stringify(keDataForSnapshot), + campaignParticipationId, }); await databaseBuilder.commit(); diff --git a/api/tests/integration/infrastructure/repositories/knowledge-element-repository_test.js b/api/tests/integration/infrastructure/repositories/knowledge-element-repository_test.js index dee17a27aaf..4dade014053 100644 --- a/api/tests/integration/infrastructure/repositories/knowledge-element-repository_test.js +++ b/api/tests/integration/infrastructure/repositories/knowledge-element-repository_test.js @@ -313,12 +313,13 @@ describe('Integration | Repository | knowledgeElementRepository', function () { }); describe('#findSnapshotGroupedByCompetencesForUsers', function () { - let userId1, userId2, sandbox; + let userId1, userId2, campaignParticipationId, sandbox; beforeEach(function () { sandbox = sinon.createSandbox(); userId1 = databaseBuilder.factory.buildUser().id; userId2 = databaseBuilder.factory.buildUser().id; + campaignParticipationId = databaseBuilder.factory.buildCampaignParticipation().id; return databaseBuilder.commit(); }); @@ -399,6 +400,7 @@ describe('Integration | Repository | knowledgeElementRepository', function () { userId: userId1, snappedAt: dateUserId1, snapshot: JSON.stringify([knowledgeElement]), + campaignParticipationId, }); await databaseBuilder.commit(); @@ -416,11 +418,14 @@ describe('Integration | Repository | knowledgeElementRepository', function () { context('when user does not have a snapshot for this date', function () { context('when no date is provided along with the user', function () { let expectedKnowledgeElement; + let campaignParticipationId; beforeEach(function () { + campaignParticipationId = databaseBuilder.factory.buildCampaignParticipation().id; expectedKnowledgeElement = databaseBuilder.factory.buildKnowledgeElement({ userId: userId1, createdAt: new Date('2018-01-01'), + campaignParticipationId, }); return databaseBuilder.commit(); }); @@ -1010,6 +1015,8 @@ describe('Integration | Repository | knowledgeElementRepository', function () { it('should return the knowledge elements in the snapshot when user has a snapshot for this date', async function () { // given const learningContent = domainBuilder.buildCampaignLearningContent.withSimpleContent(); + const campaignParticipationId = databaseBuilder.factory.buildCampaignParticipation().id; + const userId = databaseBuilder.factory.buildUser().id; const dateUserId = new Date('2020-01-03'); const knowledgeElement = databaseBuilder.factory.buildKnowledgeElement({ @@ -1020,6 +1027,7 @@ describe('Integration | Repository | knowledgeElementRepository', function () { userId, snappedAt: dateUserId, snapshot: JSON.stringify([knowledgeElement]), + campaignParticipationId, }); await databaseBuilder.commit(); diff --git a/api/tests/integration/infrastructure/repositories/knowledge-element-snapshot-repository_test.js b/api/tests/integration/infrastructure/repositories/knowledge-element-snapshot-repository_test.js index 4ce380f78d7..b9a0dffc870 100644 --- a/api/tests/integration/infrastructure/repositories/knowledge-element-snapshot-repository_test.js +++ b/api/tests/integration/infrastructure/repositories/knowledge-element-snapshot-repository_test.js @@ -14,12 +14,10 @@ describe('Integration | Repository | KnowledgeElementSnapshotRepository', functi const knowledgeElement1 = databaseBuilder.factory.buildKnowledgeElement({ userId, createdAt: new Date('2019-03-01'), - campaignParticipationId, }); const knowledgeElement2 = databaseBuilder.factory.buildKnowledgeElement({ userId, createdAt: new Date('2019-03-01'), - campaignParticipationId, }); const knowledgeElements = [knowledgeElement1, knowledgeElement2]; await databaseBuilder.commit(); @@ -47,7 +45,8 @@ describe('Integration | Repository | KnowledgeElementSnapshotRepository', functi // given const snappedAt = new Date('2019-04-01'); const userId = databaseBuilder.factory.buildUser().id; - databaseBuilder.factory.buildKnowledgeElementSnapshot({ userId, snappedAt }); + const campaignParticipationId = databaseBuilder.factory.buildCampaignParticipation().id; + databaseBuilder.factory.buildKnowledgeElementSnapshot({ userId, snappedAt, campaignParticipationId }); await databaseBuilder.commit(); // when @@ -55,6 +54,7 @@ describe('Integration | Repository | KnowledgeElementSnapshotRepository', functi userId, snappedAt, knowledgeElements: [], + campaignParticipationId, }); // then @@ -94,6 +94,7 @@ describe('Integration | Repository | KnowledgeElementSnapshotRepository', functi it('does not save knowledge elements snapshot using a transaction', async function () { const snappedAt = new Date('2019-04-01'); const userId = databaseBuilder.factory.buildUser().id; + const campaignParticipationId = databaseBuilder.factory.buildCampaignParticipation().id; const knowledgeElement1 = databaseBuilder.factory.buildKnowledgeElement({ userId, createdAt: new Date('2019-03-01'), @@ -103,7 +104,12 @@ describe('Integration | Repository | KnowledgeElementSnapshotRepository', functi try { await DomainTransaction.execute(async () => { - await knowledgeElementSnapshotRepository.save({ userId, snappedAt, knowledgeElements }); + await knowledgeElementSnapshotRepository.save({ + userId, + snappedAt, + knowledgeElements, + campaignParticipationId, + }); throw new Error(); }); // eslint-disable-next-line no-empty @@ -116,12 +122,12 @@ describe('Integration | Repository | KnowledgeElementSnapshotRepository', functi }); describe('#findByUserIdsAndSnappedAtDates', function () { - let userId1; - let userId2; + let userId1, userId2, campaignParticipationId; beforeEach(function () { userId1 = databaseBuilder.factory.buildUser().id; userId2 = databaseBuilder.factory.buildUser().id; + campaignParticipationId = databaseBuilder.factory.buildCampaignParticipation().id; return databaseBuilder.commit(); }); @@ -133,6 +139,7 @@ describe('Integration | Repository | KnowledgeElementSnapshotRepository', functi userId: userId1, snappedAt: snappedAt1, snapshot: JSON.stringify([knowledgeElement1]), + campaignParticipationId, }); const snappedAt2 = new Date('2020-02-02'); const knowledgeElement2 = databaseBuilder.factory.buildKnowledgeElement({ userId: userId2 }); @@ -140,6 +147,7 @@ describe('Integration | Repository | KnowledgeElementSnapshotRepository', functi userId: userId2, snappedAt: snappedAt2, snapshot: JSON.stringify([knowledgeElement2]), + campaignParticipationId, }); await databaseBuilder.commit(); @@ -254,9 +262,9 @@ describe('Integration | Repository | KnowledgeElementSnapshotRepository', functi // when const knowledgeElementsByUserId = await knowledgeElementSnapshotRepository.findMultipleUsersFromUserIdsAndSnappedAtDates([ - { userId: userId1, sharedAt: snappedAt1, campaignParticipationId: campaignParticipation1 }, - { userId: userId2, sharedAt: snappedAt2, campaignParticipationId: campaignParticipation2 }, - { userId: userId2, sharedAt: snappedAt3, campaignParticipationId: campaignParticipation3 }, + { userId: userId1, sharedAt: snappedAt1 }, + { userId: userId2, sharedAt: snappedAt2 }, + { userId: userId2, sharedAt: snappedAt3 }, ]); // then