@@ -73,6 +73,7 @@ test.serial('Throws if the API response does not have a successful status code',
7373 body : ( payload ) => {
7474 const data = JSON . parse ( payload )
7575
76+ t . is ( data . cache_tags , undefined )
7677 t . is ( data . site_id , mockSiteID )
7778 } ,
7879 headers : { Authorization : `Bearer ${ mockToken } ` } ,
@@ -104,7 +105,7 @@ test.serial('Ignores purgeCache if in local dev with no token or site', async (t
104105 const mockAPI = new MockFetch ( ) . post ( {
105106 body : ( ) => {
106107 t . fail ( )
107- }
108+ } ,
108109 } )
109110 const myFunction = async ( ) => {
110111 await purgeCache ( )
@@ -116,3 +117,40 @@ test.serial('Ignores purgeCache if in local dev with no token or site', async (t
116117
117118 t . is ( response , undefined )
118119} )
120+
121+ test . serial ( 'Calls the purge API endpoint with an empty array of cache tags' , async ( t ) => {
122+ if ( ! hasFetchAPI ) {
123+ console . warn ( 'Skipping test requires the fetch API' )
124+
125+ return t . pass ( )
126+ }
127+
128+ const mockSiteID = '123456789'
129+ const mockToken = '1q2w3e4r5t6y7u8i9o0p'
130+
131+ process . env . NETLIFY_PURGE_API_TOKEN = mockToken
132+ process . env . SITE_ID = mockSiteID
133+
134+ const mockAPI = new MockFetch ( ) . post ( {
135+ body : ( payload ) => {
136+ const data = JSON . parse ( payload )
137+
138+ t . deepEqual ( data . cache_tags , [ ] )
139+ t . is ( data . site_id , mockSiteID )
140+ } ,
141+ headers : { Authorization : `Bearer ${ mockToken } ` } ,
142+ method : 'post' ,
143+ response : new Response ( null , { status : 202 } ) ,
144+ url : `https://api.netlify.com/api/v1/purge` ,
145+ } )
146+ const myFunction = async ( ) => {
147+ await purgeCache ( { tags : [ ] } )
148+ }
149+
150+ globalThis . fetch = mockAPI . fetcher
151+
152+ const response = await invokeLambda ( myFunction )
153+
154+ t . is ( response , undefined )
155+ t . true ( mockAPI . fulfilled )
156+ } )
0 commit comments