import * as fs from 'fs' ; import { S3 } from 'aws-sdk' ; import { BucketHandler , s3CreateBucket as createBucket , } from '../../../../test/utils' ; import { deployTrigger } from '../deploy-trigger' ; import { generateZipBundle } from './utils' ; describe ( 'deploy-trigger' , ( ) => { let s3 ; beforeAll ( ( ) => { s3 = new S3 ( { endpoint : process . env . S3_ENDPOINT , accessKeyId : process . env . MINIO_ACCESS_KEY , secretAccessKey : process . env . MINIO_SECRET_KEY , s3ForcePathStyle : true , signatureVersion : 'v4' , sslEnabled : false , } ) ; } ) ; describe ( 'Extract an uploaded deployment' , ( ) => { let sourceBucket ; let targetBucket ; beforeAll ( async ( ) => { sourceBucket = await createBucket ( s3 ) ; targetBucket = await createBucket ( s3 ) ; } ) ; afterAll ( async ( ) => { await sourceBucket . destroy ( ) ; await targetBucket . destroy ( ) ; } ) ; test ( 'Extract an uploaded deployment' , async ( ) => { const packageKey = 'static-website-files.zip' ; const staticRouteKey = '404' ; const staticAssetKey = '_next/static/some.js' ; const packageContent = [ 'index' , staticRouteKey , staticAssetKey ] ; const bundle = await generateZipBundle ( packageContent ) ; await s3 . upload ( { Key : 'static-website-files.zip' , Body : fs . createReadStream ( bundle ) , Bucket : sourceBucket . bucketName , } ) . promise ( ) ; const { buildId , files } = await deployTrigger ( { s3 , sourceBucket : sourceBucket . bucketName , deployBucket : targetBucket . bucketName , key : packageKey , } ) ; expect ( buildId ) . toBeDefined ( ) ; expect ( files . length ) . toBe ( packageContent . length ) ; const { Contents } = await s3 . listObjects ( { Bucket : targetBucket . bucketName } ) . promise ( ) ; for ( const fileKey of packageContent ) { expect ( Contents ) . toEqual ( expect . arrayContaining ( [ expect . objectContaining ( { Key : fileKey , } ) , ] ) ) ; } const staticRouteObject = await s3 . getObject ( { Bucket : targetBucket . bucketName , Key : staticRouteKey } ) . promise ( ) ; expect ( staticRouteObject . ContentType ) . toBe ( 'text/html; charset=utf-8' ) ; expect ( staticRouteObject . CacheControl ) . toBe ( 'public,max-age=0,must-revalidate,s-maxage=31536000' ) ; const staticAssetObject = await s3 . getObject ( { Bucket : targetBucket . bucketName , Key : staticAssetKey } ) . promise ( ) ; expect ( staticAssetObject . ContentType ) . toBe ( 'application/javascript; charset=utf-8' ) ; expect ( staticAssetObject . CacheControl ) . toBe ( 'public,max-age=31536000,immutable' ) ; } ) ; } ) ; } ) ;