Skip to content

Commit

Permalink
moved getter functionality into new quals util
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonopono123 committed Sep 5, 2024
1 parent 3e02084 commit 0d3c643
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
12 changes: 2 additions & 10 deletions backend/server/models/workerAvailableQualifications.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* jshint indent: 2 */
const { formatQualificationTitle } = require('../utils/qualificationsUtils');

module.exports = function(sequelize, DataTypes) {
const WorkerQualifications = sequelize.define('workerAvailableQualifications', {
Expand Down Expand Up @@ -27,16 +28,7 @@ module.exports = function(sequelize, DataTypes) {
const titleValue = this.getDataValue('title');
const levelValue = this.getDataValue('level');

if (levelValue) {
if (titleValue.endsWith(')')) {
const sub = titleValue.substring(0, titleValue.length - 1);
return `${sub}, level ${levelValue})`;
} else {
return `${titleValue} (level ${levelValue})`;
}
}

return titleValue;
return formatQualificationTitle(titleValue, levelValue);
}
},
level: {
Expand Down
28 changes: 28 additions & 0 deletions backend/server/test/unit/utils/qualificationsUtils.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const expect = require('chai').expect;

const { formatQualificationTitle } = require('../../../utils/qualificationsUtils');
const { registrationWithUser, convertedRegistrationResponse } = require('../mockdata/registration');

describe('qualificationsUtils', () => {
describe('formatQualificationTitle', () => {
it('should return the title unchanged when no level is provided', () => {
const title = 'This is a qual';
const level = null;

const returnedValue = formatQualificationTitle(title, level);

expect(returnedValue).to.deep.equal(title);
});

describe('level is provided', () => {
it('should return the title with the level in brackets', () => {
const title = 'This is a qual';
const level = '4';

const returnedValue = formatQualificationTitle(title, level);

expect(returnedValue).to.deep.equal('This is a qual (level 4)');
});
})
});
});
13 changes: 13 additions & 0 deletions backend/server/utils/qualificationsUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


module.exports.formatQualificationTitle = (title, level) => {
if (level) {
if (title.endsWith(')')) {
const sub = title.substring(0, title.length - 1);
return `${sub}, level ${level})`;
} else {
return `${title} (level ${level})`;
}
}
return title;
}

0 comments on commit 0d3c643

Please sign in to comment.