|
| 1 | +import { http, HttpResponse } from "msw"; |
| 2 | +import { endEventLoop } from "../helpers/end-event-loop"; |
| 3 | +import { mockAccountId, mockApiToken } from "../helpers/mock-account-id"; |
| 4 | +import { mockConsoleMethods } from "../helpers/mock-console"; |
| 5 | +import { msw } from "../helpers/msw"; |
| 6 | +import { runInTempDir } from "../helpers/run-in-tmp"; |
| 7 | +import { runWrangler } from "../helpers/run-wrangler"; |
| 8 | + |
| 9 | +const PROJECT_NAME = "images"; |
| 10 | +const DEPLOYMENT = "deployment"; |
| 11 | + |
| 12 | +describe("pages deployment delete", () => { |
| 13 | + runInTempDir(); |
| 14 | + mockAccountId(); |
| 15 | + mockApiToken(); |
| 16 | + mockConsoleMethods(); |
| 17 | + |
| 18 | + afterEach(async () => { |
| 19 | + await endEventLoop(); |
| 20 | + msw.resetHandlers(); |
| 21 | + msw.restoreHandlers(); |
| 22 | + }); |
| 23 | + |
| 24 | + it("should make request to delete deployment", async () => { |
| 25 | + const requests = mockDeploymentDeleteRequest(DEPLOYMENT); |
| 26 | + await runWrangler( |
| 27 | + `pages deployment delete ${DEPLOYMENT} --project-name=${PROJECT_NAME}` |
| 28 | + ); |
| 29 | + expect(requests.count).toBe(1); |
| 30 | + }); |
| 31 | + |
| 32 | + it("should throw an error if deployment ID is missing", async () => { |
| 33 | + await expect( |
| 34 | + runWrangler(`pages deployment delete --project-name=${PROJECT_NAME}`) |
| 35 | + ).rejects.toThrow("Must specify a project name and deployment."); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should throw an error if project name is missing in non-interactive mode", async () => { |
| 39 | + await expect( |
| 40 | + runWrangler(`pages deployment delete ${DEPLOYMENT}`) |
| 41 | + ).rejects.toThrow("Must specify a project name in non-interactive mode."); |
| 42 | + }); |
| 43 | +}); |
| 44 | + |
| 45 | +/* -------------------------------------------------- */ |
| 46 | +/* Helper Functions */ |
| 47 | +/* -------------------------------------------------- */ |
| 48 | + |
| 49 | +type RequestLogger = { |
| 50 | + count: number; |
| 51 | + queryParams: [string, string][][]; |
| 52 | +}; |
| 53 | + |
| 54 | +function mockDeploymentDeleteRequest(deployment: string): RequestLogger { |
| 55 | + const requests: RequestLogger = { count: 0, queryParams: [] }; |
| 56 | + msw.use( |
| 57 | + http.delete( |
| 58 | + "*/accounts/:accountId/pages/projects/:project/deployments/:deployment", |
| 59 | + ({ request, params }) => { |
| 60 | + requests.count++; |
| 61 | + const url = new URL(request.url); |
| 62 | + requests.queryParams.push(Array.from(url.searchParams.entries())); |
| 63 | + expect(params.project).toEqual(PROJECT_NAME); |
| 64 | + expect(params.accountId).toEqual("some-account-id"); |
| 65 | + |
| 66 | + return HttpResponse.json( |
| 67 | + { |
| 68 | + success: true, |
| 69 | + errors: [], |
| 70 | + messages: [], |
| 71 | + result: deployment, |
| 72 | + }, |
| 73 | + { status: 200 } |
| 74 | + ); |
| 75 | + }, |
| 76 | + { once: true } |
| 77 | + ) |
| 78 | + ); |
| 79 | + return requests; |
| 80 | +} |
0 commit comments