diff --git a/api/src/certification/enrolment/application/api/candidates-api.js b/api/src/certification/enrolment/application/api/candidates-api.js new file mode 100644 index 00000000000..c5c5dbe850b --- /dev/null +++ b/api/src/certification/enrolment/application/api/candidates-api.js @@ -0,0 +1,17 @@ +import { usecases } from '../../../enrolment/domain/usecases/index.js'; + +/** + * Checks if a user has been candidate to a certification + * + * @function + * @param {Object} params + * @param {number} params.userId user id to search for candidates + * @returns {Promise} + * @throws {TypeError} preconditions failed + */ +export const hasBeenCandidate = async ({ userId }) => { + if (!userId) { + throw new TypeError('user identifier is required'); + } + return usecases.hasBeenCandidate({ userId }); +}; diff --git a/api/tests/certification/enrolment/unit/application/api/candidates-api_test.js b/api/tests/certification/enrolment/unit/application/api/candidates-api_test.js new file mode 100644 index 00000000000..1675d21ae2c --- /dev/null +++ b/api/tests/certification/enrolment/unit/application/api/candidates-api_test.js @@ -0,0 +1,30 @@ +import { hasBeenCandidate } from '../../../../../../src/certification/enrolment/application/api/candidates-api.js'; +import { usecases } from '../../../../../../src/certification/enrolment/domain/usecases/index.js'; +import { catchErr, expect, sinon } from '../../../../../test-helper.js'; + +describe('Unit | Certification | Enrolment | API | candidates-api', function () { + describe('hasBeenCandidate', function () { + it('should check if a user has been candidate', async function () { + // given + sinon.stub(usecases, 'hasBeenCandidate').resolves(); + + // when + await hasBeenCandidate({ userId: 12 }); + + // then + expect(usecases.hasBeenCandidate).to.have.been.calledOnceWithExactly({ userId: 12 }); + }); + + it('should reject calls without a userId', async function () { + // given + sinon.stub(usecases, 'hasBeenCandidate').resolves(); + + // when + const error = await catchErr(() => hasBeenCandidate({ userId: null }))(); + + // then + expect(error).to.be.instanceOf(TypeError); + expect(error.message).to.equals('user identifier is required'); + }); + }); +});