Skip to content

Commit edf5109

Browse files
write test for updating numberOfHours
1 parent 7ca7e38 commit edf5109

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

controllers/userStatus.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ const updateUserStatus = async (req, res) => {
103103
try {
104104
const userId = getUserIdBasedOnRoute(req);
105105
if (userId) {
106-
const result = await getJoinData(userId);
107-
const dataToUpdate = { ...req.body, monthlyHours: { committed: 4 * result[0].intro.numberOfHours } };
106+
const joinData = await getJoinData(userId);
107+
const dataToUpdate = { ...req.body, monthlyHours: { committed: 4 * joinData[0].intro.numberOfHours } };
108108
const updateStatus = await userStatusModel.updateUserStatus(userId, dataToUpdate);
109109
const { userStatusExists, id, data } = updateStatus;
110110
const responseObject = { id, userId, data: null, message: "" };

test/fixtures/user/join.js

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

test/integration/userStatus.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const {
1616
oooStatusDataForShortDuration,
1717
generateUserStatusData,
1818
} = require("../fixtures/userStatus/userStatus");
19+
const { addJoinData } = require("../../models/users");
20+
const joinData = require("../fixtures/user/join");
1921

2022
const config = require("config");
2123
const { updateUserStatus } = require("../../models/userStatus");
@@ -34,6 +36,7 @@ describe("UserStatus", function () {
3436
jwt = authService.generateAuthToken({ userId });
3537
superUserId = await addUser(superUser);
3638
superUserAuthToken = authService.generateAuthToken({ userId: superUserId });
39+
await addJoinData(joinData(userId)[0]);
3740
await updateUserStatus(userId, userStatusDataForNewUser);
3841
});
3942

@@ -129,6 +132,7 @@ describe("UserStatus", function () {
129132
toFake: ["Date"],
130133
});
131134
testUserId = await addUser(userData[1]);
135+
await addJoinData(joinData(testUserId)[0]);
132136
testUserJwt = authService.generateAuthToken({ userId: testUserId });
133137
});
134138

@@ -277,6 +281,7 @@ describe("UserStatus", function () {
277281
toFake: ["Date"],
278282
});
279283
testUserId = await addUser(userData[1]);
284+
await addJoinData(joinData(testUserId)[0]);
280285
testUserJwt = authService.generateAuthToken({ userId: testUserId });
281286
});
282287

@@ -398,7 +403,7 @@ describe("UserStatus", function () {
398403
expect(res).to.have.status(400);
399404
expect(res.body).to.be.an("object");
400405
expect(res.body.error).to.equal(`Bad Request`);
401-
expect(res.body.message).to.equal(`Invalid State. State must be either IDLE, ACTIVE , OOO, or ONBOARDING`);
406+
expect(res.body.message).to.equal(`Invalid State. State must be either IDLE, ACTIVE, OOO, or ONBOARDING`);
402407
return done();
403408
});
404409
});

0 commit comments

Comments
 (0)