Skip to content

Commit 1485cb4

Browse files
committed
testcases added
1 parent 79dc9e6 commit 1485cb4

File tree

13 files changed

+2193
-158
lines changed

13 files changed

+2193
-158
lines changed

package-lock.json

Lines changed: 1709 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"dev": "DEBUG=ws-nodejs-re:* $(npm bin)/nodemon --exec babel-node -L src/app.js",
1010
"lint": "$(npm bin)/eslint src/ config/ test/",
1111
"start": "node src/app.js",
12-
"test": "NODE_ENV=test PORT=3333 $(npm bin)/mocha --exit --recursive -R spec"
12+
"test": "NODE_ENV=test PORT=3333 $(npm bin)/mocha --require @babel/register --exit $(find test -name '*spec.js')",
13+
"integration-test": "export PORT=3333 NODE_ENV=test && sequelize db:migrate:undo:all && sequelize db:migrate && nyc --require @babel/register mocha ./test/integration/integration.js --timeout 20000 --exit"
1314
},
1415
"author": "Digication",
1516
"license": "PRIVATE",
@@ -27,7 +28,9 @@
2728
"pg-hstore": "^2.3.3",
2829
"request": "^2.88.0",
2930
"request-promise": "^4.2.4",
31+
"rewire": "^4.0.1",
3032
"sequelize": "^5.21.5",
33+
"sinon": "^9.0.0",
3134
"sqlite3": "^4.1.0",
3235
"uuid": "^7.0.1"
3336
},
@@ -41,14 +44,17 @@
4144
"@babel/runtime": "^7.8.4",
4245
"apidoc": "^0.17.7",
4346
"babel-loader": "^8.0.6",
47+
"chai": "^4.2.0",
48+
"chai-http": "^4.3.0",
4449
"eslint": "^6.8.0",
4550
"eslint-config-airbnb-base": "^14.0.0",
4651
"eslint-plugin-import": "^2.20.1",
4752
"eslint-plugin-node": "^10.0.0",
4853
"eslint-plugin-promise": "^4.2.1",
4954
"eslint-plugin-security": "^1.4.0",
50-
"mocha": "^6.2.1",
55+
"mocha": "^6.2.2",
5156
"nodemon": "^1.19.3",
57+
"nyc": "^15.0.0",
5258
"sequelize-fixtures": "^1.1.1"
5359
},
5460
"apidoc": {

src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ app.use(cookieParser());
3636

3737
app.use('/users/', router.default.UserRouter);
3838
app.use('/courses/', router.default.CourseRouter);
39-
app.use('/registration/', router.default.RegistrationRouter);
39+
app.use('/registrations/', router.default.RegistrationRouter);
4040

4141

4242
// catch 404 and forwarded to error handler

src/db/config/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"dialect": "postgres"
88
},
99
"test": {
10-
"username": "postgres",
11-
"password": null,
10+
"username": "tester",
11+
"password": "test",
1212
"database": "roster_management_test",
1313
"host": "127.0.0.1",
1414
"dialect": "postgres"

src/db/models/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ Object.keys(db).forEach((modelName) => {
4141
});
4242

4343
// Associations
44-
db.Registration.hasMany(db.Course);
45-
db.Registration.hasMany(db.User);
44+
// db.Registration.hasMany(db.Course);
45+
// db.Registration.hasMany(db.User);
4646

47-
db.User.belongsTo(db.Registration);
48-
db.Course.belongsTo(db.Registration);
47+
// db.User.belongsTo(db.Registration);
48+
// db.Course.belongsTo(db.Registration);
4949

5050
db.sequelize = sequelize;
5151
db.Sequelize = Sequelize;

src/db/models/user.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ module.exports = (sequelize, DataTypes) => {
2020
}, {
2121
tableName: 'users',
2222
timestamps: false,
23+
freezeTableName: true,
2324
});
25+
2426
User.beforeCreate((user) => { user.id = uuid(); }); // eslint-disable-line no-param-reassign
2527
return User;
2628
};

src/server/controllers/registration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class RegistrationController {
2525
}
2626

2727
static async addRegistration(req, res) {
28-
if (!req.body.registration_id || !req.body.user_id) {
28+
if (!req.body.course_id || !req.body.user_id) {
2929
util.setError(statusCode.BAD_REQUEST, 'Please provide complete details');
3030
return util.send(res);
3131
}

src/server/services/registration.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import database from '../../db/models';
33
class registrationService {
44
static async getAllRegistrations(queryParams) {
55
const filerObject = {};
6-
if (queryParams.registration_id) {
7-
filerObject.registration_id = queryParams.registration_id;
6+
if (queryParams.course_id) {
7+
filerObject.course_id = queryParams.course_id;
88
}
99
if (queryParams.user_id) {
10-
filerObject.registration_id = queryParams.user_id;
10+
filerObject.user_id = queryParams.user_id;
1111
}
1212
return database.Registration.findAll({ where: filerObject });
1313
}

src/server/utils/Utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default class Util {
3232
case status.OK:
3333
return res.status(this.statusCode).json(this.data);
3434
case status.CREATED:
35-
return res.status(this.statusCode).end();
35+
return res.status(this.statusCode).json(this.data);
3636
case status.SUCCESS_NO_CONTENT:
3737
return res.status(this.statusCode).end();
3838
case status.BAD_REQUEST:

0 commit comments

Comments
 (0)