Skip to content

Commit

Permalink
feat(api): add public API checking if a user has been candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
bpetetot committed Nov 14, 2024
1 parent 8a20902 commit 7b84015
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
17 changes: 17 additions & 0 deletions api/src/certification/enrolment/application/api/candidates-api.js
Original file line number Diff line number Diff line change
@@ -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<boolean>}
* @throws {TypeError} preconditions failed
*/
export const hasBeenCandidate = async ({ userId }) => {
if (!userId) {
throw new TypeError('user identifier is required');
}
return usecases.hasBeenCandidate({ userId });
};
Original file line number Diff line number Diff line change
@@ -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');
});
});
});

0 comments on commit 7b84015

Please sign in to comment.