Skip to content

Commit

Permalink
🧪 test(errors): fix unauthorized error tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Sep 20, 2023
1 parent 279b0c4 commit 8d56ea5
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/__tests__/api/account/mine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ describe("/api/account/mine", () => {

await handler(req, res);

expect(res._getStatusCode()).toBe(403);
expect(res._getStatusCode()).toBe(401);

expect(res._getJSONData()).toMatchInlineSnapshot(`
{
"errorCode": "NOT_AUTHENTICATED",
"message": "role-doesn't-exist not found for 'roles'",
"method": "GET",
"name": "ForbiddenError",
"name": "UnauthorizedError",
"path": "",
"statusCode": 403,
"statusCode": 401,
}
`);
});
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/api/integrations/constants/[key].spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe("/api/integrations/constants/[key]", () => {
});

describe("permission", () => {
it("should return 401 when user has no permission", async () => {
it("should return 403 when user has no permission", async () => {
const { req, res } = createAuthenticatedViewerMocks({
method: "PUT",
query: {
Expand All @@ -241,7 +241,7 @@ describe("/api/integrations/constants/[key]", () => {

await handler(req, res);

expect(res._getStatusCode()).toBe(401);
expect(res._getStatusCode()).toBe(403);
});
it("should work when user has correct permission", async () => {
await setupRolesTestData([
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/api/integrations/credentials/[key].spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ describe("/api/integrations/credentials/[key]", () => {
});

describe("permission", () => {
it("should return 401 when user has incorrect permission", async () => {
it("should return 403 when user has incorrect permission", async () => {
await setupRolesTestData([
{
id: "custom-role",
Expand All @@ -315,7 +315,7 @@ describe("/api/integrations/credentials/[key]", () => {

await handler(req, res);

expect(res._getStatusCode()).toBe(401);
expect(res._getStatusCode()).toBe(403);
});
it("should work when user has correct permission", async () => {
await Promise.all([
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/api/integrations/env/[key].spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe("/api/integrations/env/[key]", () => {
});

describe("permission", () => {
it("should return 401 when user has no permission", async () => {
it("should return 403 when user has no permission", async () => {
const { req, res } = createAuthenticatedViewerMocks({
method: "PUT",
query: {
Expand All @@ -241,7 +241,7 @@ describe("/api/integrations/env/[key]", () => {

await handler(req, res);

expect(res._getStatusCode()).toBe(401);
expect(res._getStatusCode()).toBe(403);
});
it("should work when user has correct permission", async () => {
await setupRolesTestData([
Expand Down
1 change: 1 addition & 0 deletions src/backend/lib/errors/error-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ describe("/api/error/handling", () => {
expect(res._getStatusCode()).toBe(401);
expect(res._getJSONData()).toMatchInlineSnapshot(`
{
"errorCode": "",
"message": "Invalid Login",
"method": "GET",
"name": "UnauthorizedError",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ describe("Request Validations => canUserValidationImpl", () => {

await handler(req, res);

expect(res._getStatusCode()).toBe(401);
expect(res._getStatusCode()).toBe(403);
expect(res._getJSONData()).toMatchInlineSnapshot(`
{
"errorCode": "",
"message": "Your account doesn't have enough priviledge to perform this action: (Can Manage Dashboard)",
"method": "GET",
"name": "ForbiddenError",
"path": "",
"statusCode": 401,
"statusCode": 403,
}
`);
});
Expand Down

0 comments on commit 8d56ea5

Please sign in to comment.