From ee06efa480baf9e216741a883798eefec2a93bf9 Mon Sep 17 00:00:00 2001 From: Angelo Ashmore Date: Wed, 30 Oct 2024 13:29:03 -1000 Subject: [PATCH] feat: retry invalid/expired refs (#356) * feat: retry invalid/expired refs * fix: remove duplicate ref retry logic and support `getFirst` * test: invalid ref retry * feat: allow up to 3 retries before throwing * feat: use a new master ref once a known-stale ref is used * test: simplify test title * docs: update const description --- src/Client.ts | 81 ++++++++++- test/__testutils__/testInvalidRefRetry.ts | 170 ++++++++++++++++++++++ test/client-get.test.ts | 5 + test/client-getAllByEveryTag.test.ts | 5 + test/client-getAllByIDs.test.ts | 5 + test/client-getAllBySomeTags.test.ts | 5 + test/client-getAllByTag.test.ts | 5 + test/client-getAllByType.test.ts | 5 + test/client-getAllByUIDs.test.ts | 6 + test/client-getByEveryTag.test.ts | 5 + test/client-getByID.test.ts | 5 + test/client-getByIDs.test.ts | 5 + test/client-getBySomeTags.test.ts | 5 + test/client-getByTag.test.ts | 5 + test/client-getByType.test.ts | 5 + test/client-getByUID.test.ts | 5 + test/client-getByUIDs.test.ts | 5 + test/client-getFirst.test.ts | 5 + test/client-getSingle.test.ts | 5 + 19 files changed, 330 insertions(+), 7 deletions(-) create mode 100644 test/__testutils__/testInvalidRefRetry.ts diff --git a/src/Client.ts b/src/Client.ts index 22fcd565..e722384a 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -73,6 +73,13 @@ export const GET_ALL_QUERY_DELAY = 500 */ const DEFUALT_RETRY_AFTER_MS = 1000 +/** + * The maximum number of attemps to retry a query with an invalid ref. We allow + * multiple attempts since each attempt may use a different (and possibly + * invalid) ref. Capping the number of attemps prevents infinite loops. + */ +const MAX_INVALID_REF_RETRY_ATTEMPS = 3 + /** * Extracts one or more Prismic document types that match a given Prismic * document type. If no matches are found, no extraction is performed and the @@ -529,9 +536,9 @@ export class Client< async get( params?: Partial & FetchParams, ): Promise> { - const url = await this.buildQueryURL(params) + const { data } = await this._get(params) - return await this.fetch>(url, params) + return data } /** @@ -546,8 +553,9 @@ export class Client< * * @typeParam TDocument - Type of the Prismic document returned. * - * @param params - Parameters to filter, sort, and paginate results. @returns - * The first result of the query, if any. + * @param params - Parameters to filter, sort, and paginate results. + * + * @returns The first result of the query, if any. */ async getFirst( params?: Partial & FetchParams, @@ -556,10 +564,9 @@ export class Client< if (!(params && params.page) && !params?.pageSize) { actualParams.pageSize = this.defaultParams?.pageSize ?? 1 } - const url = await this.buildQueryURL(actualParams) - const result = await this.fetch>(url, params) + const { data, url } = await this._get(actualParams) - const firstResult = result.results[0] + const firstResult = data.results[0] if (firstResult) { return firstResult @@ -1678,6 +1685,66 @@ export class Client< return findMasterRef(cachedRepository.refs).ref } + /** + * The private implementation of `this.get`. It returns the API response and + * the URL used to make the request. The URL is sometimes used in the public + * method to include in thrown errors. + * + * This method retries requests that throw `RefNotFoundError` or + * `RefExpiredError`. It contains special logic to retry with the latest + * master ref, provided in the API's error message. + * + * @typeParam TDocument - Type of Prismic documents returned. + * + * @param params - Parameters to filter, sort, and paginate results. + * + * @returns An object containing the paginated response containing the result + * of the query and the URL used to make the API request. + */ + private async _get( + params?: Partial & FetchParams, + attemptCount = 0, + ): Promise<{ data: Query; url: string }> { + const url = await this.buildQueryURL(params) + + try { + const data = await this.fetch>(url, params) + + return { data, url } + } catch (error) { + if ( + !( + error instanceof RefNotFoundError || error instanceof RefExpiredError + ) || + attemptCount >= MAX_INVALID_REF_RETRY_ATTEMPS - 1 + ) { + throw error + } + + // If no explicit ref is given (i.e. the master ref from + // /api/v2 is used), clear the cached repository value. + // Clearing the cached value prevents other methods from + // using a known-stale ref. + if (!params?.ref) { + this.cachedRepository = undefined + } + + const masterRef = error.message.match(/Master ref is: (?.*)$/) + ?.groups?.ref + if (!masterRef) { + throw error + } + + const badRef = new URL(url).searchParams.get("ref") + const issue = error instanceof RefNotFoundError ? "invalid" : "expired" + console.warn( + `The ref (${badRef}) was ${issue}. Now retrying with the latest master ref (${masterRef}). If you were previewing content, the response will not include draft content.`, + ) + + return await this._get({ ...params, ref: masterRef }, attemptCount + 1) + } + } + /** * Performs a network request using the configured `fetch` function. It * assumes all successful responses will have a JSON content type. It also diff --git a/test/__testutils__/testInvalidRefRetry.ts b/test/__testutils__/testInvalidRefRetry.ts new file mode 100644 index 00000000..1a53cbe6 --- /dev/null +++ b/test/__testutils__/testInvalidRefRetry.ts @@ -0,0 +1,170 @@ +import { expect, it, vi } from "vitest" + +import { rest } from "msw" + +import { createTestClient } from "./createClient" +import { mockPrismicRestAPIV2 } from "./mockPrismicRestAPIV2" + +import * as prismic from "../../src" + +type TestInvalidRefRetryArgs = { + run: ( + client: prismic.Client, + params?: Parameters[0], + ) => Promise +} + +export const testInvalidRefRetry = (args: TestInvalidRefRetryArgs): void => { + it("retries with the master ref when an invalid ref is used", async (ctx) => { + const client = createTestClient({ ctx }) + const badRef = ctx.mock.api.ref().ref + const masterRef = ctx.mock.api.ref().ref + const queryResponse = ctx.mock.api.query({ + documents: [ctx.mock.value.document()], + }) + + const triedRefs = new Set() + + mockPrismicRestAPIV2({ ctx, queryResponse }) + const endpoint = new URL( + "documents/search", + `${client.documentAPIEndpoint}/`, + ).toString() + ctx.server.use( + rest.get(endpoint, (req) => { + triedRefs.add(req.url.searchParams.get("ref")) + }), + rest.get(endpoint, (_req, res, ctx) => + res.once( + ctx.json({ + type: "api_notfound_error", + message: `Master ref is: ${masterRef}`, + }), + ctx.status(404), + ), + ), + ) + + const consoleWarnSpy = vi + .spyOn(console, "warn") + .mockImplementation(() => void 0) + await args.run(client, { ref: badRef }) + consoleWarnSpy.mockRestore() + + expect([...triedRefs]).toStrictEqual([badRef, masterRef]) + }) + + it("retries with the master ref when an expired ref is used", async (ctx) => { + const client = createTestClient({ ctx }) + const badRef = ctx.mock.api.ref().ref + const masterRef = ctx.mock.api.ref().ref + const queryResponse = ctx.mock.api.query({ + documents: [ctx.mock.value.document()], + }) + + const triedRefs = new Set() + + mockPrismicRestAPIV2({ ctx, queryResponse }) + const endpoint = new URL( + "documents/search", + `${client.documentAPIEndpoint}/`, + ).toString() + ctx.server.use( + rest.get(endpoint, (req) => { + triedRefs.add(req.url.searchParams.get("ref")) + }), + rest.get(endpoint, (_req, res, ctx) => + res.once( + ctx.json({ message: `Master ref is: ${masterRef}` }), + ctx.status(410), + ), + ), + ) + + const consoleWarnSpy = vi + .spyOn(console, "warn") + .mockImplementation(() => void 0) + await args.run(client, { ref: badRef }) + consoleWarnSpy.mockRestore() + + expect([...triedRefs]).toStrictEqual([badRef, masterRef]) + }) + + it("throws if the maximum number of retries with invalid refs is reached", async (ctx) => { + const client = createTestClient({ ctx }) + const queryResponse = ctx.mock.api.query({ + documents: [ctx.mock.value.document()], + }) + + const triedRefs = new Set() + + mockPrismicRestAPIV2({ ctx, queryResponse }) + const endpoint = new URL( + "documents/search", + `${client.documentAPIEndpoint}/`, + ).toString() + ctx.server.use( + rest.get(endpoint, (req) => { + triedRefs.add(req.url.searchParams.get("ref")) + }), + rest.get(endpoint, (_req, res, requestCtx) => + res( + requestCtx.json({ + type: "api_notfound_error", + message: `Master ref is: ${ctx.mock.api.ref().ref}`, + }), + requestCtx.status(404), + ), + ), + ) + + const consoleWarnSpy = vi + .spyOn(console, "warn") + .mockImplementation(() => void 0) + await expect(async () => { + await args.run(client) + }).rejects.toThrow(prismic.RefNotFoundError) + consoleWarnSpy.mockRestore() + + expect(triedRefs.size).toBe(3) + }) + + it("fetches a new master ref on subsequent queries if an invalid ref is used", async (ctx) => { + const client = createTestClient({ ctx }) + const queryResponse = ctx.mock.api.query({ + documents: [ctx.mock.value.document()], + }) + + const triedRefs = new Set() + + mockPrismicRestAPIV2({ ctx, queryResponse }) + const endpoint = new URL( + "documents/search", + `${client.documentAPIEndpoint}/`, + ).toString() + ctx.server.use( + rest.get(endpoint, (req) => { + triedRefs.add(req.url.searchParams.get("ref")) + }), + rest.get(endpoint, (_req, res, requestCtx) => + res.once( + requestCtx.json({ + type: "api_notfound_error", + message: `Master ref is: ${ctx.mock.api.ref().ref}`, + }), + requestCtx.status(404), + ), + ), + ) + + const consoleWarnSpy = vi + .spyOn(console, "warn") + .mockImplementation(() => void 0) + await args.run(client) + consoleWarnSpy.mockRestore() + + await args.run(client) + + expect(triedRefs.size).toBe(3) + }) +} diff --git a/test/client-get.test.ts b/test/client-get.test.ts index 61893155..ecadaa38 100644 --- a/test/client-get.test.ts +++ b/test/client-get.test.ts @@ -7,6 +7,7 @@ import { mockPrismicRestAPIV2 } from "./__testutils__/mockPrismicRestAPIV2" import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetMethod } from "./__testutils__/testAnyGetMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetMethod("resolves a query", { run: (client) => client.get(), @@ -92,6 +93,10 @@ it("uses cached repository metadata within the client's repository cache TTL", a ) }) +testInvalidRefRetry({ + run: (client, params) => client.get(params), +}) + testFetchOptions("supports fetch options", { run: (client, params) => client.get(params), }) diff --git a/test/client-getAllByEveryTag.test.ts b/test/client-getAllByEveryTag.test.ts index ffca2b71..73a45ce2 100644 --- a/test/client-getAllByEveryTag.test.ts +++ b/test/client-getAllByEveryTag.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetAllMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetAllMethod("returns all documents by every tag from paginated response", { run: (client) => client.getAllByEveryTag(["foo", "bar"]), @@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getAllByEveryTag(["foo", "bar"], params), }) +testInvalidRefRetry({ + run: (client, params) => client.getAllByEveryTag(["foo", "bar"], params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getAllByEveryTag(["foo", "bar"], params), }) diff --git a/test/client-getAllByIDs.test.ts b/test/client-getAllByIDs.test.ts index fbe027a3..44fd5e73 100644 --- a/test/client-getAllByIDs.test.ts +++ b/test/client-getAllByIDs.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetAllMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetAllMethod("returns all documents by IDs from paginated response", { run: (client) => client.getAllByIDs(["id1", "id2"]), @@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getAllByIDs(["id1", "id2"], params), }) +testInvalidRefRetry({ + run: (client, params) => client.getAllByIDs(["id1", "id2"], params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getAllByIDs(["id1", "id2"], params), }) diff --git a/test/client-getAllBySomeTags.test.ts b/test/client-getAllBySomeTags.test.ts index 002f92b0..e13ca5cd 100644 --- a/test/client-getAllBySomeTags.test.ts +++ b/test/client-getAllBySomeTags.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetAllMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetAllMethod("returns all documents by some tags from paginated response", { run: (client) => client.getAllBySomeTags(["foo", "bar"]), @@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getAllBySomeTags(["foo", "bar"], params), }) +testInvalidRefRetry({ + run: (client, params) => client.getAllBySomeTags(["foo", "bar"], params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getAllBySomeTags(["foo", "bar"], params), }) diff --git a/test/client-getAllByTag.test.ts b/test/client-getAllByTag.test.ts index d2b81bd4..488afdac 100644 --- a/test/client-getAllByTag.test.ts +++ b/test/client-getAllByTag.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetAllMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetAllMethod("returns all documents by tag from paginated response", { run: (client) => client.getAllByTag("tag"), @@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getAllByTag("tag", params), }) +testInvalidRefRetry({ + run: (client, params) => client.getAllByTag("tag", params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getAllByTag("tag", params), }) diff --git a/test/client-getAllByType.test.ts b/test/client-getAllByType.test.ts index 2af6e770..d1045604 100644 --- a/test/client-getAllByType.test.ts +++ b/test/client-getAllByType.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetAllMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetAllMethod("returns all documents by type from paginated response", { run: (client) => client.getAllByType("type"), @@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getAllByType("type", params), }) +testInvalidRefRetry({ + run: (client, params) => client.getAllByType("type", params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getAllByType("type", params), }) diff --git a/test/client-getAllByUIDs.test.ts b/test/client-getAllByUIDs.test.ts index c1ddb21b..9d6d2b7d 100644 --- a/test/client-getAllByUIDs.test.ts +++ b/test/client-getAllByUIDs.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetAllMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetAllMethod("returns all documents by UIDs from paginated response", { run: (client) => client.getAllByUIDs("type", ["uid1", "uid2"]), @@ -36,6 +37,11 @@ testFetchOptions("supports fetch options", { client.getAllByUIDs("type", ["uid1", "uid2"], params), }) +testInvalidRefRetry({ + run: (client, params) => + client.getAllByUIDs("type", ["uid1", "uid2"], params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getAllByUIDs("type", ["uid1", "uid2"], params), diff --git a/test/client-getByEveryTag.test.ts b/test/client-getByEveryTag.test.ts index fa5b34a5..1ee3a19b 100644 --- a/test/client-getByEveryTag.test.ts +++ b/test/client-getByEveryTag.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetMethod("queries for documents by tag", { run: (client) => client.getByEveryTag(["foo", "bar"]), @@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getByEveryTag(["foo", "bar"], params), }) +testInvalidRefRetry({ + run: (client, params) => client.getByEveryTag(["foo", "bar"], params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getByEveryTag(["foo", "bar"], params), }) diff --git a/test/client-getByID.test.ts b/test/client-getByID.test.ts index 1914dffa..1559a9a3 100644 --- a/test/client-getByID.test.ts +++ b/test/client-getByID.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetFirstMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetFirstMethod("queries for document by ID", { run: (client) => client.getByID("id"), @@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getByID("id", params), }) +testInvalidRefRetry({ + run: (client, params) => client.getByID("id", params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getByID("id", params), }) diff --git a/test/client-getByIDs.test.ts b/test/client-getByIDs.test.ts index 1bbfbad9..b73e21e0 100644 --- a/test/client-getByIDs.test.ts +++ b/test/client-getByIDs.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetMethod("queries for documents by IDs", { run: (client) => client.getByIDs(["id1", "id2"]), @@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getByIDs(["id1", "id2"], params), }) +testInvalidRefRetry({ + run: (client, params) => client.getByIDs(["id1", "id2"], params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getByIDs(["id1", "id2"], params), }) diff --git a/test/client-getBySomeTags.test.ts b/test/client-getBySomeTags.test.ts index b90922be..7adef377 100644 --- a/test/client-getBySomeTags.test.ts +++ b/test/client-getBySomeTags.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetMethod("queries for documents by some tags", { run: (client) => client.getBySomeTags(["foo", "bar"]), @@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getBySomeTags(["foo", "bar"], params), }) +testInvalidRefRetry({ + run: (client, params) => client.getBySomeTags(["foo", "bar"], params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getBySomeTags(["foo", "bar"], params), }) diff --git a/test/client-getByTag.test.ts b/test/client-getByTag.test.ts index fa6d0567..e12d19d4 100644 --- a/test/client-getByTag.test.ts +++ b/test/client-getByTag.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetMethod("queries for documents by tag", { run: (client) => client.getByTag("tag"), @@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getByTag("tag", params), }) +testInvalidRefRetry({ + run: (client, params) => client.getByTag("tag", params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getByTag("tag", params), }) diff --git a/test/client-getByType.test.ts b/test/client-getByType.test.ts index 9ef415b2..42cf032c 100644 --- a/test/client-getByType.test.ts +++ b/test/client-getByType.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetMethod("queries for documents by type", { run: (client) => client.getByType("type"), @@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getByType("type", params), }) +testInvalidRefRetry({ + run: (client, params) => client.getByType("type", params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getByType("type", params), }) diff --git a/test/client-getByUID.test.ts b/test/client-getByUID.test.ts index 27fa358a..4f4a49c8 100644 --- a/test/client-getByUID.test.ts +++ b/test/client-getByUID.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetFirstMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetFirstMethod("queries for document by UID", { run: (client) => client.getByUID("type", "uid"), @@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getByUID("type", "uid", params), }) +testInvalidRefRetry({ + run: (client, params) => client.getByUID("type", "uid", params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getByUID("type", "uid", params), }) diff --git a/test/client-getByUIDs.test.ts b/test/client-getByUIDs.test.ts index 45ac76ac..00f89b69 100644 --- a/test/client-getByUIDs.test.ts +++ b/test/client-getByUIDs.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetMethod("queries for documents by UIDs", { run: (client) => client.getByUIDs("type", ["uid1", "uid2"]), @@ -35,6 +36,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getByUIDs("type", ["uid1", "uid2"], params), }) +testInvalidRefRetry({ + run: (client, params) => client.getByUIDs("type", ["uid1", "uid2"], params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getByUIDs("type", ["uid1", "uid2"], params), }) diff --git a/test/client-getFirst.test.ts b/test/client-getFirst.test.ts index 48634f67..8235233b 100644 --- a/test/client-getFirst.test.ts +++ b/test/client-getFirst.test.ts @@ -8,6 +8,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetFirstMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" import * as prismic from "../src" @@ -98,6 +99,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getFirst(params), }) +testInvalidRefRetry({ + run: (client, params) => client.getFirst(params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getFirst(params), }) diff --git a/test/client-getSingle.test.ts b/test/client-getSingle.test.ts index 8e123578..b1fa3f51 100644 --- a/test/client-getSingle.test.ts +++ b/test/client-getSingle.test.ts @@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod" import { testGetFirstMethod } from "./__testutils__/testAnyGetMethod" import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod" import { testFetchOptions } from "./__testutils__/testFetchOptions" +import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry" testGetFirstMethod("queries for singleton document", { run: (client) => client.getSingle("type"), @@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", { run: (client, params) => client.getSingle("type", params), }) +testInvalidRefRetry({ + run: (client, params) => client.getSingle("type", params), +}) + testAbortableMethod("is abortable with an AbortController", { run: (client, params) => client.getSingle("type", params), })