Skip to content

Commit

Permalink
feat(orga): added attribute campaignParticipationId in repository and…
Browse files Browse the repository at this point in the history
… in save method
  • Loading branch information
alicegoarnisson committed Dec 18, 2024
1 parent 488a10b commit 25bde83
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ function _toKnowledgeElementCollection({ snapshot } = {}) {
);
}

const save = async function ({ userId, snappedAt, knowledgeElements }) {
const save = async function ({ userId, snappedAt, knowledgeElements, campaignParticipationId }) {
try {
const knexConn = DomainTransaction.getConnection();
return await knexConn('knowledge-element-snapshots').insert({
userId,
snappedAt,
snapshot: JSON.stringify(knowledgeElements),
campaignParticipationId,
});
} catch (error) {
if (knexUtils.isUniqConstraintViolated(error)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const updateWithSnapshot = async function (campaignParticipation) {
userId: campaignParticipation.userId,
snappedAt: campaignParticipation.sharedAt,
knowledgeElements,
campaignParticipationId: campaignParticipation.id,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ describe('Integration | Repository | KnowledgeElementSnapshotRepository', functi
// given
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'),
campaignParticipationId,
});
const knowledgeElement2 = databaseBuilder.factory.buildKnowledgeElement({
userId,
createdAt: new Date('2019-03-01'),
campaignParticipationId,
});
const knowledgeElements = [knowledgeElement1, knowledgeElement2];
await databaseBuilder.commit();

// when
await knowledgeElementSnapshotRepository.save({ userId, snappedAt, knowledgeElements });
await knowledgeElementSnapshotRepository.save({ userId, snappedAt, knowledgeElements, campaignParticipationId });

// then
const actualUserSnapshot = await knex.select('*').from('knowledge-element-snapshots').first();
Expand Down

0 comments on commit 25bde83

Please sign in to comment.