From 455671ec839b3c0201fa609bb0b182d9bd421468 Mon Sep 17 00:00:00 2001 From: Angelo Ashmore Date: Thu, 19 Oct 2023 17:00:53 -1000 Subject: [PATCH] test: fix unauthenticated tests --- packages/manager/src/index.ts | 11 +++++++++++ ...rismicAuthManager-getAuthenticationCookies.test.ts | 4 ++-- .../PrismicAuthManager-getAuthenticationToken.test.ts | 4 ++-- .../test/PrismicAuthManager-getProfile.test.ts | 4 ++-- ...smicAuthManager-refreshAuthenticationToken.test.ts | 4 ++-- ...Manager-customTypes-fetchRemoteCustomTypes.test.ts | 4 ++-- ...eMachineManager-customTypes-pushCustomType.test.ts | 4 ++-- ...iceMachineManager-prismicRepository-create.test.ts | 4 ++-- ...iceMachineManager-prismicRepository-delete.test.ts | 4 ++-- ...ineManager-prismicRepository-pushDocuments.test.ts | 4 ++-- ...ceMachineManager-prismicRepository-readAll.test.ts | 4 ++-- ...iceMachineManager-slices-fetchRemoteSlices.test.ts | 4 ++-- ...chineManager-user-getAuthenticationCookies.test.ts | 4 ++-- ...MachineManager-user-getAuthenticationToken.test.ts | 4 ++-- .../test/SliceMachineManager-user-getProfile.test.ts | 4 ++-- ...ineManager-user-refreshAuthenticationToken.test.ts | 4 ++-- 16 files changed, 41 insertions(+), 30 deletions(-) diff --git a/packages/manager/src/index.ts b/packages/manager/src/index.ts index fbaa6e37cb..b30b36597a 100644 --- a/packages/manager/src/index.ts +++ b/packages/manager/src/index.ts @@ -25,6 +25,17 @@ export type { PrismicAuthCheckStatusResponse, } from "./auth/createPrismicAuthManagerMiddleware"; +export { + SliceMachineError, + UnauthorizedError, + UnauthenticatedError, + NotFoundError, + UnexpectedDataError, + InternalError, + PluginError, + PluginHookResultError, +} from "./errors"; + export { DecodeError } from "./lib/DecodeError"; export type { SliceMachineConfig, PackageManager } from "./types"; diff --git a/packages/manager/test/PrismicAuthManager-getAuthenticationCookies.test.ts b/packages/manager/test/PrismicAuthManager-getAuthenticationCookies.test.ts index c90646229f..77c710d01a 100644 --- a/packages/manager/test/PrismicAuthManager-getAuthenticationCookies.test.ts +++ b/packages/manager/test/PrismicAuthManager-getAuthenticationCookies.test.ts @@ -3,7 +3,7 @@ import { expect, it } from "vitest"; import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createPrismicAuthManager } from "../src"; +import { createPrismicAuthManager, UnauthenticatedError } from "../src"; it("returns parsed cookies from the auth state file", async (ctx) => { const prismicAuthManager = createPrismicAuthManager(); @@ -32,5 +32,5 @@ it("throws if the user is not logged in", async () => { expect(async () => { await prismicAuthManager.getAuthenticationCookies(); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); }); diff --git a/packages/manager/test/PrismicAuthManager-getAuthenticationToken.test.ts b/packages/manager/test/PrismicAuthManager-getAuthenticationToken.test.ts index 91ac17d1a9..aa1e315bb6 100644 --- a/packages/manager/test/PrismicAuthManager-getAuthenticationToken.test.ts +++ b/packages/manager/test/PrismicAuthManager-getAuthenticationToken.test.ts @@ -3,7 +3,7 @@ import { expect, it } from "vitest"; import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createPrismicAuthManager } from "../src"; +import { createPrismicAuthManager, UnauthenticatedError } from "../src"; it("returns the user's Prismic authentication token", async (ctx) => { const prismicAuthManager = createPrismicAuthManager(); @@ -28,5 +28,5 @@ it("throws if the user is not logged in", async () => { expect(async () => { await prismicAuthManager.getAuthenticationToken(); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); }); diff --git a/packages/manager/test/PrismicAuthManager-getProfile.test.ts b/packages/manager/test/PrismicAuthManager-getProfile.test.ts index 35426c5642..2513a0e1b6 100644 --- a/packages/manager/test/PrismicAuthManager-getProfile.test.ts +++ b/packages/manager/test/PrismicAuthManager-getProfile.test.ts @@ -4,7 +4,7 @@ import { createPrismicAuthLoginResponse } from "./__testutils__/createPrismicAut import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createPrismicAuthManager } from "../src"; +import { createPrismicAuthManager, UnauthenticatedError } from "../src"; it("returns the profile for the user", async (ctx) => { const prismicAuthManager = createPrismicAuthManager(); @@ -26,5 +26,5 @@ it("throws if the user is not logged in", async () => { expect(async () => { await prismicAuthManager.getAuthenticationToken(); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); }); diff --git a/packages/manager/test/PrismicAuthManager-refreshAuthenticationToken.test.ts b/packages/manager/test/PrismicAuthManager-refreshAuthenticationToken.test.ts index 56607ea5ea..e8e660e52d 100644 --- a/packages/manager/test/PrismicAuthManager-refreshAuthenticationToken.test.ts +++ b/packages/manager/test/PrismicAuthManager-refreshAuthenticationToken.test.ts @@ -4,7 +4,7 @@ import { createPrismicAuthLoginResponse } from "./__testutils__/createPrismicAut import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createPrismicAuthManager } from "../src"; +import { createPrismicAuthManager, UnauthenticatedError } from "../src"; it("refreshes the auth token in the auth state file", async (ctx) => { const prismicAuthManager = createPrismicAuthManager(); @@ -49,5 +49,5 @@ it("throws if the user is not logged in", async () => { expect(async () => { await prismicAuthManager.getAuthenticationToken(); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); }); diff --git a/packages/manager/test/SliceMachineManager-customTypes-fetchRemoteCustomTypes.test.ts b/packages/manager/test/SliceMachineManager-customTypes-fetchRemoteCustomTypes.test.ts index a4db238b83..a984da7de8 100644 --- a/packages/manager/test/SliceMachineManager-customTypes-fetchRemoteCustomTypes.test.ts +++ b/packages/manager/test/SliceMachineManager-customTypes-fetchRemoteCustomTypes.test.ts @@ -6,7 +6,7 @@ import { mockCustomTypesAPI } from "./__testutils__/mockCustomTypesAPI"; import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createSliceMachineManager } from "../src"; +import { createSliceMachineManager, UnauthenticatedError } from "../src"; it("fetches Custom Types from the Custom Types API", async (ctx) => { const adapter = createTestPlugin(); @@ -56,5 +56,5 @@ it("throws if the user is not logged in", async () => { await expect(async () => { await manager.customTypes.fetchRemoteCustomTypes(); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); }); diff --git a/packages/manager/test/SliceMachineManager-customTypes-pushCustomType.test.ts b/packages/manager/test/SliceMachineManager-customTypes-pushCustomType.test.ts index af9e019cef..4dfd8ea266 100644 --- a/packages/manager/test/SliceMachineManager-customTypes-pushCustomType.test.ts +++ b/packages/manager/test/SliceMachineManager-customTypes-pushCustomType.test.ts @@ -7,7 +7,7 @@ import { mockCustomTypesAPI } from "./__testutils__/mockCustomTypesAPI"; import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createSliceMachineManager } from "../src"; +import { createSliceMachineManager, UnauthenticatedError } from "../src"; it("pushes a Custom Type using the Custom Types API", async (ctx) => { const model = ctx.mockPrismic.model.customType(); @@ -110,5 +110,5 @@ it("throws if not logged in", async () => { await expect(async () => { await manager.customTypes.pushCustomType({ id: "id" }); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); }); diff --git a/packages/manager/test/SliceMachineManager-prismicRepository-create.test.ts b/packages/manager/test/SliceMachineManager-prismicRepository-create.test.ts index ce5dfb138d..f62c7cbaa4 100644 --- a/packages/manager/test/SliceMachineManager-prismicRepository-create.test.ts +++ b/packages/manager/test/SliceMachineManager-prismicRepository-create.test.ts @@ -7,7 +7,7 @@ import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicRepositoryAPI } from "./__testutils__/mockPrismicRepositoryAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createSliceMachineManager } from "../src"; +import { createSliceMachineManager, UnauthenticatedError } from "../src"; // TODO: This test times out. It seems like a bug in MSW or node-fetch. // `create()` times out when it tries to read the network response's text via @@ -104,5 +104,5 @@ it("throws if not logged in", async () => { domain: "foo", framework: "other", }); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); }); diff --git a/packages/manager/test/SliceMachineManager-prismicRepository-delete.test.ts b/packages/manager/test/SliceMachineManager-prismicRepository-delete.test.ts index 22aa030b03..337db89fef 100644 --- a/packages/manager/test/SliceMachineManager-prismicRepository-delete.test.ts +++ b/packages/manager/test/SliceMachineManager-prismicRepository-delete.test.ts @@ -7,7 +7,7 @@ import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicRepositoryAPI } from "./__testutils__/mockPrismicRepositoryAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createSliceMachineManager } from "../src"; +import { createSliceMachineManager, UnauthenticatedError } from "../src"; // TODO: This test is unfinished. Is this method necessary? It doesn't seem to // be used anywhere. @@ -102,5 +102,5 @@ it("throws if not logged in", async () => { domain: "foo", password: "bar", }); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); }); diff --git a/packages/manager/test/SliceMachineManager-prismicRepository-pushDocuments.test.ts b/packages/manager/test/SliceMachineManager-prismicRepository-pushDocuments.test.ts index d03d722e3a..3142205f9c 100644 --- a/packages/manager/test/SliceMachineManager-prismicRepository-pushDocuments.test.ts +++ b/packages/manager/test/SliceMachineManager-prismicRepository-pushDocuments.test.ts @@ -7,7 +7,7 @@ import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicRepositoryAPI } from "./__testutils__/mockPrismicRepositoryAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createSliceMachineManager } from "../src"; +import { createSliceMachineManager, UnauthenticatedError } from "../src"; // TODO: The endpoint is called more than once. Why? it.skip("pushes a given set of documents to a given repository", async (ctx) => { @@ -153,5 +153,5 @@ it("throws if not logged in", async () => { domain: "foo", framework: "other", }); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); }); diff --git a/packages/manager/test/SliceMachineManager-prismicRepository-readAll.test.ts b/packages/manager/test/SliceMachineManager-prismicRepository-readAll.test.ts index 5c25d43f3e..e356749b43 100644 --- a/packages/manager/test/SliceMachineManager-prismicRepository-readAll.test.ts +++ b/packages/manager/test/SliceMachineManager-prismicRepository-readAll.test.ts @@ -6,7 +6,7 @@ import { createTestProject } from "./__testutils__/createTestProject"; import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createSliceMachineManager } from "../src"; +import { createSliceMachineManager, UnauthenticatedError } from "../src"; it("returns all repositories for the logged in user", async (ctx) => { const adapter = createTestPlugin(); @@ -88,5 +88,5 @@ it("throws if not logged in", async () => { await expect(async () => { await manager.prismicRepository.readAll(); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); }); diff --git a/packages/manager/test/SliceMachineManager-slices-fetchRemoteSlices.test.ts b/packages/manager/test/SliceMachineManager-slices-fetchRemoteSlices.test.ts index d38d8199c2..05438d2934 100644 --- a/packages/manager/test/SliceMachineManager-slices-fetchRemoteSlices.test.ts +++ b/packages/manager/test/SliceMachineManager-slices-fetchRemoteSlices.test.ts @@ -6,7 +6,7 @@ import { mockCustomTypesAPI } from "./__testutils__/mockCustomTypesAPI"; import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createSliceMachineManager } from "../src"; +import { createSliceMachineManager, UnauthenticatedError } from "../src"; it("fetches Slices from the Custom Types API", async (ctx) => { const adapter = createTestPlugin(); @@ -56,5 +56,5 @@ it("throws if the user is not logged in", async () => { await expect(async () => { await manager.slices.fetchRemoteSlices(); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); }); diff --git a/packages/manager/test/SliceMachineManager-user-getAuthenticationCookies.test.ts b/packages/manager/test/SliceMachineManager-user-getAuthenticationCookies.test.ts index 8133730b2e..f47e9a7d43 100644 --- a/packages/manager/test/SliceMachineManager-user-getAuthenticationCookies.test.ts +++ b/packages/manager/test/SliceMachineManager-user-getAuthenticationCookies.test.ts @@ -5,7 +5,7 @@ import { createTestProject } from "./__testutils__/createTestProject"; import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createSliceMachineManager } from "../src"; +import { createSliceMachineManager, UnauthenticatedError } from "../src"; it("returns parsed cookies from the auth state file", async (ctx) => { const adapter = createTestPlugin(); @@ -43,5 +43,5 @@ it("throws if the user is not logged in", async () => { expect(async () => { await manager.user.getAuthenticationCookies(); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); }); diff --git a/packages/manager/test/SliceMachineManager-user-getAuthenticationToken.test.ts b/packages/manager/test/SliceMachineManager-user-getAuthenticationToken.test.ts index 7cbae7f3f0..935c7cb377 100644 --- a/packages/manager/test/SliceMachineManager-user-getAuthenticationToken.test.ts +++ b/packages/manager/test/SliceMachineManager-user-getAuthenticationToken.test.ts @@ -5,7 +5,7 @@ import { createTestProject } from "./__testutils__/createTestProject"; import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createSliceMachineManager } from "../src"; +import { createSliceMachineManager, UnauthenticatedError } from "../src"; it("returns the user's Prismic authentication token", async (ctx) => { const adapter = createTestPlugin(); @@ -40,5 +40,5 @@ it("throws if the user is not logged in", async () => { expect(async () => { await manager.user.getAuthenticationToken(); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); }); diff --git a/packages/manager/test/SliceMachineManager-user-getProfile.test.ts b/packages/manager/test/SliceMachineManager-user-getProfile.test.ts index 8d5820fdcc..a37bb9a554 100644 --- a/packages/manager/test/SliceMachineManager-user-getProfile.test.ts +++ b/packages/manager/test/SliceMachineManager-user-getProfile.test.ts @@ -6,7 +6,7 @@ import { createTestProject } from "./__testutils__/createTestProject"; import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createSliceMachineManager } from "../src"; +import { createSliceMachineManager, UnauthenticatedError } from "../src"; it("returns the profile for the user", async (ctx) => { const adapter = createTestPlugin(); @@ -38,5 +38,5 @@ it("throws if the user is not logged in", async () => { expect(async () => { await manager.user.getAuthenticationToken(); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); }); diff --git a/packages/manager/test/SliceMachineManager-user-refreshAuthenticationToken.test.ts b/packages/manager/test/SliceMachineManager-user-refreshAuthenticationToken.test.ts index a7d53f57da..004e79b88f 100644 --- a/packages/manager/test/SliceMachineManager-user-refreshAuthenticationToken.test.ts +++ b/packages/manager/test/SliceMachineManager-user-refreshAuthenticationToken.test.ts @@ -6,7 +6,7 @@ import { createTestProject } from "./__testutils__/createTestProject"; import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; -import { createSliceMachineManager } from "../src"; +import { createSliceMachineManager, UnauthenticatedError } from "../src"; it("refreshes the auth token in the auth state file", async (ctx) => { const adapter = createTestPlugin(); @@ -66,5 +66,5 @@ it("throws if the user is not logged in", async () => { expect(async () => { await manager.user.getAuthenticationToken(); - }).rejects.toThrow(/not logged in/i); + }).rejects.toThrow(UnauthenticatedError); });