Skip to content

Commit ee06efa

Browse files
authoredOct 30, 2024··
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
1 parent 9da8fdf commit ee06efa

19 files changed

+330
-7
lines changed
 

‎src/Client.ts

+74-7
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ export const GET_ALL_QUERY_DELAY = 500
7373
*/
7474
const DEFUALT_RETRY_AFTER_MS = 1000
7575

76+
/**
77+
* The maximum number of attemps to retry a query with an invalid ref. We allow
78+
* multiple attempts since each attempt may use a different (and possibly
79+
* invalid) ref. Capping the number of attemps prevents infinite loops.
80+
*/
81+
const MAX_INVALID_REF_RETRY_ATTEMPS = 3
82+
7683
/**
7784
* Extracts one or more Prismic document types that match a given Prismic
7885
* document type. If no matches are found, no extraction is performed and the
@@ -529,9 +536,9 @@ export class Client<
529536
async get<TDocument extends TDocuments>(
530537
params?: Partial<BuildQueryURLArgs> & FetchParams,
531538
): Promise<Query<TDocument>> {
532-
const url = await this.buildQueryURL(params)
539+
const { data } = await this._get<TDocument>(params)
533540

534-
return await this.fetch<Query<TDocument>>(url, params)
541+
return data
535542
}
536543

537544
/**
@@ -546,8 +553,9 @@ export class Client<
546553
*
547554
* @typeParam TDocument - Type of the Prismic document returned.
548555
*
549-
* @param params - Parameters to filter, sort, and paginate results. @returns
550-
* The first result of the query, if any.
556+
* @param params - Parameters to filter, sort, and paginate results.
557+
*
558+
* @returns The first result of the query, if any.
551559
*/
552560
async getFirst<TDocument extends TDocuments>(
553561
params?: Partial<BuildQueryURLArgs> & FetchParams,
@@ -556,10 +564,9 @@ export class Client<
556564
if (!(params && params.page) && !params?.pageSize) {
557565
actualParams.pageSize = this.defaultParams?.pageSize ?? 1
558566
}
559-
const url = await this.buildQueryURL(actualParams)
560-
const result = await this.fetch<Query<TDocument>>(url, params)
567+
const { data, url } = await this._get<TDocument>(actualParams)
561568

562-
const firstResult = result.results[0]
569+
const firstResult = data.results[0]
563570

564571
if (firstResult) {
565572
return firstResult
@@ -1678,6 +1685,66 @@ export class Client<
16781685
return findMasterRef(cachedRepository.refs).ref
16791686
}
16801687

1688+
/**
1689+
* The private implementation of `this.get`. It returns the API response and
1690+
* the URL used to make the request. The URL is sometimes used in the public
1691+
* method to include in thrown errors.
1692+
*
1693+
* This method retries requests that throw `RefNotFoundError` or
1694+
* `RefExpiredError`. It contains special logic to retry with the latest
1695+
* master ref, provided in the API's error message.
1696+
*
1697+
* @typeParam TDocument - Type of Prismic documents returned.
1698+
*
1699+
* @param params - Parameters to filter, sort, and paginate results.
1700+
*
1701+
* @returns An object containing the paginated response containing the result
1702+
* of the query and the URL used to make the API request.
1703+
*/
1704+
private async _get<TDocument extends TDocuments>(
1705+
params?: Partial<BuildQueryURLArgs> & FetchParams,
1706+
attemptCount = 0,
1707+
): Promise<{ data: Query<TDocument>; url: string }> {
1708+
const url = await this.buildQueryURL(params)
1709+
1710+
try {
1711+
const data = await this.fetch<Query<TDocument>>(url, params)
1712+
1713+
return { data, url }
1714+
} catch (error) {
1715+
if (
1716+
!(
1717+
error instanceof RefNotFoundError || error instanceof RefExpiredError
1718+
) ||
1719+
attemptCount >= MAX_INVALID_REF_RETRY_ATTEMPS - 1
1720+
) {
1721+
throw error
1722+
}
1723+
1724+
// If no explicit ref is given (i.e. the master ref from
1725+
// /api/v2 is used), clear the cached repository value.
1726+
// Clearing the cached value prevents other methods from
1727+
// using a known-stale ref.
1728+
if (!params?.ref) {
1729+
this.cachedRepository = undefined
1730+
}
1731+
1732+
const masterRef = error.message.match(/Master ref is: (?<ref>.*)$/)
1733+
?.groups?.ref
1734+
if (!masterRef) {
1735+
throw error
1736+
}
1737+
1738+
const badRef = new URL(url).searchParams.get("ref")
1739+
const issue = error instanceof RefNotFoundError ? "invalid" : "expired"
1740+
console.warn(
1741+
`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.`,
1742+
)
1743+
1744+
return await this._get({ ...params, ref: masterRef }, attemptCount + 1)
1745+
}
1746+
}
1747+
16811748
/**
16821749
* Performs a network request using the configured `fetch` function. It
16831750
* assumes all successful responses will have a JSON content type. It also
+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import { expect, it, vi } from "vitest"
2+
3+
import { rest } from "msw"
4+
5+
import { createTestClient } from "./createClient"
6+
import { mockPrismicRestAPIV2 } from "./mockPrismicRestAPIV2"
7+
8+
import * as prismic from "../../src"
9+
10+
type TestInvalidRefRetryArgs = {
11+
run: (
12+
client: prismic.Client,
13+
params?: Parameters<prismic.Client["get"]>[0],
14+
) => Promise<unknown>
15+
}
16+
17+
export const testInvalidRefRetry = (args: TestInvalidRefRetryArgs): void => {
18+
it("retries with the master ref when an invalid ref is used", async (ctx) => {
19+
const client = createTestClient({ ctx })
20+
const badRef = ctx.mock.api.ref().ref
21+
const masterRef = ctx.mock.api.ref().ref
22+
const queryResponse = ctx.mock.api.query({
23+
documents: [ctx.mock.value.document()],
24+
})
25+
26+
const triedRefs = new Set<string | null>()
27+
28+
mockPrismicRestAPIV2({ ctx, queryResponse })
29+
const endpoint = new URL(
30+
"documents/search",
31+
`${client.documentAPIEndpoint}/`,
32+
).toString()
33+
ctx.server.use(
34+
rest.get(endpoint, (req) => {
35+
triedRefs.add(req.url.searchParams.get("ref"))
36+
}),
37+
rest.get(endpoint, (_req, res, ctx) =>
38+
res.once(
39+
ctx.json({
40+
type: "api_notfound_error",
41+
message: `Master ref is: ${masterRef}`,
42+
}),
43+
ctx.status(404),
44+
),
45+
),
46+
)
47+
48+
const consoleWarnSpy = vi
49+
.spyOn(console, "warn")
50+
.mockImplementation(() => void 0)
51+
await args.run(client, { ref: badRef })
52+
consoleWarnSpy.mockRestore()
53+
54+
expect([...triedRefs]).toStrictEqual([badRef, masterRef])
55+
})
56+
57+
it("retries with the master ref when an expired ref is used", async (ctx) => {
58+
const client = createTestClient({ ctx })
59+
const badRef = ctx.mock.api.ref().ref
60+
const masterRef = ctx.mock.api.ref().ref
61+
const queryResponse = ctx.mock.api.query({
62+
documents: [ctx.mock.value.document()],
63+
})
64+
65+
const triedRefs = new Set<string | null>()
66+
67+
mockPrismicRestAPIV2({ ctx, queryResponse })
68+
const endpoint = new URL(
69+
"documents/search",
70+
`${client.documentAPIEndpoint}/`,
71+
).toString()
72+
ctx.server.use(
73+
rest.get(endpoint, (req) => {
74+
triedRefs.add(req.url.searchParams.get("ref"))
75+
}),
76+
rest.get(endpoint, (_req, res, ctx) =>
77+
res.once(
78+
ctx.json({ message: `Master ref is: ${masterRef}` }),
79+
ctx.status(410),
80+
),
81+
),
82+
)
83+
84+
const consoleWarnSpy = vi
85+
.spyOn(console, "warn")
86+
.mockImplementation(() => void 0)
87+
await args.run(client, { ref: badRef })
88+
consoleWarnSpy.mockRestore()
89+
90+
expect([...triedRefs]).toStrictEqual([badRef, masterRef])
91+
})
92+
93+
it("throws if the maximum number of retries with invalid refs is reached", async (ctx) => {
94+
const client = createTestClient({ ctx })
95+
const queryResponse = ctx.mock.api.query({
96+
documents: [ctx.mock.value.document()],
97+
})
98+
99+
const triedRefs = new Set<string | null>()
100+
101+
mockPrismicRestAPIV2({ ctx, queryResponse })
102+
const endpoint = new URL(
103+
"documents/search",
104+
`${client.documentAPIEndpoint}/`,
105+
).toString()
106+
ctx.server.use(
107+
rest.get(endpoint, (req) => {
108+
triedRefs.add(req.url.searchParams.get("ref"))
109+
}),
110+
rest.get(endpoint, (_req, res, requestCtx) =>
111+
res(
112+
requestCtx.json({
113+
type: "api_notfound_error",
114+
message: `Master ref is: ${ctx.mock.api.ref().ref}`,
115+
}),
116+
requestCtx.status(404),
117+
),
118+
),
119+
)
120+
121+
const consoleWarnSpy = vi
122+
.spyOn(console, "warn")
123+
.mockImplementation(() => void 0)
124+
await expect(async () => {
125+
await args.run(client)
126+
}).rejects.toThrow(prismic.RefNotFoundError)
127+
consoleWarnSpy.mockRestore()
128+
129+
expect(triedRefs.size).toBe(3)
130+
})
131+
132+
it("fetches a new master ref on subsequent queries if an invalid ref is used", async (ctx) => {
133+
const client = createTestClient({ ctx })
134+
const queryResponse = ctx.mock.api.query({
135+
documents: [ctx.mock.value.document()],
136+
})
137+
138+
const triedRefs = new Set<string | null>()
139+
140+
mockPrismicRestAPIV2({ ctx, queryResponse })
141+
const endpoint = new URL(
142+
"documents/search",
143+
`${client.documentAPIEndpoint}/`,
144+
).toString()
145+
ctx.server.use(
146+
rest.get(endpoint, (req) => {
147+
triedRefs.add(req.url.searchParams.get("ref"))
148+
}),
149+
rest.get(endpoint, (_req, res, requestCtx) =>
150+
res.once(
151+
requestCtx.json({
152+
type: "api_notfound_error",
153+
message: `Master ref is: ${ctx.mock.api.ref().ref}`,
154+
}),
155+
requestCtx.status(404),
156+
),
157+
),
158+
)
159+
160+
const consoleWarnSpy = vi
161+
.spyOn(console, "warn")
162+
.mockImplementation(() => void 0)
163+
await args.run(client)
164+
consoleWarnSpy.mockRestore()
165+
166+
await args.run(client)
167+
168+
expect(triedRefs.size).toBe(3)
169+
})
170+
}

‎test/client-get.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { mockPrismicRestAPIV2 } from "./__testutils__/mockPrismicRestAPIV2"
77
import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
88
import { testGetMethod } from "./__testutils__/testAnyGetMethod"
99
import { testFetchOptions } from "./__testutils__/testFetchOptions"
10+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
1011

1112
testGetMethod("resolves a query", {
1213
run: (client) => client.get(),
@@ -92,6 +93,10 @@ it("uses cached repository metadata within the client's repository cache TTL", a
9293
)
9394
})
9495

96+
testInvalidRefRetry({
97+
run: (client, params) => client.get(params),
98+
})
99+
95100
testFetchOptions("supports fetch options", {
96101
run: (client, params) => client.get(params),
97102
})

‎test/client-getAllByEveryTag.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetAllMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetAllMethod("returns all documents by every tag from paginated response", {
78
run: (client) => client.getAllByEveryTag(["foo", "bar"]),
@@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", {
2930
run: (client, params) => client.getAllByEveryTag(["foo", "bar"], params),
3031
})
3132

33+
testInvalidRefRetry({
34+
run: (client, params) => client.getAllByEveryTag(["foo", "bar"], params),
35+
})
36+
3237
testAbortableMethod("is abortable with an AbortController", {
3338
run: (client, params) => client.getAllByEveryTag(["foo", "bar"], params),
3439
})

‎test/client-getAllByIDs.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetAllMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetAllMethod("returns all documents by IDs from paginated response", {
78
run: (client) => client.getAllByIDs(["id1", "id2"]),
@@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", {
2930
run: (client, params) => client.getAllByIDs(["id1", "id2"], params),
3031
})
3132

33+
testInvalidRefRetry({
34+
run: (client, params) => client.getAllByIDs(["id1", "id2"], params),
35+
})
36+
3237
testAbortableMethod("is abortable with an AbortController", {
3338
run: (client, params) => client.getAllByIDs(["id1", "id2"], params),
3439
})

‎test/client-getAllBySomeTags.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetAllMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetAllMethod("returns all documents by some tags from paginated response", {
78
run: (client) => client.getAllBySomeTags(["foo", "bar"]),
@@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", {
2930
run: (client, params) => client.getAllBySomeTags(["foo", "bar"], params),
3031
})
3132

33+
testInvalidRefRetry({
34+
run: (client, params) => client.getAllBySomeTags(["foo", "bar"], params),
35+
})
36+
3237
testAbortableMethod("is abortable with an AbortController", {
3338
run: (client, params) => client.getAllBySomeTags(["foo", "bar"], params),
3439
})

‎test/client-getAllByTag.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetAllMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetAllMethod("returns all documents by tag from paginated response", {
78
run: (client) => client.getAllByTag("tag"),
@@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", {
2930
run: (client, params) => client.getAllByTag("tag", params),
3031
})
3132

33+
testInvalidRefRetry({
34+
run: (client, params) => client.getAllByTag("tag", params),
35+
})
36+
3237
testAbortableMethod("is abortable with an AbortController", {
3338
run: (client, params) => client.getAllByTag("tag", params),
3439
})

‎test/client-getAllByType.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetAllMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetAllMethod("returns all documents by type from paginated response", {
78
run: (client) => client.getAllByType("type"),
@@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", {
2930
run: (client, params) => client.getAllByType("type", params),
3031
})
3132

33+
testInvalidRefRetry({
34+
run: (client, params) => client.getAllByType("type", params),
35+
})
36+
3237
testAbortableMethod("is abortable with an AbortController", {
3338
run: (client, params) => client.getAllByType("type", params),
3439
})

‎test/client-getAllByUIDs.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetAllMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetAllMethod("returns all documents by UIDs from paginated response", {
78
run: (client) => client.getAllByUIDs("type", ["uid1", "uid2"]),
@@ -36,6 +37,11 @@ testFetchOptions("supports fetch options", {
3637
client.getAllByUIDs("type", ["uid1", "uid2"], params),
3738
})
3839

40+
testInvalidRefRetry({
41+
run: (client, params) =>
42+
client.getAllByUIDs("type", ["uid1", "uid2"], params),
43+
})
44+
3945
testAbortableMethod("is abortable with an AbortController", {
4046
run: (client, params) =>
4147
client.getAllByUIDs("type", ["uid1", "uid2"], params),

‎test/client-getByEveryTag.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetMethod("queries for documents by tag", {
78
run: (client) => client.getByEveryTag(["foo", "bar"]),
@@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", {
2930
run: (client, params) => client.getByEveryTag(["foo", "bar"], params),
3031
})
3132

33+
testInvalidRefRetry({
34+
run: (client, params) => client.getByEveryTag(["foo", "bar"], params),
35+
})
36+
3237
testAbortableMethod("is abortable with an AbortController", {
3338
run: (client, params) => client.getByEveryTag(["foo", "bar"], params),
3439
})

‎test/client-getByID.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetFirstMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetFirstMethod("queries for document by ID", {
78
run: (client) => client.getByID("id"),
@@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", {
2930
run: (client, params) => client.getByID("id", params),
3031
})
3132

33+
testInvalidRefRetry({
34+
run: (client, params) => client.getByID("id", params),
35+
})
36+
3237
testAbortableMethod("is abortable with an AbortController", {
3338
run: (client, params) => client.getByID("id", params),
3439
})

‎test/client-getByIDs.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetMethod("queries for documents by IDs", {
78
run: (client) => client.getByIDs(["id1", "id2"]),
@@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", {
2930
run: (client, params) => client.getByIDs(["id1", "id2"], params),
3031
})
3132

33+
testInvalidRefRetry({
34+
run: (client, params) => client.getByIDs(["id1", "id2"], params),
35+
})
36+
3237
testAbortableMethod("is abortable with an AbortController", {
3338
run: (client, params) => client.getByIDs(["id1", "id2"], params),
3439
})

‎test/client-getBySomeTags.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetMethod("queries for documents by some tags", {
78
run: (client) => client.getBySomeTags(["foo", "bar"]),
@@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", {
2930
run: (client, params) => client.getBySomeTags(["foo", "bar"], params),
3031
})
3132

33+
testInvalidRefRetry({
34+
run: (client, params) => client.getBySomeTags(["foo", "bar"], params),
35+
})
36+
3237
testAbortableMethod("is abortable with an AbortController", {
3338
run: (client, params) => client.getBySomeTags(["foo", "bar"], params),
3439
})

‎test/client-getByTag.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetMethod("queries for documents by tag", {
78
run: (client) => client.getByTag("tag"),
@@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", {
2930
run: (client, params) => client.getByTag("tag", params),
3031
})
3132

33+
testInvalidRefRetry({
34+
run: (client, params) => client.getByTag("tag", params),
35+
})
36+
3237
testAbortableMethod("is abortable with an AbortController", {
3338
run: (client, params) => client.getByTag("tag", params),
3439
})

‎test/client-getByType.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetMethod("queries for documents by type", {
78
run: (client) => client.getByType("type"),
@@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", {
2930
run: (client, params) => client.getByType("type", params),
3031
})
3132

33+
testInvalidRefRetry({
34+
run: (client, params) => client.getByType("type", params),
35+
})
36+
3237
testAbortableMethod("is abortable with an AbortController", {
3338
run: (client, params) => client.getByType("type", params),
3439
})

‎test/client-getByUID.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetFirstMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetFirstMethod("queries for document by UID", {
78
run: (client) => client.getByUID("type", "uid"),
@@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", {
2930
run: (client, params) => client.getByUID("type", "uid", params),
3031
})
3132

33+
testInvalidRefRetry({
34+
run: (client, params) => client.getByUID("type", "uid", params),
35+
})
36+
3237
testAbortableMethod("is abortable with an AbortController", {
3338
run: (client, params) => client.getByUID("type", "uid", params),
3439
})

‎test/client-getByUIDs.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetMethod("queries for documents by UIDs", {
78
run: (client) => client.getByUIDs("type", ["uid1", "uid2"]),
@@ -35,6 +36,10 @@ testFetchOptions("supports fetch options", {
3536
run: (client, params) => client.getByUIDs("type", ["uid1", "uid2"], params),
3637
})
3738

39+
testInvalidRefRetry({
40+
run: (client, params) => client.getByUIDs("type", ["uid1", "uid2"], params),
41+
})
42+
3843
testAbortableMethod("is abortable with an AbortController", {
3944
run: (client, params) => client.getByUIDs("type", ["uid1", "uid2"], params),
4045
})

‎test/client-getFirst.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
88
import { testGetFirstMethod } from "./__testutils__/testAnyGetMethod"
99
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
1010
import { testFetchOptions } from "./__testutils__/testFetchOptions"
11+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
1112

1213
import * as prismic from "../src"
1314

@@ -98,6 +99,10 @@ testFetchOptions("supports fetch options", {
9899
run: (client, params) => client.getFirst(params),
99100
})
100101

102+
testInvalidRefRetry({
103+
run: (client, params) => client.getFirst(params),
104+
})
105+
101106
testAbortableMethod("is abortable with an AbortController", {
102107
run: (client, params) => client.getFirst(params),
103108
})

‎test/client-getSingle.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { testAbortableMethod } from "./__testutils__/testAbortableMethod"
22
import { testGetFirstMethod } from "./__testutils__/testAnyGetMethod"
33
import { testConcurrentMethod } from "./__testutils__/testConcurrentMethod"
44
import { testFetchOptions } from "./__testutils__/testFetchOptions"
5+
import { testInvalidRefRetry } from "./__testutils__/testInvalidRefRetry"
56

67
testGetFirstMethod("queries for singleton document", {
78
run: (client) => client.getSingle("type"),
@@ -29,6 +30,10 @@ testFetchOptions("supports fetch options", {
2930
run: (client, params) => client.getSingle("type", params),
3031
})
3132

33+
testInvalidRefRetry({
34+
run: (client, params) => client.getSingle("type", params),
35+
})
36+
3237
testAbortableMethod("is abortable with an AbortController", {
3338
run: (client, params) => client.getSingle("type", params),
3439
})

0 commit comments

Comments
 (0)
Please sign in to comment.