Skip to content

Commit

Permalink
feat(api): allow categorie filter on admin target profile summary route
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelB committed Oct 10, 2024
1 parent 13cbd21 commit 0c16fdc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
2 changes: 2 additions & 0 deletions api/src/prescription/shared/domain/types/identifiers-type.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Joi from 'joi';

import { categories } from '../../../../shared/domain/models/TargetProfile.js';
import { certificabilityByLabel } from '../../application/helpers.js';

const filterType = {
certificability: Joi.string().valid(...Object.keys(certificabilityByLabel)),
targetProfileCategory: Joi.string().valid(...Object.values(categories)),
};

export { filterType };
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Joi from 'joi';
import { BadRequestError, NotFoundError, sendJsonApiError } from '../../../shared/application/http-errors.js';
import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js';
import { identifiersType, optionalIdentifiersType } from '../../../shared/domain/types/identifiers-type.js';
import { filterType } from '../../shared/domain/types/identifiers-type.js';
import { targetProfileController } from './admin-target-profile-controller.js';

const register = async function (server) {
Expand Down Expand Up @@ -374,6 +375,7 @@ const register = async function (server) {
filter: Joi.object({
id: Joi.number().integer().empty('').allow(null).optional(),
name: Joi.string().empty('').allow(null).optional(),
categories: [filterType.targetProfileCategory, Joi.array().items(filterType.targetProfileCategory)],
}).default({}),
page: Joi.object({
number: Joi.number().integer().empty('').allow(null).optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ describe('Acceptance | Controller | training-controller', function () {
outdated: false,
'created-at': undefined,
'can-detach': false,
category: undefined,
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as TargetProfile from '../../../../../src/shared/domain/models/TargetProfile.js';
import {
createServer,
databaseBuilder,
Expand Down Expand Up @@ -567,20 +568,41 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil

// then
expect(response.statusCode).to.equal(200);
expect(response.result).to.deep.equal({
data: [
{
type: 'target-profile-summaries',
id: '1',
attributes: {
name: 'Super profil cible',
outdated: false,
'created-at': undefined,
'can-detach': false,
},
},
],
expect(response.result.data).to.have.lengthOf(1);
});
});

describe('GET /api/admin/target-profile-summaries', function () {
let userId;
let organizationId;

beforeEach(async function () {
userId = databaseBuilder.factory.buildUser.withRole().id;
organizationId = databaseBuilder.factory.buildOrganization().id;
databaseBuilder.factory.buildTargetProfile({
id: 1,
ownerOrganizationId: organizationId,
name: 'Super profil cible',
outdated: false,
category: TargetProfile.categories.OTHER,
});
await databaseBuilder.commit();
});

it('should return serialized target profile summaries', async function () {
// given
const options = {
method: 'GET',
url: `/api/admin/target-profile-summaries`,
headers: { authorization: generateValidRequestAuthorizationHeader(userId) },
};

// when
const response = await server.inject(options);

// then
expect(response.statusCode).to.equal(200);
expect(response.result.data).to.have.lengthOf(1);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { targetProfileController } from '../../../../../src/prescription/target-profile/application/admin-target-profile-controller.js';
import * as moduleUnderTest from '../../../../../src/prescription/target-profile/application/admin-target-profile-route.js';
import { securityPreHandlers } from '../../../../../src/shared/application/security-pre-handlers.js';
import { categories } from '../../../../../src/shared/domain/models/TargetProfile.js';
import { expect, HttpTestServer, sinon } from '../../../../test-helper.js';

describe('Unit | Application | Admin Target Profiles | Routes', function () {
Expand Down Expand Up @@ -1072,7 +1073,7 @@ describe('Unit | Application | Admin Target Profiles | Routes', function () {
// when
const response = await httpTestServer.request(
method,
`${url}?filter[id]=1&filter[name]=azerty&page[size]=10&page[number]=1`,
`${url}?filter[id]=1&filter[name]=azerty&filter[categories][]=${categories.COMPETENCES}&filter[categories][]=${categories.OTHER}&page[size]=10&page[number]=1`,
);

// then
Expand Down

0 comments on commit 0c16fdc

Please sign in to comment.