Skip to content

Commit

Permalink
feat(api): add legal-document api
Browse files Browse the repository at this point in the history
  • Loading branch information
P-Jeremy committed Dec 9, 2024
1 parent 6647763 commit 561cbdb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
16 changes: 16 additions & 0 deletions api/src/legal-documents/application/api/legal-documents-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { usecases } from '../../domain/usecases/index.js';

/**
* Accept legal document by user id.
*
* @param{string} params.service
* @param{string} params.type
* @param{string} params.userId
*
* @returns {Promise<void>}
*/
const acceptLegalDocumentByUserId = async ({ type, service, userId }) => {
return usecases.acceptLegalDocumentByUserId({ type, service, userId });
};

export { acceptLegalDocumentByUserId };
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as legalDocumentsApi from '../../../../../src/legal-documents/application/api/legal-documents-api.js';
import { LegalDocument } from '../../../../../src/legal-documents/domain/models/LegalDocument.js';
import { databaseBuilder, expect, knex } from '../../../../test-helper.js';

const { TOS } = LegalDocument.TYPES;
const { PIX_ORGA } = LegalDocument.SERVICES;

describe('Integration | Privacy | Application | Api | legal documents', function () {
describe('#acceptLegalDocumentByUserId', function () {
it('accepts the latest legal document version by user id ', async function () {
// given
const userId = databaseBuilder.factory.buildUser().id;
databaseBuilder.factory.buildLegalDocumentVersion({
type: TOS,
service: PIX_ORGA,
versionAt: new Date('2021-01-01'),
});

const latestDocument = databaseBuilder.factory.buildLegalDocumentVersion({
type: TOS,
service: PIX_ORGA,
versionAt: new Date(),
});

await databaseBuilder.commit();

const formerAcceptances = await knex('legal-document-version-user-acceptances').where({ userId });

expect(formerAcceptances.length).to.equal(0);

// when
await legalDocumentsApi.acceptLegalDocumentByUserId({ userId, type: TOS, service: PIX_ORGA });

// then
const userAcceptance = await knex('legal-document-version-user-acceptances')
.where({ userId })
.where('legalDocumentVersionId', latestDocument.id)
.first();

expect(userAcceptance).to.exist;
});
});
});

0 comments on commit 561cbdb

Please sign in to comment.