@@ -163,6 +163,56 @@ describe('get', () => {
163163
164164 expect ( mockStore . fulfilled ) . toBeTruthy ( )
165165 } )
166+
167+ test ( 'Reads from a store with a legacy namespace' , async ( ) => {
168+ const mockStore = new MockFetch ( )
169+ . get ( {
170+ headers : { accept : 'application/json;type=signed-url' , authorization : `Bearer ${ apiToken } ` } ,
171+ response : new Response ( JSON . stringify ( { url : signedURL } ) ) ,
172+ url : `https://api.netlify.com/api/v1/blobs/${ siteID } /oldie/${ key } ` ,
173+ } )
174+ . get ( {
175+ response : new Response ( value ) ,
176+ url : signedURL ,
177+ } )
178+ . get ( {
179+ headers : { accept : 'application/json;type=signed-url' , authorization : `Bearer ${ apiToken } ` } ,
180+ response : new Response ( JSON . stringify ( { url : signedURL } ) ) ,
181+ url : `https://api.netlify.com/api/v1/blobs/${ siteID } /oldie/${ key } ` ,
182+ } )
183+ . get ( {
184+ response : new Response ( value ) ,
185+ url : signedURL ,
186+ } )
187+ . get ( {
188+ headers : { accept : 'application/json;type=signed-url' , authorization : `Bearer ${ apiToken } ` } ,
189+ response : new Response ( JSON . stringify ( { url : signedURL } ) ) ,
190+ url : `https://api.netlify.com/api/v1/blobs/${ siteID } /oldie/${ complexKey } ` ,
191+ } )
192+ . get ( {
193+ response : new Response ( value ) ,
194+ url : signedURL ,
195+ } )
196+
197+ globalThis . fetch = mockStore . fetch
198+
199+ const blobs = getStore ( {
200+ name : 'netlify-internal/legacy-namespace/oldie' ,
201+ token : apiToken ,
202+ siteID,
203+ } )
204+
205+ const string = await blobs . get ( key )
206+ expect ( string ) . toBe ( value )
207+
208+ const stream = await blobs . get ( key , { type : 'stream' } )
209+ expect ( await streamToString ( stream as unknown as NodeJS . ReadableStream ) ) . toBe ( value )
210+
211+ const string2 = await blobs . get ( complexKey )
212+ expect ( string2 ) . toBe ( value )
213+
214+ expect ( mockStore . fulfilled ) . toBeTruthy ( )
215+ } )
166216 } )
167217
168218 describe ( 'With edge credentials' , ( ) => {
@@ -1057,22 +1107,14 @@ describe('delete', () => {
10571107 const mockStore = new MockFetch ( )
10581108 . delete ( {
10591109 headers : { authorization : `Bearer ${ apiToken } ` } ,
1060- response : new Response ( JSON . stringify ( { url : signedURL } ) ) ,
1110+ response : new Response ( null , { status : 204 } ) ,
10611111 url : `https://api.netlify.com/api/v1/blobs/${ siteID } /site:production/${ key } ` ,
10621112 } )
1063- . delete ( {
1064- response : new Response ( null ) ,
1065- url : signedURL ,
1066- } )
10671113 . delete ( {
10681114 headers : { authorization : `Bearer ${ apiToken } ` } ,
1069- response : new Response ( JSON . stringify ( { url : signedURL } ) ) ,
1115+ response : new Response ( null , { status : 204 } ) ,
10701116 url : `https://api.netlify.com/api/v1/blobs/${ siteID } /site:production/${ complexKey } ` ,
10711117 } )
1072- . delete ( {
1073- response : new Response ( null ) ,
1074- url : signedURL ,
1075- } )
10761118
10771119 globalThis . fetch = mockStore . fetch
10781120
@@ -1089,16 +1131,11 @@ describe('delete', () => {
10891131 } )
10901132
10911133 test ( 'Does not throw when the blob does not exist' , async ( ) => {
1092- const mockStore = new MockFetch ( )
1093- . delete ( {
1094- headers : { authorization : `Bearer ${ apiToken } ` } ,
1095- response : new Response ( JSON . stringify ( { url : signedURL } ) ) ,
1096- url : `https://api.netlify.com/api/v1/blobs/${ siteID } /site:production/${ key } ` ,
1097- } )
1098- . delete ( {
1099- response : new Response ( null , { status : 404 } ) ,
1100- url : signedURL ,
1101- } )
1134+ const mockStore = new MockFetch ( ) . delete ( {
1135+ headers : { authorization : `Bearer ${ apiToken } ` } ,
1136+ response : new Response ( null , { status : 404 } ) ,
1137+ url : `https://api.netlify.com/api/v1/blobs/${ siteID } /site:production/${ key } ` ,
1138+ } )
11021139
11031140 globalThis . fetch = mockStore . fetch
11041141
@@ -1128,7 +1165,7 @@ describe('delete', () => {
11281165 siteID,
11291166 } )
11301167
1131- expect ( async ( ) => await blobs . delete ( key ) ) . rejects . toThrowError (
1168+ await expect ( async ( ) => await blobs . delete ( key ) ) . rejects . toThrowError (
11321169 `Netlify Blobs has generated an internal error: 401 response` ,
11331170 )
11341171 expect ( mockStore . fulfilled ) . toBeTruthy ( )
0 commit comments