-
Notifications
You must be signed in to change notification settings - Fork 777
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Pages] feat: add
wrangler pages project delete
command (#3293)
- Loading branch information
1 parent
2b709ce
commit 4a88db3
Showing
4 changed files
with
155 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": minor | ||
--- | ||
|
||
feat: add `wrangler pages project delete` command |
103 changes: 103 additions & 0 deletions
103
packages/wrangler/src/__tests__/pages/project-delete.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { rest } from "msw"; | ||
import { endEventLoop } from "../helpers/end-event-loop"; | ||
import { mockAccountId, mockApiToken } from "../helpers/mock-account-id"; | ||
import { mockConsoleMethods } from "../helpers/mock-console"; | ||
import { mockConfirm, clearDialogs } from "../helpers/mock-dialogs"; | ||
import { useMockIsTTY } from "../helpers/mock-istty"; | ||
import { msw } from "../helpers/msw"; | ||
import { runInTempDir } from "../helpers/run-in-tmp"; | ||
import { runWrangler } from "../helpers/run-wrangler"; | ||
|
||
describe("project delete", () => { | ||
const std = mockConsoleMethods(); | ||
|
||
runInTempDir(); | ||
mockAccountId(); | ||
mockApiToken(); | ||
const { setIsTTY } = useMockIsTTY(); | ||
|
||
beforeEach(() => { | ||
setIsTTY(true); | ||
}); | ||
|
||
afterEach(async () => { | ||
// Force a tick to ensure that all promises resolve | ||
await endEventLoop(); | ||
// Reset MSW after tick to ensure that all requests have been handled | ||
msw.resetHandlers(); | ||
msw.restoreHandlers(); | ||
clearDialogs(); | ||
}); | ||
|
||
it("should delete a project with the given name", async () => { | ||
msw.use( | ||
rest.delete( | ||
"*/accounts/:accountId/pages/projects/:projectName", | ||
async (req, res, ctx) => { | ||
expect(req.params.accountId).toEqual("some-account-id"); | ||
expect(req.params.projectName).toEqual("some-project-name"); | ||
return res.once( | ||
ctx.status(200), | ||
ctx.json({ | ||
result: null, | ||
success: true, | ||
errors: [], | ||
messages: [], | ||
}) | ||
); | ||
} | ||
) | ||
); | ||
|
||
mockConfirm({ | ||
text: `Are you sure you want to delete "some-project-name"? This action cannot be undone.`, | ||
result: true, | ||
}); | ||
|
||
await runWrangler("pages project delete some-project-name"); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
"Deleting some-project-name | ||
Successfully deleted some-project-name" | ||
`); | ||
}); | ||
|
||
it("should not delete a project if confirmation refused", async () => { | ||
mockConfirm({ | ||
text: `Are you sure you want to delete "some-project-name-2"? This action cannot be undone.`, | ||
result: false, | ||
}); | ||
|
||
await runWrangler("pages project delete some-project-name-2"); | ||
|
||
expect(std.out).toMatchInlineSnapshot(`""`); | ||
}); | ||
|
||
it("should delete a project without asking if --yes provided", async () => { | ||
msw.use( | ||
rest.delete( | ||
"*/accounts/:accountId/pages/projects/:projectName", | ||
async (req, res, ctx) => { | ||
expect(req.params.accountId).toEqual("some-account-id"); | ||
expect(req.params.projectName).toEqual("some-project-name"); | ||
return res.once( | ||
ctx.status(200), | ||
ctx.json({ | ||
result: null, | ||
success: true, | ||
errors: [], | ||
messages: [], | ||
}) | ||
); | ||
} | ||
) | ||
); | ||
|
||
await runWrangler("pages project delete some-project-name -y"); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
"Deleting some-project-name | ||
Successfully deleted some-project-name" | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters