Skip to content

Commit 11f12c9

Browse files
committed
feat: handle DELETE requests in API
1 parent 63e447c commit 11f12c9

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ export class Client {
126126
apiHeaders[METADATA_HEADER_EXTERNAL] = encodedMetadata
127127
}
128128

129-
// HEAD requests are implemented directly in the Netlify API.
130-
if (method === HTTPMethod.HEAD) {
129+
// HEAD and DELETE requests are implemented directly in the Netlify API.
130+
if (method === HTTPMethod.HEAD || method === HTTPMethod.DELETE) {
131131
return {
132132
headers: apiHeaders,
133133
url: url.toString(),

src/main.test.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,22 +1107,14 @@ describe('delete', () => {
11071107
const mockStore = new MockFetch()
11081108
.delete({
11091109
headers: { authorization: `Bearer ${apiToken}` },
1110-
response: new Response(JSON.stringify({ url: signedURL })),
1110+
response: new Response(null, { status: 204 }),
11111111
url: `https://api.netlify.com/api/v1/blobs/${siteID}/site:production/${key}`,
11121112
})
1113-
.delete({
1114-
response: new Response(null),
1115-
url: signedURL,
1116-
})
11171113
.delete({
11181114
headers: { authorization: `Bearer ${apiToken}` },
1119-
response: new Response(JSON.stringify({ url: signedURL })),
1115+
response: new Response(null, { status: 204 }),
11201116
url: `https://api.netlify.com/api/v1/blobs/${siteID}/site:production/${complexKey}`,
11211117
})
1122-
.delete({
1123-
response: new Response(null),
1124-
url: signedURL,
1125-
})
11261118

11271119
globalThis.fetch = mockStore.fetch
11281120

@@ -1139,16 +1131,11 @@ describe('delete', () => {
11391131
})
11401132

11411133
test('Does not throw when the blob does not exist', async () => {
1142-
const mockStore = new MockFetch()
1143-
.delete({
1144-
headers: { authorization: `Bearer ${apiToken}` },
1145-
response: new Response(JSON.stringify({ url: signedURL })),
1146-
url: `https://api.netlify.com/api/v1/blobs/${siteID}/site:production/${key}`,
1147-
})
1148-
.delete({
1149-
response: new Response(null, { status: 404 }),
1150-
url: signedURL,
1151-
})
1134+
const mockStore = new MockFetch().delete({
1135+
headers: { authorization: `Bearer ${apiToken}` },
1136+
response: new Response(null, { status: 404 }),
1137+
url: `https://api.netlify.com/api/v1/blobs/${siteID}/site:production/${key}`,
1138+
})
11521139

11531140
globalThis.fetch = mockStore.fetch
11541141

@@ -1178,7 +1165,7 @@ describe('delete', () => {
11781165
siteID,
11791166
})
11801167

1181-
expect(async () => await blobs.delete(key)).rejects.toThrowError(
1168+
await expect(async () => await blobs.delete(key)).rejects.toThrowError(
11821169
`Netlify Blobs has generated an internal error: 401 response`,
11831170
)
11841171
expect(mockStore.fulfilled).toBeTruthy()

0 commit comments

Comments
 (0)