@@ -5,7 +5,7 @@ import { mockConsoleMethods } from "./helpers/mock-console";
5
5
import { runInTempDir } from "./helpers/run-in-tmp" ;
6
6
import { runWrangler } from "./helpers/run-wrangler" ;
7
7
import type { Project , Deployment } from "../pages" ;
8
- import type { File , FormData } from "undici" ;
8
+ import type { FormData } from "undici" ;
9
9
10
10
describe ( "pages" , ( ) => {
11
11
runInTempDir ( ) ;
@@ -279,21 +279,53 @@ describe("pages", () => {
279
279
writeFileSync ( "logo.png" , "foobar" ) ;
280
280
281
281
setMockResponse (
282
- "/accounts/:accountId/pages/projects/foo/file " ,
283
- async ( [ _url , accountId ] , init ) => {
282
+ "/accounts/:accountId/pages/projects/foo/upload-token " ,
283
+ async ( [ _url , accountId ] ) => {
284
284
expect ( accountId ) . toEqual ( "some-account-id" ) ;
285
- expect ( init . method ) . toEqual ( "POST" ) ;
286
- const body = init . body as FormData ;
287
- const logoPNGFile = body . get ( "file" ) as File ;
288
- expect ( await logoPNGFile . text ( ) ) . toEqual ( "foobar" ) ;
289
- expect ( logoPNGFile . name ) . toEqual ( "logo.png" ) ;
290
285
291
286
return {
292
- id : "2082190357cfd3617ccfe04f340c6247 " ,
287
+ jwt : "<<funfetti-auth-jwt>> " ,
293
288
} ;
294
289
}
295
290
) ;
296
291
292
+ setMockResponse (
293
+ "/pages/assets/check-missing" ,
294
+ "POST" ,
295
+ async ( _ , init ) => {
296
+ expect ( init . headers ) . toMatchObject ( {
297
+ Authorization : "Bearer <<funfetti-auth-jwt>>" ,
298
+ } ) ;
299
+ const body = JSON . parse ( init . body as string ) as { hashes : string [ ] } ;
300
+ expect ( body ) . toMatchObject ( {
301
+ hashes : [ "2082190357cfd3617ccfe04f340c6247" ] ,
302
+ } ) ;
303
+ return body . hashes ;
304
+ }
305
+ ) ;
306
+
307
+ setMockResponse ( "/pages/assets/upload" , "POST" , async ( _ , init ) => {
308
+ expect ( init . headers ) . toMatchObject ( {
309
+ Authorization : "Bearer <<funfetti-auth-jwt>>" ,
310
+ } ) ;
311
+ const body = JSON . parse ( init . body as string ) as {
312
+ key : string ;
313
+ value : string ;
314
+ metadata : { contentType : string } ;
315
+ base64 : boolean ;
316
+ } [ ] ;
317
+ expect ( body ) . toMatchObject ( [
318
+ {
319
+ key : "2082190357cfd3617ccfe04f340c6247" ,
320
+ value : Buffer . from ( "foobar" ) . toString ( "base64" ) ,
321
+ metadata : {
322
+ contentType : "image/png" ,
323
+ } ,
324
+ base64 : true ,
325
+ } ,
326
+ ] ) ;
327
+ } ) ;
328
+
297
329
setMockResponse (
298
330
"/accounts/:accountId/pages/projects/foo/deployments" ,
299
331
async ( [ _url , accountId ] , init ) => {
@@ -326,15 +358,58 @@ describe("pages", () => {
326
358
327
359
it ( "should not error when directory names contain periods and houses a extensionless file" , async ( ) => {
328
360
mkdirSync ( ".well-known" ) ;
361
+ // Note: same content as previous test, but since it's a different extension,
362
+ // it hashes to a different value
329
363
writeFileSync ( ".well-known/foobar" , "foobar" ) ;
330
364
331
365
setMockResponse (
332
- "/accounts/:accountId/pages/projects/foo/file" ,
333
- async ( ) => ( {
334
- id : "7b764dacfd211bebd8077828a7ddefd7" ,
335
- } )
366
+ "/accounts/:accountId/pages/projects/foo/upload-token" ,
367
+ async ( [ _url , accountId ] ) => {
368
+ expect ( accountId ) . toEqual ( "some-account-id" ) ;
369
+
370
+ return {
371
+ jwt : "<<funfetti-auth-jwt>>" ,
372
+ } ;
373
+ }
374
+ ) ;
375
+
376
+ setMockResponse (
377
+ "/pages/assets/check-missing" ,
378
+ "POST" ,
379
+ async ( _ , init ) => {
380
+ expect ( init . headers ) . toMatchObject ( {
381
+ Authorization : "Bearer <<funfetti-auth-jwt>>" ,
382
+ } ) ;
383
+ const body = JSON . parse ( init . body as string ) as { hashes : string [ ] } ;
384
+ expect ( body ) . toMatchObject ( {
385
+ hashes : [ "7b764dacfd211bebd8077828a7ddefd7" ] ,
386
+ } ) ;
387
+ return body . hashes ;
388
+ }
336
389
) ;
337
390
391
+ setMockResponse ( "/pages/assets/upload" , "POST" , async ( _ , init ) => {
392
+ expect ( init . headers ) . toMatchObject ( {
393
+ Authorization : "Bearer <<funfetti-auth-jwt>>" ,
394
+ } ) ;
395
+ const body = JSON . parse ( init . body as string ) as {
396
+ key : string ;
397
+ value : string ;
398
+ metadata : { contentType : string } ;
399
+ base64 : boolean ;
400
+ } [ ] ;
401
+ expect ( body ) . toMatchObject ( [
402
+ {
403
+ key : "7b764dacfd211bebd8077828a7ddefd7" ,
404
+ value : Buffer . from ( "foobar" ) . toString ( "base64" ) ,
405
+ metadata : {
406
+ contentType : "application/octet-stream" ,
407
+ } ,
408
+ base64 : true ,
409
+ } ,
410
+ ] ) ;
411
+ } ) ;
412
+
338
413
setMockResponse (
339
414
"/accounts/:accountId/pages/projects/foo/deployments" ,
340
415
async ( ) => ( {
0 commit comments