Skip to content

Commit

Permalink
✨ api: modifying chars for invigilatorPassword
Browse files Browse the repository at this point in the history
Co-authored-by: Steph0 <Steph0@users.noreply.github.com>
  • Loading branch information
AndreiaPena and Steph0 authored Sep 26, 2024
1 parent b3448b4 commit 52a78ef
Showing 4 changed files with 28 additions and 20 deletions.
14 changes: 4 additions & 10 deletions api/src/certification/enrolment/domain/models/SessionEnrolment.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import _ from 'lodash';

import { config } from '../../../../shared/config.js';
import { CERTIFICATION_CENTER_TYPES } from '../../../../shared/domain/constants.js';
import { SESSION_STATUSES } from '../../../shared/domain/constants.js';
import { CERTIFICATION_VERSIONS } from '../../../shared/domain/models/CertificationVersion.js';

const availableCharactersForPasswordGeneration =
`${config.availableCharacterForCode.numbers}${config.availableCharacterForCode.letters}`.split('');
const NB_CHAR = 5;
const INVIGILATOR_PASSWORD_LENGTH = 6;
const INVIGILATOR_PASSWORD_CHARS = '23456789bcdfghjkmpqrstvwxyBCDFGHJKMPQRSTVWXY!*?'.split('');

class SessionEnrolment {
constructor({
@@ -54,8 +52,8 @@ class SessionEnrolment {
return this.certificationCenterType === CERTIFICATION_CENTER_TYPES.SCO;
}

static generateInvigilatorPassword() {
return _.times(NB_CHAR, _randomCharacter).join('');
#generateInvigilatorPassword() {
return _.sampleSize(INVIGILATOR_PASSWORD_CHARS, INVIGILATOR_PASSWORD_LENGTH).join('');
}

isSessionScheduledInThePast() {
@@ -112,7 +110,3 @@ function findMatchingCandidates({
}

export { SessionEnrolment };

function _randomCharacter() {
return _.sample(availableCharactersForPasswordGeneration);
}
Original file line number Diff line number Diff line change
@@ -113,14 +113,28 @@ describe('Unit | Certification | Enrolment | Domain | Models | SessionEnrolment'
});
});

context('static #generateInvigilatorPassword', function () {
it('should return a supervisor password containing 6 characters', async function () {
context('#generateInvigilatorPassword', function () {
it('should return a invigilator password containing 6 characters', async function () {
// given
// when
const supervisorPassword = SessionEnrolment.generateSupervisorPassword();
const sessionEnrolment = new SessionEnrolment();

// then
expect(supervisorPassword).to.match(/^[2346789BCDFGHJKMPQRTVWXY]{5}$/);
expect(sessionEnrolment.invigilatorPassword).to.have.lengthOf(6);
});

it('should return a invigilator password containing only allowed characters', async function () {
// given
// when
const randomPasswords = _.times(100, () => {
const aSession = new SessionEnrolment();
return aSession.invigilatorPassword;
});

// then
randomPasswords.forEach((password) => {
expect(password).to.match(/^[bcdfghjkmpqrstvwxyBCDFGHJKMPQRSTVWXY2-9!*?]+$/);
});
});
});

Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ describe('Unit | UseCase | create-session', function () {
certificationCenterId,
certificationCenter: certificationCenterName,
accessCode,
supervisorPassword: sinon.match(/^[2346789BCDFGHJKMPQRTVWXY]{5}$/),
invigilatorPassword: sinon.match.string,
version: 2,
createdBy: userId,
certificationCandidates: [],
@@ -113,7 +113,7 @@ describe('Unit | UseCase | create-session', function () {
certificationCenterId,
certificationCenter: certificationCenterName,
accessCode,
supervisorPassword: sinon.match(/^[2346789BCDFGHJKMPQRTVWXY]{5}$/),
invigilatorPassword: sinon.match.string,
version: 3,
createdBy: userId,
certificationCandidates: [],
Original file line number Diff line number Diff line change
@@ -205,13 +205,13 @@ describe('Unit | UseCase | sessions-mass-import | validate-sessions', function (
...expectedSession1,
certificationCandidates: [candidate1],
createdBy: undefined,
supervisorPassword: sinon.match(/^[2346789BCDFGHJKMPQRTVWXY]{5}$/),
invigilatorPassword: sinon.match.string,
}),
sinon.match({
...expectedSession2,
certificationCandidates: [candidate2],
createdBy: undefined,
supervisorPassword: sinon.match(/^[2346789BCDFGHJKMPQRTVWXY]{5}$/),
invigilatorPassword: sinon.match.string,
}),
],
userId,
@@ -331,13 +331,13 @@ describe('Unit | UseCase | sessions-mass-import | validate-sessions', function (
...expectedSession1,
certificationCandidates: [candidate1],
createdBy: undefined,
supervisorPassword: sinon.match(/^[2346789BCDFGHJKMPQRTVWXY]{5}$/),
invigilatorPassword: sinon.match.string,
}),
sinon.match({
...expectedSession2,
certificationCandidates: [candidate2, candidate3],
createdBy: undefined,
supervisorPassword: sinon.match(/^[2346789BCDFGHJKMPQRTVWXY]{5}$/),
invigilatorPassword: sinon.match.string,
}),
],
userId,

0 comments on commit 52a78ef

Please sign in to comment.