Skip to content

Commit 561cbdb

Browse files
committed
feat(api): add legal-document api
1 parent 6647763 commit 561cbdb

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { usecases } from '../../domain/usecases/index.js';
2+
3+
/**
4+
* Accept legal document by user id.
5+
*
6+
* @param{string} params.service
7+
* @param{string} params.type
8+
* @param{string} params.userId
9+
*
10+
* @returns {Promise<void>}
11+
*/
12+
const acceptLegalDocumentByUserId = async ({ type, service, userId }) => {
13+
return usecases.acceptLegalDocumentByUserId({ type, service, userId });
14+
};
15+
16+
export { acceptLegalDocumentByUserId };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as legalDocumentsApi from '../../../../../src/legal-documents/application/api/legal-documents-api.js';
2+
import { LegalDocument } from '../../../../../src/legal-documents/domain/models/LegalDocument.js';
3+
import { databaseBuilder, expect, knex } from '../../../../test-helper.js';
4+
5+
const { TOS } = LegalDocument.TYPES;
6+
const { PIX_ORGA } = LegalDocument.SERVICES;
7+
8+
describe('Integration | Privacy | Application | Api | legal documents', function () {
9+
describe('#acceptLegalDocumentByUserId', function () {
10+
it('accepts the latest legal document version by user id ', async function () {
11+
// given
12+
const userId = databaseBuilder.factory.buildUser().id;
13+
databaseBuilder.factory.buildLegalDocumentVersion({
14+
type: TOS,
15+
service: PIX_ORGA,
16+
versionAt: new Date('2021-01-01'),
17+
});
18+
19+
const latestDocument = databaseBuilder.factory.buildLegalDocumentVersion({
20+
type: TOS,
21+
service: PIX_ORGA,
22+
versionAt: new Date(),
23+
});
24+
25+
await databaseBuilder.commit();
26+
27+
const formerAcceptances = await knex('legal-document-version-user-acceptances').where({ userId });
28+
29+
expect(formerAcceptances.length).to.equal(0);
30+
31+
// when
32+
await legalDocumentsApi.acceptLegalDocumentByUserId({ userId, type: TOS, service: PIX_ORGA });
33+
34+
// then
35+
const userAcceptance = await knex('legal-document-version-user-acceptances')
36+
.where({ userId })
37+
.where('legalDocumentVersionId', latestDocument.id)
38+
.first();
39+
40+
expect(userAcceptance).to.exist;
41+
});
42+
});
43+
});

0 commit comments

Comments
 (0)