tinfo-web-server / test /facultyValidation.test.js
Faridaqurr
initial backend
e8c33fa
Raw
History Blame Contribute Delete
1.92 kB
const test = require('node:test');
const assert = require('node:assert/strict');
const {
getSingleAssignmentPositionKey,
getSingleAssignmentPositionLabel,
getSingleAssignmentPositionRegex,
} = require('../validation/facultyValidation');
test('single-assignment position key supports canonical and legacy spellings', () => {
assert.equal(getSingleAssignmentPositionKey('Head of Department'), 'head-of-department');
assert.equal(getSingleAssignmentPositionKey('Head of the Department'), 'head-of-department');
assert.equal(getSingleAssignmentPositionKey('Secretary'), 'secretary');
assert.equal(getSingleAssignmentPositionKey('Head of Laboratory'), 'head-of-laboratory');
assert.equal(getSingleAssignmentPositionKey('Head of the Laboratory'), 'head-of-laboratory');
});
test('single-assignment position label returns canonical role labels', () => {
assert.equal(getSingleAssignmentPositionLabel('head of department'), 'Head of the Department');
assert.equal(getSingleAssignmentPositionLabel('SECRETARY'), 'Secretary');
assert.equal(getSingleAssignmentPositionLabel('head of laboratory'), 'Head of the Laboratory');
assert.equal(getSingleAssignmentPositionLabel('Lecturer'), '');
});
test('single-assignment position regex matches aliases and skips other roles', () => {
const departmentRegex = getSingleAssignmentPositionRegex('head of department');
assert.ok(departmentRegex instanceof RegExp);
assert.equal(departmentRegex.test('Head of Department'), true);
assert.equal(departmentRegex.test('Head of the Department'), true);
const secretaryRegex = getSingleAssignmentPositionRegex('secretary');
assert.ok(secretaryRegex instanceof RegExp);
assert.equal(secretaryRegex.test('Secretary'), true);
assert.equal(secretaryRegex.test('Senior Secretary'), false);
const nonRestrictedRegex = getSingleAssignmentPositionRegex('Lecturer');
assert.equal(nonRestrictedRegex, null);
});