From eb385a37fd2410182981b274138595a938adbb84 Mon Sep 17 00:00:00 2001 From: Laura Bergoens Date: Thu, 12 Dec 2024 11:40:12 +0100 Subject: [PATCH] bugfix(api): guard code against invalid values in tutorial repository --- .../repositories/tutorial-repository_test.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/api/tests/devcomp/integration/infrastructure/repositories/tutorial-repository_test.js b/api/tests/devcomp/integration/infrastructure/repositories/tutorial-repository_test.js index 63a5e86e6ac..a055c080336 100644 --- a/api/tests/devcomp/integration/infrastructure/repositories/tutorial-repository_test.js +++ b/api/tests/devcomp/integration/infrastructure/repositories/tutorial-repository_test.js @@ -170,6 +170,57 @@ describe('Integration | Repository | tutorial-repository', function () { expect(tutorials).to.have.lengthOf(1); expect(tutorials[0].tutorialEvaluation).to.deep.equal(tutorialEvaluation); }); + + it('should return empty array when invalid argument given for ids', 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 tutorials1 = await tutorialRepository.findByRecordIdsForCurrentUser({ + ids: [], + userId: null, + }); + const tutorials2 = await tutorialRepository.findByRecordIdsForCurrentUser({ + ids: null, + userId: null, + }); + const tutorials3 = await tutorialRepository.findByRecordIdsForCurrentUser({ + ids: undefined, + userId: null, + }); + + // then + expect(tutorials1).to.deep.equal([]); + expect(tutorials2).to.deep.equal([]); + expect(tutorials3).to.deep.equal([]); + }); }); describe('#findPaginatedFilteredForCurrentUser', function () {