Skip to content

Commit

Permalink
feat(api): add filter category
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBazin committed Oct 9, 2024
1 parent 8a7e064 commit 4a70355
Showing 1 changed file with 71 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,46 +147,45 @@ describe('Integration | Repository | Target-profile-summary-for-admin', function
});

context('when passing a filter', function () {
let targetProfileData;
beforeEach(function () {
targetProfileData = [
{
id: 1,
name: 'TP DISCIPLINE',
outdated: false,
createdAt: new Date('2021-01-01'),
category: TargetProfile.categories.DISCIPLINE,
},
{
id: 2,
name: 'Outdated DISCIPLINE',
outdated: true,
createdAt: new Date('2021-01-01'),
category: TargetProfile.categories.DISCIPLINE,
},
{
id: 3,
name: 'TP BACK_TO_SCHOOL',
outdated: false,
createdAt: new Date('2021-01-01'),
category: TargetProfile.categories.BACK_TO_SCHOOL,
},
{
id: 4,
name: 'Outdated BACK_TO_SCHOOL',
outdated: true,
createdAt: new Date('2021-01-01'),
category: TargetProfile.categories.BACK_TO_SCHOOL,
},
];
targetProfileData.map(databaseBuilder.factory.buildTargetProfile);
return databaseBuilder.commit();
});
context('name filter', function () {
let targetProfileData;
beforeEach(function () {
targetProfileData = [
{
id: 1,
name: 'paTtErN',
outdated: false,
createdAt: new Date('2021-01-01'),
category: TargetProfile.categories.DISCIPLINE,
},
{
id: 2,
name: 'AApatterNOo',
outdated: true,
createdAt: new Date('2021-01-01'),
category: TargetProfile.categories.DISCIPLINE,
},
{
id: 3,
name: 'NotUnderTheRadar',
outdated: false,
createdAt: new Date('2021-01-01'),
category: TargetProfile.categories.DISCIPLINE,
},
{
id: 4,
name: 'PaTternXXXX',
outdated: true,
createdAt: new Date('2021-01-01'),
category: TargetProfile.categories.DISCIPLINE,
},
];
targetProfileData.map(databaseBuilder.factory.buildTargetProfile);
return databaseBuilder.commit();
});

it('should return only target profiles matching "name" pattern in filter', async function () {
it('should return only target profiles matching "name" discipline in filter', async function () {
// given
const filter = { name: 'pattern' };
const filter = { name: 'discipline' };
const page = { number: 1, size: 10 };

// when
Expand All @@ -200,21 +199,14 @@ describe('Integration | Repository | Target-profile-summary-for-admin', function
const expectedTargetProfileSummaries = [
domainBuilder.buildTargetProfileSummaryForAdmin({
id: 1,
name: 'paTtErN',
name: 'TP DISCIPLINE',
outdated: false,
createdAt: new Date('2021-01-01'),
category: TargetProfile.categories.DISCIPLINE,
}),
domainBuilder.buildTargetProfileSummaryForAdmin({
id: 2,
name: 'AApatterNOo',
outdated: true,
createdAt: new Date('2021-01-01'),
category: TargetProfile.categories.DISCIPLINE,
}),
domainBuilder.buildTargetProfileSummaryForAdmin({
id: 4,
name: 'PaTternXXXX',
name: 'Outdated DISCIPLINE',
outdated: true,
createdAt: new Date('2021-01-01'),
category: TargetProfile.categories.DISCIPLINE,
Expand All @@ -224,27 +216,35 @@ describe('Integration | Repository | Target-profile-summary-for-admin', function
});
});
context('id filter', function () {
let targetProfileData;
beforeEach(function () {
targetProfileData = [
{
it('should return only target profiles with exact match ID', async function () {
// given
const filter = { id: 1 };
const page = { number: 1, size: 10 };

// when
const { models: actualTargetProfileSummaries } =
await targetProfileSummaryForAdminRepository.findPaginatedFiltered({
filter,
page,
});

// then
const expectedTargetProfileSummaries = [
domainBuilder.buildTargetProfileSummaryForAdmin({
id: 1,
name: 'TPA',
name: 'TP DISCIPLINE',
outdated: false,
createdAt: new Date('2021-01-01'),
category: TargetProfile.categories.PIX_PLUS,
},
{ id: 11, name: 'TPB', outdated: true, createdAt: new Date('2021-01-01') },
{ id: 21, name: 'TPC', outdated: false, createdAt: new Date('2021-01-01') },
{ id: 4, name: 'TPD', outdated: true, createdAt: new Date('2021-01-01') },
category: TargetProfile.categories.DISCIPLINE,
}),
];
targetProfileData.map(databaseBuilder.factory.buildTargetProfile);
return databaseBuilder.commit();
expect(actualTargetProfileSummaries).to.deepEqualArray(expectedTargetProfileSummaries);
});

it('should return only target profiles with exact match ID', async function () {
});
context('category filter', function () {
it('should return only target profiles with matching category discipline', async function () {
// given
const filter = { id: 1 };
const filter = { category: TargetProfile.categories.DISCIPLINE };
const page = { number: 1, size: 10 };

// when
Expand All @@ -258,26 +258,23 @@ describe('Integration | Repository | Target-profile-summary-for-admin', function
const expectedTargetProfileSummaries = [
domainBuilder.buildTargetProfileSummaryForAdmin({
id: 1,
name: 'TPA',
name: 'TP DISCIPLINE',
outdated: false,
createdAt: new Date('2021-01-01'),
category: TargetProfile.categories.PIX_PLUS,
category: TargetProfile.categories.DISCIPLINE,
}),
domainBuilder.buildTargetProfileSummaryForAdmin({
id: 1,
name: 'Outdated DISCIPLINE',
outdated: true,
createdAt: new Date('2021-01-01'),
category: TargetProfile.categories.DISCIPLINE,
}),
];
expect(actualTargetProfileSummaries).to.deepEqualArray(expectedTargetProfileSummaries);
});
});
context('no match', function () {
let targetProfileData;
beforeEach(function () {
targetProfileData = [
{ id: 1, name: 'HELLO', outdated: false },
{ id: 2, name: 'SALUT', outdated: true },
];
targetProfileData.map(databaseBuilder.factory.buildTargetProfile);
return databaseBuilder.commit();
});

it('should return an empty array when no records match the filter', async function () {
// given
const filter = { name: 'COUCOU' };
Expand Down

0 comments on commit 4a70355

Please sign in to comment.