Skip to content

Commit

Permalink
feat(orga): trying to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alicegoarnisson committed Dec 18, 2024
1 parent dd20ffd commit a64dbc9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions api/db/seeds/data/common/tooling/campaign-tooling.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ async function createProfilesCollectionCampaign({
userId,
snappedAt: sharedAt,
snapshot: JSON.stringify(keDataForSnapshot),
campaignParticipationId,
});

await databaseBuilder.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down Expand Up @@ -399,6 +400,7 @@ describe('Integration | Repository | knowledgeElementRepository', function () {
userId: userId1,
snappedAt: dateUserId1,
snapshot: JSON.stringify([knowledgeElement]),
campaignParticipationId,
});
await databaseBuilder.commit();

Expand All @@ -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();
});
Expand Down Expand Up @@ -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({
Expand All @@ -1020,6 +1027,7 @@ describe('Integration | Repository | knowledgeElementRepository', function () {
userId,
snappedAt: dateUserId,
snapshot: JSON.stringify([knowledgeElement]),
campaignParticipationId,
});
await databaseBuilder.commit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -47,14 +45,16 @@ 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
const error = await catchErr(knowledgeElementSnapshotRepository.save)({
userId,
snappedAt,
knowledgeElements: [],
campaignParticipationId,
});

// then
Expand Down Expand Up @@ -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'),
Expand All @@ -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
Expand All @@ -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();
});

Expand All @@ -133,13 +139,15 @@ 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 });
databaseBuilder.factory.buildKnowledgeElementSnapshot({
userId: userId2,
snappedAt: snappedAt2,
snapshot: JSON.stringify([knowledgeElement2]),
campaignParticipationId,
});
await databaseBuilder.commit();

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a64dbc9

Please sign in to comment.