Skip to content

Commit

Permalink
refactor(api): move route
Browse files Browse the repository at this point in the history
  • Loading branch information
igorissen committed Jun 20, 2024
1 parent a79e09a commit cb4debe
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 33 deletions.
29 changes: 0 additions & 29 deletions api/lib/application/account-recovery/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import JoiDate from '@joi/date';
import BaseJoi from 'joi';
const Joi = BaseJoi.extend(JoiDate);
import XRegExp from 'xregexp';
const inePattern = new RegExp('^[0-9]{9}[a-zA-Z]{2}$');
const inaPattern = new RegExp('^[0-9]{10}[a-zA-Z]{1}$');

import { config } from '../../config.js';
import { accountRecoveryController } from './account-recovery-controller.js';

const { passwordValidationPattern } = config.account;

const register = async function (server) {
server.route([
{
Expand Down Expand Up @@ -57,31 +53,6 @@ const register = async function (server) {
tags: ['api', 'account-recovery'],
},
},
{
method: 'PATCH',
path: '/api/account-recovery',
config: {
auth: false,
handler: accountRecoveryController.updateUserAccountFromRecoveryDemand,
validate: {
payload: Joi.object({
data: {
attributes: {
'temporary-key': Joi.string().min(32).required(),
password: Joi.string().pattern(XRegExp(passwordValidationPattern)).required(),
},
},
}),
options: {
allowUnknown: true,
},
},
notes: [
'- Permet de mettre à jour les informations d’un utilisateur via à une demande de récupération de compte.',
],
tags: ['api', 'account-recovery'],
},
},
]);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Joi from 'joi';
import XRegExp from 'xregexp';

import { config } from '../../../shared/config.js';
import { accountRecoveryController } from './account-recovery.controller.js';

const { passwordValidationPattern } = config.account;

export const accountRecoveryRoutes = [
{
method: 'PATCH',
path: '/api/account-recovery',
config: {
auth: false,
handler: (request, h) => accountRecoveryController.updateUserAccountFromRecoveryDemand(request, h),
validate: {
payload: Joi.object({
data: {
attributes: {
'temporary-key': Joi.string().min(32).required(),
password: Joi.string().pattern(XRegExp(passwordValidationPattern)).required(),
},
},
}),
options: {
allowUnknown: true,
},
},
notes: [
'- Permet de mettre à jour les informations d’un utilisateur via à une demande de récupération de compte.',
],
tags: ['identity-access-management', 'api', 'account-recovery'],
},
},
];
2 changes: 2 additions & 0 deletions api/src/identity-access-management/application/routes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { accountRecoveryRoutes } from './account-recovery/account-recovery.route.js';
import { anonymizationAdminRoutes } from './anonymization/anonymization.admin.route.js';
import { oidcProviderAdminRoutes } from './oidc-provider/oidc-provider.admin.route.js';
import { oidcProviderRoutes } from './oidc-provider/oidc-provider.route.js';
Expand All @@ -9,6 +10,7 @@ import { userRoutes } from './user/user.route.js';

const register = async function (server) {
server.route([
...accountRecoveryRoutes,
...anonymizationAdminRoutes,
...oidcProviderAdminRoutes,
...oidcProviderRoutes,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createServer, databaseBuilder, expect, knex } from '../../../test-helper.js';
import { createServer, databaseBuilder, expect, knex } from '../../../../test-helper.js';

describe('Acceptance | Route | Account-recovery', function () {
describe('Acceptance | Identity Access Management | Application | Route | account-recovery', function () {
describe('PATCH /api/account-recovery', function () {
context('when user has pix authentication method', function () {
it("should proceed to the account recover by changing user's password and email", async function () {
it("proceeds to the account recover by changing user's password and email", async function () {
// given
const server = await createServer();
const userId = databaseBuilder.factory.buildUser.withRawPassword({
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('Acceptance | Route | Account-recovery', function () {
});

context('when user has no pix authentication method', function () {
it('should proceed to the account recover by create pix authentication method', async function () {
it('proceeds to the account recover by create pix authentication method', async function () {
// given
const server = await createServer();
const userWithGarAuthenticationMethod = databaseBuilder.factory.buildUser.withoutPixAuthenticationMethod({
Expand Down

0 comments on commit cb4debe

Please sign in to comment.