import { Client , expect , TestSandbox } from '@loopback/testlab' ; import path from 'path' ; import { FileUploadApplication } from '../..' ; import { getSandbox , setupApplication } from './test-helper' ; describe ( 'file upload acceptance - multipart/form-data' , ( ) => { let sandbox ; let client ; let app ; before ( resetSandbox ) ; before ( givenAClient ) ; after ( async ( ) => { await app . stop ( ) ; } ) ; after ( resetSandbox ) ; it ( 'supports file uploads' , async ( ) => { const FIXTURES = path . resolve ( __dirname , '../../../fixtures' ) ; const res = await client . post ( '/files' ) . field ( 'user' , 'john' ) . field ( 'email' , 'john@example.com' ) . attach ( 'testFile1' , path . resolve ( FIXTURES , 'file-upload-test.txt' ) , { filename : 'file-upload-test.txt' , contentType : 'multipart/form-data' , } ) . attach ( 'testFile2' , path . resolve ( FIXTURES , 'assets/index.html' ) , { filename : 'index.html' , contentType : 'multipart/form-data' , } ) . expect ( 200 ) ; expect ( res . body . files [ 0 ] ) . containEql ( { fieldname : 'testFile1' , originalname : 'file-upload-test.txt' , mimetype : 'multipart/form-data' , } ) ; expect ( res . body . files [ 1 ] ) . containEql ( { fieldname : 'testFile2' , originalname : 'index.html' , mimetype : 'multipart/form-data' , } ) ; } ) ; async function givenAClient ( ) { ( { app , client } = await setupApplication ( sandbox . path ) ) ; } async function resetSandbox ( ) { sandbox = getSandbox ( ) ; await sandbox . reset ( ) ; } } ) ;