Skip to content

Commit cfd3d62

Browse files
committed
Update r2 domain tests to check for confirmation prompts
1 parent 494fd92 commit cfd3d62

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

.changeset/tame-dryers-end.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"wrangler": patch
2+
"wrangler": minor
33
---
44

55
Added the ability to list, add, remove, and update R2 bucket custom domains.

packages/wrangler/src/__tests__/r2.test.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { actionsForEventCategories } from "../r2/helpers";
55
import { endEventLoop } from "./helpers/end-event-loop";
66
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
77
import { mockConsoleMethods } from "./helpers/mock-console";
8+
import { mockConfirm } from "./helpers/mock-dialogs";
89
import { useMockIsTTY } from "./helpers/mock-istty";
910
import { createFetchResult, msw, mswR2handlers } from "./helpers/msw";
1011
import { runInTempDir } from "./helpers/run-in-tmp";
@@ -1446,13 +1447,22 @@ describe("r2", () => {
14461447
});
14471448
});
14481449
describe("domain", () => {
1450+
const { setIsTTY } = useMockIsTTY();
14491451
mockAccountId();
14501452
mockApiToken();
14511453
describe("add", () => {
14521454
it("should add custom domain to the bucket as expected", async () => {
14531455
const bucketName = "my-bucket";
14541456
const domainName = "example.com";
14551457
const zoneId = "zone-id-123";
1458+
1459+
setIsTTY(true);
1460+
mockConfirm({
1461+
text:
1462+
`Are you sure you want to add the custom domain '${domainName}' to bucket '${bucketName}'? ` +
1463+
`The contents of your bucket will be made publicly available at 'https://${domainName}'`,
1464+
result: true,
1465+
});
14561466
msw.use(
14571467
http.post(
14581468
"*/accounts/:accountId/r2/buckets/:bucketName/domains/custom",
@@ -1473,7 +1483,7 @@ describe("r2", () => {
14731483
)
14741484
);
14751485
await runWrangler(
1476-
`r2 bucket domain add ${bucketName} --domain ${domainName} --zone-id ${zoneId} --force`
1486+
`r2 bucket domain add ${bucketName} --domain ${domainName} --zone-id ${zoneId}`
14771487
);
14781488
expect(std.out).toMatchInlineSnapshot(`
14791489
"Connecting custom domain 'example.com' to bucket 'my-bucket'...
@@ -1484,7 +1494,7 @@ describe("r2", () => {
14841494
it("should error if domain and zone-id are not provided", async () => {
14851495
const bucketName = "my-bucket";
14861496
await expect(
1487-
runWrangler(`r2 bucket domain add ${bucketName} --force`)
1497+
runWrangler(`r2 bucket domain add ${bucketName}`)
14881498
).rejects.toThrowErrorMatchingInlineSnapshot(
14891499
`[Error: Missing required arguments: domain, zone-id]`
14901500
);
@@ -1563,6 +1573,13 @@ describe("r2", () => {
15631573
it("should remove a custom domain as expected", async () => {
15641574
const bucketName = "my-bucket";
15651575
const domainName = "example.com";
1576+
setIsTTY(true);
1577+
mockConfirm({
1578+
text:
1579+
`Are you sure you want to remove the custom domain '${domainName}' from bucket '${bucketName}'? ` +
1580+
`Your bucket will no longer be available from 'https://${domainName}'`,
1581+
result: true,
1582+
});
15661583
msw.use(
15671584
http.delete(
15681585
"*/accounts/:accountId/r2/buckets/:bucketName/domains/custom/:domainName",
@@ -1581,7 +1598,7 @@ describe("r2", () => {
15811598
)
15821599
);
15831600
await runWrangler(
1584-
`r2 bucket domain remove ${bucketName} --domain ${domainName} --force`
1601+
`r2 bucket domain remove ${bucketName} --domain ${domainName}`
15851602
);
15861603
expect(std.out).toMatchInlineSnapshot(`
15871604
"Removing custom domain 'example.com' from bucket 'my-bucket'...

0 commit comments

Comments
 (0)