Skip to content

Commit

Permalink
Update sql import tests
Browse files Browse the repository at this point in the history
  • Loading branch information
t-wright committed Oct 20, 2023
1 parent ac836e5 commit eaa9bb2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Binary file added __fixtures__/validations/bad-sql-dump.sql.gz
Binary file not shown.
Binary file removed __fixtures__/validations/empty.sql.gz
Binary file not shown.
19 changes: 11 additions & 8 deletions __tests__/bin/vip-import-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,26 @@ describe( 'vip-import-sql', () => {
} );

it( 'fails if the import file has an invalid extension', async () => {
const compressedFilePath = path.join(
const invalidFilePath = path.join(
process.cwd(),
'__fixtures__',
'validations',
'empty.zip'
);

await gates( opts.app, opts.env, compressedFilePath );
expect( mockExit ).toHaveBeenCalledWith( 'File must have an extension of .gz or .sql.' );
const fileMeta = { fileName: invalidFilePath, basename: 'empty.zip' };
await gates( opts.app, opts.env, fileMeta );
expect( mockExit ).toHaveBeenCalledWith(
'Invalid file extension. Please provide a .sql or .gz file.'
);
} );

it.each( [ 'empty.sql.gz', 'bad-sql-dump.sql' ] )(
it.each( [ 'bad-sql-dump.sql.gz', 'bad-sql-dump.sql' ] )(
'passes if the import file has a valid extension',
async fileName => {
const validPath = path.join( process.cwd(), '__fixtures__', 'validations', fileName );

await gates( opts.app, opts.env, validPath );
async basename => {
const validFilePath = path.join( process.cwd(), '__fixtures__', 'validations', basename );
const fileMeta = { fileName: validFilePath, basename };
await gates( opts.app, opts.env, fileMeta );
expect( mockExit ).not.toHaveBeenCalled();
}
);
Expand Down
1 change: 1 addition & 0 deletions src/lib/client-file-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const unzipFile = async (

const extractionInfo = extractFunctions[ mimeType ];

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if ( ! extractionInfo ) {
throw new Error( `unsupported file format: ${ mimeType }` );
}
Expand Down

0 comments on commit eaa9bb2

Please sign in to comment.