@@ -2,12 +2,14 @@ import { http, HttpResponse } from "msw";
22import patchConsole from "patch-console" ;
33import { mockAccount , setWranglerConfig } from "../cloudchamber/utils" ;
44import { mockAccountId , mockApiToken } from "../helpers/mock-account-id" ;
5- import { mockConsoleMethods } from "../helpers/mock-console" ;
5+ import { mockCLIOutput , mockConsoleMethods } from "../helpers/mock-console" ;
66import { useMockIsTTY } from "../helpers/mock-istty" ;
77import { msw } from "../helpers/msw" ;
88import { runWrangler } from "../helpers/run-wrangler" ;
99
1010describe ( "containers delete" , ( ) => {
11+ const stdCli = mockCLIOutput ( ) ;
12+
1113 const std = mockConsoleMethods ( ) ;
1214 const { setIsTTY } = useMockIsTTY ( ) ;
1315
@@ -43,6 +45,98 @@ describe("containers delete", () => {
4345 ` ) ;
4446 } ) ;
4547
48+ async function testStatusCode ( code : number ) {
49+ setWranglerConfig ( { } ) ;
50+ msw . use (
51+ http . delete (
52+ "*/applications/:id" ,
53+ async ( { request } ) => {
54+ expect ( await request . text ( ) ) . toEqual ( "" ) ;
55+ return new HttpResponse ( `{"error": "something happened"}` , {
56+ status : code ,
57+ } ) ;
58+ } ,
59+ { once : true }
60+ )
61+ ) ;
62+ await expect ( runWrangler ( "containers delete 123" ) ) . rejects
63+ . toMatchInlineSnapshot ( `
64+ [Error: There has been an error deleting the container.
65+ something happened]
66+ ` ) ;
67+ expect ( stdCli . stderr ) . toMatchInlineSnapshot ( `""` ) ;
68+ expect ( stdCli . stdout ) . toMatchInlineSnapshot ( `
69+ "├ Loading account
70+ │
71+ ├ Loading account
72+ │
73+ ╭ Delete your container
74+ │
75+ "
76+ ` ) ;
77+ }
78+
79+ it ( "should delete container with 400" , ( ) => testStatusCode ( 400 ) ) ;
80+ it ( "should delete container with 404" , ( ) => testStatusCode ( 404 ) ) ;
81+
82+ it ( "should delete container with 500" , async ( ) => {
83+ setWranglerConfig ( { } ) ;
84+ msw . use (
85+ http . delete (
86+ "*/applications/:id" ,
87+ async ( { request } ) => {
88+ expect ( await request . text ( ) ) . toEqual ( "" ) ;
89+ return new HttpResponse ( `{"error": "something happened"}` , {
90+ status : 500 ,
91+ } ) ;
92+ } ,
93+ { once : true }
94+ )
95+ ) ;
96+ await expect ( runWrangler ( "containers delete 123" ) ) . rejects
97+ . toMatchInlineSnapshot ( `
98+ [Error: There has been an unknown error deleting the container.
99+ "{/"error/": /"something happened/"}"]
100+ ` ) ;
101+ expect ( stdCli . stderr ) . toMatchInlineSnapshot ( `""` ) ;
102+ expect ( stdCli . stdout ) . toMatchInlineSnapshot ( `
103+ "├ Loading account
104+ │
105+ ├ Loading account
106+ │
107+ ╭ Delete your container
108+ │
109+ "
110+ ` ) ;
111+ } ) ;
112+
113+ it ( "should delete container" , async ( ) => {
114+ setWranglerConfig ( { } ) ;
115+ msw . use (
116+ http . delete (
117+ "*/applications/:id" ,
118+ async ( { request } ) => {
119+ expect ( await request . text ( ) ) . toEqual ( "" ) ;
120+ return new HttpResponse ( "{}" ) ;
121+ } ,
122+ { once : true }
123+ )
124+ ) ;
125+ await runWrangler ( "containers delete 123" ) ;
126+ expect ( stdCli . stderr ) . toMatchInlineSnapshot ( `""` ) ;
127+ expect ( stdCli . stdout ) . toMatchInlineSnapshot ( `
128+ "├ Loading account
129+ │
130+ ├ Loading account
131+ │
132+ ╭ Delete your container
133+ │
134+ ╰ Your container has been deleted
135+
136+ "
137+ ` ) ;
138+ } ) ;
139+
46140 it ( "should delete container (json)" , async ( ) => {
47141 setIsTTY ( false ) ;
48142 setWranglerConfig ( { } ) ;
0 commit comments