From 8d56ea55a058c67f5975e9195aad3785518840e2 Mon Sep 17 00:00:00 2001 From: Ayobami Akingbade Date: Wed, 20 Sep 2023 09:41:24 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20test(errors):=20fix=20unauthoriz?= =?UTF-8?q?ed=20error=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/api/account/mine.spec.ts | 6 +++--- src/__tests__/api/integrations/constants/[key].spec.ts | 4 ++-- src/__tests__/api/integrations/credentials/[key].spec.ts | 4 ++-- src/__tests__/api/integrations/env/[key].spec.ts | 4 ++-- src/backend/lib/errors/error-handler.spec.ts | 1 + .../validations/implementations/__tests__/can-user.spec.ts | 4 ++-- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/__tests__/api/account/mine.spec.ts b/src/__tests__/api/account/mine.spec.ts index ace517d14..7631fb025 100644 --- a/src/__tests__/api/account/mine.spec.ts +++ b/src/__tests__/api/account/mine.spec.ts @@ -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, } `); }); diff --git a/src/__tests__/api/integrations/constants/[key].spec.ts b/src/__tests__/api/integrations/constants/[key].spec.ts index 626bf60fd..5c8fd0ff0 100644 --- a/src/__tests__/api/integrations/constants/[key].spec.ts +++ b/src/__tests__/api/integrations/constants/[key].spec.ts @@ -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: { @@ -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([ diff --git a/src/__tests__/api/integrations/credentials/[key].spec.ts b/src/__tests__/api/integrations/credentials/[key].spec.ts index 381ab0f7a..64a0ae2f3 100644 --- a/src/__tests__/api/integrations/credentials/[key].spec.ts +++ b/src/__tests__/api/integrations/credentials/[key].spec.ts @@ -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", @@ -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([ diff --git a/src/__tests__/api/integrations/env/[key].spec.ts b/src/__tests__/api/integrations/env/[key].spec.ts index de8f65274..87441bf8b 100644 --- a/src/__tests__/api/integrations/env/[key].spec.ts +++ b/src/__tests__/api/integrations/env/[key].spec.ts @@ -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: { @@ -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([ diff --git a/src/backend/lib/errors/error-handler.spec.ts b/src/backend/lib/errors/error-handler.spec.ts index 859e49090..55ae3d18d 100644 --- a/src/backend/lib/errors/error-handler.spec.ts +++ b/src/backend/lib/errors/error-handler.spec.ts @@ -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", diff --git a/src/backend/lib/request/validations/implementations/__tests__/can-user.spec.ts b/src/backend/lib/request/validations/implementations/__tests__/can-user.spec.ts index 8fdc17ca3..59b3c2dcb 100644 --- a/src/backend/lib/request/validations/implementations/__tests__/can-user.spec.ts +++ b/src/backend/lib/request/validations/implementations/__tests__/can-user.spec.ts @@ -41,7 +41,7 @@ describe("Request Validations => canUserValidationImpl", () => { await handler(req, res); - expect(res._getStatusCode()).toBe(401); + expect(res._getStatusCode()).toBe(403); expect(res._getJSONData()).toMatchInlineSnapshot(` { "errorCode": "", @@ -49,7 +49,7 @@ describe("Request Validations => canUserValidationImpl", () => { "method": "GET", "name": "ForbiddenError", "path": "", - "statusCode": 401, + "statusCode": 403, } `); });