Skip to content

Commit

Permalink
feat(api): change the accept-ToS route to use new legal document vers…
Browse files Browse the repository at this point in the history
…ioning code
  • Loading branch information
EmmanuelleBonnemay authored and lego-technix committed Dec 23, 2024
1 parent ada9c42 commit e59f8d1
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ const acceptPixLastTermsOfService = async function (request, h, dependencies = {
* }} dependencies
* @return {Promise<*>}
*/
const acceptPixOrgaTermsOfService = async function (request, h, dependencies = { userSerializer }) {
const acceptPixOrgaTermsOfService = async function (request, h) {
const authenticatedUserId = request.auth.credentials.userId;

const updatedUser = await usecases.acceptPixOrgaTermsOfService({
await usecases.acceptPixOrgaTermsOfService({
userId: authenticatedUserId,
});

return dependencies.userSerializer.serialize(updatedUser);
return h.response().code(204);
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* @param {{
* userId: string,
* userRepository: UserRepository
* legalDocumentApiRepository: legalDocumentApiRepository
* }} params
* @return {Promise<User>}
* @return {Promise<void>}
*/
export const acceptPixOrgaTermsOfService = function ({ userId, userRepository }) {
return userRepository.updatePixOrgaTermsOfServiceAcceptedToTrue(userId);
export const acceptPixOrgaTermsOfService = function ({ userId, legalDocumentApiRepository }) {
return legalDocumentApiRepository.acceptPixOrgaTos({ userId });
};
2 changes: 2 additions & 0 deletions api/src/identity-access-management/domain/usecases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { emailValidationDemandRepository } from '../../infrastructure/repositori
import { eventLoggingJobRepository } from '../../infrastructure/repositories/jobs/event-logging-job.repository.js';
import { garAnonymizedBatchEventsLoggingJobRepository } from '../../infrastructure/repositories/jobs/gar-anonymized-batch-events-logging-job-repository.js';
import { userAnonymizedEventLoggingJobRepository } from '../../infrastructure/repositories/jobs/user-anonymized-event-logging-job-repository.js';
import { legalDocumentApiRepository } from '../../infrastructure/repositories/legal-document-api.repository.js';
import { oidcProviderRepository } from '../../infrastructure/repositories/oidc-provider-repository.js';
import * as privacyUsersApiRepository from '../../infrastructure/repositories/privacy-users-api.repository.js';
import { refreshTokenRepository } from '../../infrastructure/repositories/refresh-token.repository.js';
Expand Down Expand Up @@ -61,6 +62,7 @@ const repositories = {
emailValidationDemandRepository,
emailRepository,
eventLoggingJobRepository,
legalDocumentApiRepository,
membershipRepository,
oidcProviderRepository,
organizationLearnerRepository,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as legalDocumentApi from '../../../legal-documents/application/api/legal-documents-api.js';

const acceptPixOrgaTos = async ({ userId, dependencies = { legalDocumentApi } }) => {
return dependencies.legalDocumentApi.acceptLegalDocumentByUserId({ userId, service: 'pix-orga', type: 'TOS' });
};

const legalDocumentApiRepository = { acceptPixOrgaTos };

export { legalDocumentApiRepository };
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,12 @@ describe('Acceptance | Identity Access Management | Application | Route | User',
});

describe('Success case', function () {
it('returns the user with pixOrgaTermsOfServiceAccepted', async function () {
it('replies with 204 status code', async function () {
// when
const response = await server.inject(options);

// then
expect(response.statusCode).to.equal(200);
expect(response.result.data.attributes['pix-orga-terms-of-service-accepted']).to.be.true;
expect(response.statusCode).to.equal(204);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,13 @@ describe('Unit | Identity Access Management | Application | Controller | User',

it('accepts pix orga terms of service', async function () {
// given
usecases.acceptPixOrgaTermsOfService.withArgs({ userId }).resolves({});
userSerializer.serialize.withArgs({}).returns('ok');
usecases.acceptPixOrgaTermsOfService.withArgs({ userId }).resolves();

// when
const response = await userController.acceptPixOrgaTermsOfService(request, hFake, { userSerializer });
const response = await userController.acceptPixOrgaTermsOfService(request, hFake);

// then
expect(response).to.be.equal('ok');
expect(response.statusCode).to.equal(204);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ import { acceptPixOrgaTermsOfService } from '../../../../../src/identity-access-
import { expect, sinon } from '../../../../test-helper.js';

describe('Unit | Identity Access Management | Domain | UseCase | accept-pix-orga-terms-of-service', function () {
let userRepository;
let legalDocumentApiRepository;

beforeEach(function () {
userRepository = { updatePixOrgaTermsOfServiceAcceptedToTrue: sinon.stub() };
legalDocumentApiRepository = { acceptPixOrgaTos: sinon.stub() };
});

it('accepts terms of service of pix-orga', async function () {
// given
const userId = Symbol('userId');
const updatedUser = Symbol('updateduser');
userRepository.updatePixOrgaTermsOfServiceAcceptedToTrue.resolves(updatedUser);
legalDocumentApiRepository.acceptPixOrgaTos.resolves();

// when
const actualUpdatedUser = await acceptPixOrgaTermsOfService({ userId, userRepository });
await acceptPixOrgaTermsOfService({ userId, legalDocumentApiRepository });

// then
expect(userRepository.updatePixOrgaTermsOfServiceAcceptedToTrue).to.have.been.calledWithExactly(userId);
expect(actualUpdatedUser).to.equal(updatedUser);
expect(legalDocumentApiRepository.acceptPixOrgaTos).to.have.been.calledWithExactly({ userId });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { legalDocumentApiRepository } from '../../../../../src/identity-access-management/infrastructure/repositories/legal-document-api.repository.js';
import { expect, sinon } from '../../../../test-helper.js';

describe('Unit | Identity Access Management | Infrastructure | Repositories | legal-document-api', function () {
describe('#acceptPixOrgaTos', function () {
it('accepts terms of service', async function () {
// given
const dependencies = {
legalDocumentApi: {
acceptLegalDocumentByUserId: sinon.stub().resolves(),
},
};

const userId = Symbol('userId');

// when
await legalDocumentApiRepository.acceptPixOrgaTos({ userId, dependencies });

// then
expect(dependencies.legalDocumentApi.acceptLegalDocumentByUserId).to.have.been.calledWithExactly({
userId,
service: 'pix-orga',
type: 'TOS',
});
});
});
});

0 comments on commit e59f8d1

Please sign in to comment.