Skip to content

Commit

Permalink
breaking test for tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
laura-bergoens committed Dec 10, 2024
1 parent 138caba commit 4b6044d
Showing 1 changed file with 119 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { catchErr, databaseBuilder, domainBuilder, expect, mockLearningContent }
const { ENGLISH_SPOKEN } = LOCALE;

describe('Integration | Repository | tutorial-repository', function () {
testTurorialRepository(); // eslint-disable-line mocha/no-setup-in-describe
testTutorialRepository(); // eslint-disable-line mocha/no-setup-in-describe

describe('when using old learning content', function () {
beforeEach(function () {
Expand All @@ -24,10 +24,10 @@ describe('Integration | Repository | tutorial-repository', function () {
config.featureToggles.useNewLearningContent = true;
});

testTurorialRepository(); // eslint-disable-line mocha/no-setup-in-describe
testTutorialRepository(); // eslint-disable-line mocha/no-setup-in-describe
});

function testTurorialRepository() {
function testTutorialRepository() {
describe('#findByRecordIdsForCurrentUser', function () {
it('should find tutorials by ids', async function () {
// given
Expand Down Expand Up @@ -72,6 +72,49 @@ describe('Integration | Repository | tutorial-repository', function () {
expect(tutorials).to.deep.include.members(tutorialsList);
});

it('should avoid duplicates and nulls', async function () {
// given
const tutorialsList = [
{
duration: '00:00:54',
format: 'video',
link: 'https://tuto.fr',
source: 'tuto.fr',
title: 'tuto0',
id: 'recTutorial0',
skillId: undefined,
userSavedTutorial: undefined,
tutorialEvaluation: undefined,
},
{
duration: '00:01:54',
format: 'page',
link: 'https://tuto.com',
source: 'tuto.com',
title: 'tuto1',
id: 'recTutorial1',
skillId: undefined,
userSavedTutorial: undefined,
tutorialEvaluation: undefined,
},
];

await mockLearningContent({
tutorials: tutorialsList,
});

// when
const tutorials = await tutorialRepository.findByRecordIdsForCurrentUser({
ids: ['recTutorial0', 'recTutorial1', 'recCOUCOUPAPA', 'recTutorial1'],
userId: null,
});

// then
expect(tutorials).to.have.lengthOf(2);
expect(tutorials[0]).to.be.instanceof(TutorialForUser);
expect(tutorials).to.deep.include.members(tutorialsList);
});

it('should associate userSavedTutorial when it exists for provided user', async function () {
// given
const userId = databaseBuilder.factory.buildUser().id;
Expand Down Expand Up @@ -856,6 +899,79 @@ describe('Integration | Repository | tutorial-repository', function () {
tutorialId: 'tuto4',
});
});

it('should avoid nulls and duplicates', async function () {
// given
databaseBuilder.factory.buildKnowledgeElement({
skillId: 'recSkill3',
userId,
status: KnowledgeElement.StatusType.INVALIDATED,
source: KnowledgeElement.SourceType.DIRECT,
createdAt: new Date('2000-01-01'),
});
databaseBuilder.factory.buildKnowledgeElement({
skillId: 'recSkill3',
userId,
status: KnowledgeElement.StatusType.INVALIDATED,
source: KnowledgeElement.SourceType.DIRECT,
createdAt: new Date('2000-01-02'),
});
databaseBuilder.factory.buildKnowledgeElement({
skillId: 'recSkillWithoutTuto',
userId,
status: KnowledgeElement.StatusType.INVALIDATED,
source: KnowledgeElement.SourceType.DIRECT,
createdAt: new Date('2000-01-02'),
});
const userSavedTutorialId = databaseBuilder.factory.buildUserSavedTutorial({
userId,
tutorialId: 'tuto4',
skillId: 'recSkill3',
}).id;
const tutorialEvaluationId = databaseBuilder.factory.buildTutorialEvaluation({
tutorialId: 'tuto4',
userId,
}).id;
await databaseBuilder.commit();
await mockLearningContent({
tutorials: [
{
id: 'tuto4',
locale: 'fr-fr',
},
],
skills: [
{
id: 'recSkill3',
tutorialIds: ['tuto4'],
status: 'actif',
},
{
id: 'recSkillWithoutTuto',
tutorialIds: [],
status: 'actif',
},
],
});

// when
const { results } = await tutorialRepository.findPaginatedFilteredRecommendedByUserId({ userId });

// then
expect(results.length).to.equal(1);
expect(results[0].tutorialEvaluation).to.include({
id: tutorialEvaluationId,
userId,
tutorialId: 'tuto4',
status: TutorialEvaluation.statuses.LIKED,
});
expect(results[0].userSavedTutorial).to.include({
id: userSavedTutorialId,
userId,
skillId: 'recSkill3',
tutorialId: 'tuto4',
});
});
});

describe('when tutorials amount exceed page size', function () {
Expand Down

0 comments on commit 4b6044d

Please sign in to comment.