Skip to content

Commit

Permalink
[BUGFIX] Garantir un comportement ISO entre l'ancienne version et la …
Browse files Browse the repository at this point in the history
…nouvelle version du repository lorsqu'on passe des valeurs invalides en guise de collection (PIX-15696)

 #10795
  • Loading branch information
pix-service-auto-merge authored Dec 12, 2024
2 parents 1a587cd + eb385a3 commit 965ce2e
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/lib/infrastructure/repositories/tube-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export async function list() {

export async function findByNames({ tubeNames, locale }) {
if (!config.featureToggles.useNewLearningContent) return oldTubeRepository.findByNames({ tubeNames, locale });
if (!tubeNames) {
return [];
}
const ids = await knex.pluck('id').from(TABLE_NAME).whereIn('name', tubeNames).orderBy('name');
const tubeDtos = await getInstance().loadMany(ids);
return toDomainList(tubeDtos, locale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,20 @@ describe('Integration | Repository | tube-repository', function () {
expect(tubes).to.deep.equal([]);
});
});

context('when invalid value provided for tubeNames argument', function () {
it('should return an empty array', async function () {
// when
const tubes1 = await tubeRepository.findByNames({ tubeNames: null });
const tubes2 = await tubeRepository.findByNames({ tubeNames: undefined });
const tubes3 = await tubeRepository.findByNames({ tubeNames: [] });

// then
expect(tubes1).to.deep.equal([]);
expect(tubes2).to.deep.equal([]);
expect(tubes3).to.deep.equal([]);
});
});
});

describe('#findByRecordIds', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,20 @@ describe('Integration | Repository | skill-repository', function () {
]);
});
});

context('when invalid value given for ids argument', function () {
it('should return an empty array', async function () {
// when
const skills1 = await skillRepository.findOperativeByIds(null);
const skills2 = await skillRepository.findOperativeByIds(undefined);
const skills3 = await skillRepository.findOperativeByIds([]);

// then
expect(skills1).to.deep.equal([]);
expect(skills2).to.deep.equal([]);
expect(skills3).to.deep.equal([]);
});
});
});

describe('#get', function () {
Expand Down Expand Up @@ -761,6 +775,20 @@ describe('Integration | Repository | skill-repository', function () {
]);
});
});

context('when invalid value given for ids argument', function () {
it('should return an empty array', async function () {
// when
const skills1 = await skillRepository.findActiveByRecordIds(null);
const skills2 = await skillRepository.findActiveByRecordIds(undefined);
const skills3 = await skillRepository.findActiveByRecordIds([]);

// then
expect(skills1).to.deep.equal([]);
expect(skills2).to.deep.equal([]);
expect(skills3).to.deep.equal([]);
});
});
});

describe('#findByRecordIds', function () {
Expand Down Expand Up @@ -846,6 +874,20 @@ describe('Integration | Repository | skill-repository', function () {
]);
});
});

context('when invalid value given for ids argument', function () {
it('should return an empty array', async function () {
// when
const skills1 = await skillRepository.findByRecordIds(null);
const skills2 = await skillRepository.findByRecordIds(undefined);
const skills3 = await skillRepository.findByRecordIds([]);

// then
expect(skills1).to.deep.equal([]);
expect(skills2).to.deep.equal([]);
expect(skills3).to.deep.equal([]);
});
});
});
}
});

0 comments on commit 965ce2e

Please sign in to comment.