Skip to content

Commit 119eed2

Browse files
fixed comments and tests
1 parent a186cda commit 119eed2

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

test/unit/middlewares/impersonationRequests.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe("Impersonation Request Validators", function () {
3131
reason: "Testing purpose",
3232
};
3333

34-
const updateRequestBody: UpdateImpersonationRequestStatusBody = {
34+
const updateRequestBody: UpdateImpersonationRequestStatusBody = {
3535
status: "APPROVED",
3636
message: "Testing",
3737
};
@@ -212,16 +212,14 @@ describe("Impersonation Request Validators", function () {
212212
expect(nextSpy.called).to.be.false;
213213
});
214214

215-
it("should invalidate if status field is not of correct type", async function () {
215+
it("should invalidate if status field is not of correct type", async function () {
216216
req = {
217217
body: { ...updateRequestBody, status: "ACTIVE" },
218218
};
219-
await updateImpersonationRequestValidator(
220-
req as UpdateImpersonationRequest,
221-
res as ImpersonationRequestResponse,
222-
nextSpy
223-
);
219+
await updateImpersonationRequestValidator(req as UpdateImpersonationRequest,res as ImpersonationRequestResponse, nextSpy);
220+
const errorMessageArg = res.boom.badRequest.firstCall.args[0];
224221
expect(res.boom.badRequest.calledOnce).to.be.true;
222+
expect(errorMessageArg).to.include("status must be APPROVED or REJECTED");
225223
expect(nextSpy.called).to.be.false;
226224
});
227225
});

test/unit/models/impersonationRequests.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { REQUEST_STATE, ERROR_WHILE_CREATING_REQUEST, ERROR_WHILE_UPDATING_REQUE
66
import addUser from "../../utils/addUser";
77
import userDataFixture from "../../fixtures/user/user";
88
import sinon from "sinon";
9-
import { UpdateImpersonationRequestStatusBody } from "../../../types/impersonationRequest";
9+
import { UpdateImpersonationRequestStatusBody, UpdateImpersonationRequestDataResponse } from "../../../types/impersonationRequest";
1010
import { Timestamp } from "firebase-admin/firestore";
1111
import firestore from "../../../utils/firestore";
12+
1213
const userData = userDataFixture();
1314
const logger = require("../../../utils/logger");
1415

@@ -232,7 +233,7 @@ describe("models/impersonationRequests", () => {
232233
expect(updatedRequest.status).to.equal(REQUEST_STATE.REJECTED);
233234
});
234235

235-
it("should change the startedAt, endedAt and isImpersonationFinished fields on update", async () => {
236+
it("should change the startedAt,endedAt and isImpersonationFinished fields on update", async () => {
236237
const updatedBody = {
237238
isImpersonationFinished: true,
238239
startedAt: Timestamp.fromDate(new Date(Date.now())),
@@ -242,16 +243,15 @@ describe("models/impersonationRequests", () => {
242243
id: impersonationRequest.id,
243244
updatePayload: updatedBody,
244245
lastModifiedBy: impersonationRequest.userId,
245-
});
246-
const result = await impersonationModel.getImpersonationRequestById(impersonationRequest.id);
247-
expect(result.isImpersonationFinished).to.be.true;
248-
expect(Number(result.startedAt)).to.be.greaterThan(0);
249-
expect(Number(result.endedAt)).to.be.greaterThan(Number(result.startedAt));
246+
}) as UpdateImpersonationRequestDataResponse;
247+
expect(updatedRequest.isImpersonationFinished).to.be.true;
248+
expect(Number(updatedRequest.startedAt)).to.be.greaterThan(0);
249+
expect(Number(updatedRequest.endedAt)).to.be.greaterThan(Number(updatedRequest.startedAt));
250250
});
251251

252252
it("should change updatedAt timestamp on update", async () => {
253253
const before = Number(impersonationRequest.updatedAt);
254-
const updated = await impersonationModel.updateImpersonationRequest({
254+
const updatedRequest = await impersonationModel.updateImpersonationRequesT({
255255
id: impersonationRequest.id,
256256
updatePayload: { status: "APPROVED" },
257257
lastModifiedBy: impersonationRequest.impersonatedUserId,
@@ -265,7 +265,6 @@ describe("models/impersonationRequests", () => {
265265
const error = new Error(ERROR_WHILE_UPDATING_REQUEST);
266266
const loggerStub = sinon.stub(logger, "error");
267267

268-
// Stub Firestore collection and doc chain
269268
const docUpdateStub = sinon.stub().rejects(error);
270269
const docStub = sinon.stub().returns({ update: docUpdateStub });
271270
const collectionStub = sinon.stub().returns({ doc: docStub });

test/unit/services/impersonationRequests.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ describe("Tests Impersonation Requests Service", () => {
261261
await impersonationService.updateImpersonationRequestService(body);
262262
expect.fail("Should throw error");
263263
} catch (err) {
264-
expect(loggerStub.calledWith(ERROR_WHILE_UPDATING_REQUEST, err)).to.true;
264+
expect(loggerStub.calledWith(ERROR_WHILE_UPDATING_REQUEST, err)).to.be.true;
265265
}
266266
});
267267
});

0 commit comments

Comments
 (0)