Skip to content

Commit 23933db

Browse files
used constants for 403 error
1 parent 0da0d41 commit 23933db

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

controllers/impersonationRequests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export const impersonationController = async (
199199
req: ImpersonationSessionRequest,
200200
res: ImpersonationRequestResponse,
201201
next: NextFunction
202-
): Promise<ImpersonationRequestResponse> => {
202+
): Promise<ImpersonationRequestResponse | void> => {
203203
const { action } = req.query;
204204
const requestId = req.params.id;
205205
const userId = req.userData?.id;
@@ -226,6 +226,6 @@ export const impersonationController = async (
226226
});
227227
} catch (error) {
228228
logger.error(`Failed to process impersonation ${action} for requestId=${requestId}, userId=${userId}`, error);
229-
next(error);
229+
return next(error);
230230
}
231231
};

services/impersonationRequests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const updateImpersonationRequestService = async (
104104
}
105105

106106
if (request.impersonatedUserId !== body.lastModifiedBy || request.status !== REQUEST_STATE.PENDING) {
107-
throw new Forbidden("You are not allowed for this Operation at the moment");
107+
throw new Forbidden(OPERATION_NOT_ALLOWED);
108108
}
109109

110110
const updatedRequest = await updateImpersonationRequest(body) as UpdateImpersonationStatusModelResponse;

test/integration/impersonationRequests.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
REQUEST_DOES_NOT_EXIST,
2020
REQUEST_REJECTED_SUCCESSFULLY,
2121
REQUEST_STATE,
22-
UNAUTHORIZED_TO_UPDATE_REQUEST
22+
UNAUTHORIZED_TO_UPDATE_REQUEST,
23+
OPERATION_NOT_ALLOWED
2324
} from "../../constants/requests";
2425
import { impersonationRequestsBodyData } from "../fixtures/impersonation-requests/impersonationRequests";
2526

@@ -238,7 +239,7 @@ describe("Impersonation Requests", () => {
238239
if (err) return done(err);
239240
expect(res).to.have.status(403);
240241
expect(res.body.error).to.equal("Forbidden");
241-
expect(res.body.message).to.equal("You are not allowed for this Operation at the moment");
242+
expect(res.body.message).to.equal(OPERATION_NOT_ALLOWED);
242243
done();
243244
});
244245
});
@@ -253,7 +254,7 @@ describe("Impersonation Requests", () => {
253254
if (err) return done(err);
254255
expect(res).to.have.status(403);
255256
expect(res.body.error).to.equal("Forbidden");
256-
expect(res.body.message).to.equal("You are not allowed for this Operation at the moment");
257+
expect(res.body.message).to.equal(OPERATION_NOT_ALLOWED);
257258
done();
258259
});
259260
});
@@ -736,7 +737,7 @@ describe("Impersonation Requests", () => {
736737
if (err) return done(err);
737738
expect(res).to.have.status(403);
738739
expect(res.body.error).to.equal("Forbidden");
739-
expect(res.body.message).to.equal("You are not allowed for this Operation at the moment");
740+
expect(res.body.message).to.equal(OPERATION_NOT_ALLOWED);
740741
done();
741742
});
742743
});
@@ -751,7 +752,7 @@ describe("Impersonation Requests", () => {
751752
if (err) return done(err);
752753
expect(res).to.have.status(403);
753754
expect(res.body.error).to.equal("Forbidden");
754-
expect(res.body.message).to.equal("You are not allowed for this Operation at the moment");
755+
expect(res.body.message).to.equal(OPERATION_NOT_ALLOWED);
755756
done();
756757
});
757758
});
@@ -766,7 +767,7 @@ describe("Impersonation Requests", () => {
766767
if (err) return done(err);
767768
expect(res).to.have.status(403);
768769
expect(res.body.error).to.equal("Forbidden");
769-
expect(res.body.message).to.equal("You are not allowed for this Operation at the moment");
770+
expect(res.body.message).to.equal(OPERATION_NOT_ALLOWED);
770771
done();
771772
});
772773
});

test/unit/services/impersonationRequests.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
REQUEST_REJECTED_SUCCESSFULLY,
1010
REQUEST_STATE,
1111
TASK_REQUEST_MESSAGES,
12-
ERROR_WHILE_UPDATING_REQUEST
12+
ERROR_WHILE_UPDATING_REQUEST,
13+
OPERATION_NOT_ALLOWED
1314
} from "../../../constants/requests";
1415
import userDataFixture from "../../fixtures/user/user";
1516
import cleanDb from "../../utils/cleanDb";
@@ -144,7 +145,7 @@ describe("Tests Impersonation Requests Service", () => {
144145
} catch (err) {
145146
expect(err).to.not.be.undefined;
146147
expect(err.name).to.equal("ForbiddenError");
147-
expect(err.message).to.equal("You are not allowed for this Operation at the moment");
148+
expect(err.message).to.equal(OPERATION_NOT_ALLOWED);
148149
}
149150
});
150151

@@ -167,7 +168,7 @@ describe("Tests Impersonation Requests Service", () => {
167168
} catch (err) {
168169
expect(err).to.not.be.undefined;
169170
expect(err.name).to.equal("ForbiddenError");
170-
expect(err.message).to.equal("You are not allowed for this Operation at the moment");
171+
expect(err.message).to.equal(OPERATION_NOT_ALLOWED);
171172
}
172173
});
173174

@@ -201,7 +202,7 @@ describe("Tests Impersonation Requests Service", () => {
201202
} catch (err) {
202203
expect(err).to.not.be.undefined;
203204
expect(err.name).to.equal("ForbiddenError");
204-
expect(err.message).to.equal("You are not allowed for this Operation at the moment");
205+
expect(err.message).to.equal(OPERATION_NOT_ALLOWED);
205206
}
206207
});
207208

0 commit comments

Comments
 (0)