Skip to content

Commit

Permalink
feat: qualifications
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeen committed Dec 2, 2021
1 parent bdf5c49 commit 5542ea6
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 14 deletions.
24 changes: 16 additions & 8 deletions src/controllers/qualification.controller.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import {Project, Qualification, QualificationMock} from "../models/index.js";

export const create = (req, res) => {
res.json({
message: 'Not Yet Implemented',
});
};
export const findAll = (req, res) => {
res.json({
message: 'Not Yet Implemented',
});
export const findAll = async (req, res) => {
if (req.query.useMock) {
res.json(QualificationMock.findAll());
return;
}

res.json(await Qualification.findAll());
};
export const findOne = (req, res) => {
res.json({
message: 'Not Yet Implemented',
});
export const findOne = async (req, res) => {
if (req.query.useMock) {
res.json(QualificationMock.findOne(req.query.id));
return;
}

res.json(await Qualification.findByPk(req.query.id));
};
export const update = (req, res) => {
res.json({
Expand Down
26 changes: 21 additions & 5 deletions src/models/qualifications/qualifications.model.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
'use strict';
import Sequelize from 'sequelize';
const { DataTypes, Model } = Sequelize;
import { sequelize } from '../database';

class Qualification {
static list(page = 0, limit = 10) {
return stub;
}
}
class Qualification extends Model { }

Qualification.init({
id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV1,
primaryKey: true,
},
project_id: DataTypes.STRING,
qualification_type: DataTypes.STRING,
label: DataTypes.STRING,
crediting_start_date: DataTypes.STRING,
crediting_end_date: DataTypes.STRING,
validity_start_date: DataTypes.STRING,
validity_end_date: DataTypes.STRING,
unit_quality: DataTypes.STRING,
qualification_link: DataTypes.STRING,
}, { sequelize, modelName: 'qualification' });

export { Qualification };
63 changes: 62 additions & 1 deletion src/models/qualifications/qualifications.stub.json
Original file line number Diff line number Diff line change
@@ -1 +1,62 @@
[]
[
{
"id": "1",
"project_id": 1,
"qualification_type": "basic type",
"label": "qualification 1",
"crediting_start_date": "2011-10-05T14:48:00.000Z",
"crediting_end_date": "2022-10-05T14:48:00.000Z",
"validity_start_date": "2011-11-05T14:41:00.000Z",
"validity_end_date": "2022-11-05T14:41:00.000Z",
"unit_quality": "good",
"qualification_link": "https://qualification.link/1"
},
{
"id": "2",
"project_id": 1,
"qualification_type": "basic type",
"label": "qualification 2",
"crediting_start_date": "2001-10-05T14:48:00.000Z",
"crediting_end_date": "2002-10-05T14:48:00.000Z",
"validity_start_date": "2001-11-05T14:41:00.000Z",
"validity_end_date": "2002-11-05T14:41:00.000Z",
"unit_quality": "average",
"qualification_link": "https://qualification.link/2"
},
{
"id": "3",
"project_id": 1,
"qualification_type": "advanced type",
"label": "qualification 3",
"crediting_start_date": "2005-10-05T14:48:00.000Z",
"crediting_end_date": "2007-10-05T14:48:00.000Z",
"validity_start_date": "2005-11-05T14:41:00.000Z",
"validity_end_date": "2007-11-05T14:41:00.000Z",
"unit_quality": "average",
"qualification_link": "https://qualification.link/3"
},
{
"id": "4",
"project_id": 1,
"qualification_type": "advanced type",
"label": "qualification 4",
"crediting_start_date": "2015-10-05T14:48:00.000Z",
"crediting_end_date": "2017-10-05T14:48:00.000Z",
"validity_start_date": "2015-11-05T14:41:00.000Z",
"validity_end_date": "2017-11-05T14:41:00.000Z",
"unit_quality": "average",
"qualification_link": "https://qualification.link/4"
},
{
"id": "5",
"project_id": 1,
"qualification_type": "special type",
"label": "qualification 5",
"crediting_start_date": "2035-10-05T14:48:00.000Z",
"crediting_end_date": "2037-10-05T14:48:00.000Z",
"validity_start_date": "2035-11-05T14:41:00.000Z",
"validity_end_date": "2037-11-05T14:41:00.000Z",
"unit_quality": "fair",
"qualification_link": "https://qualification.link/5"
}
]
33 changes: 33 additions & 0 deletions tests/routes/qualifications.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {QualificationMock} from "../../src/models/index.js";
import chai from 'chai';
import chaiHttp from 'chai-http';
import app from '../../src/server.js';

// Configure chai
chai.use(chaiHttp);
chai.should();

describe("Qualifications Routes", () => {
describe("GET /v1/qualifications/", () => {
it("should get all qualifications", (done) => {
chai.request(app)
.get('/v1/qualifications/?useMock=true')
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.a('array');
done();
});
});
});
describe("GET /v1/qualifications/?id=1", () => {
it("should get a single qualification", (done) => {
chai.request(app)
.get('/v1/qualifications/?useMock=true&id=1')
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.a('object');
done();
});
});
});
});

0 comments on commit 5542ea6

Please sign in to comment.