Skip to content

Commit

Permalink
Move stuff around, rename gates() to validateFile()
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahum committed Mar 5, 2024
1 parent 83938ca commit 0de4395
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
15 changes: 11 additions & 4 deletions __tests__/bin/vip-app-deploy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { appDeployCmd } from '../../src/bin/vip-app-deploy';
import * as exit from '../../src/lib/cli/exit';
import { uploadImportSqlFileToS3 } from '../../src/lib/client-file-uploader';
import { gates, promptToContinue } from '../../src/lib/custom-deploy/custom-deploy';
import { validateDeployFileExt, validateFilename } from '../../src/lib/validations/custom-deploy';
import { validateFile, promptToContinue } from '../../src/lib/custom-deploy/custom-deploy';
import {
validateDeployFileExt,
validateFilename,
isSupportedApp,
} from '../../src/lib/validations/custom-deploy';

jest.mock( '../../src/lib/client-file-uploader', () => ( {
...jest.requireActual( '../../src/lib/client-file-uploader' ),
Expand All @@ -13,9 +17,10 @@ jest.mock( '../../src/lib/client-file-uploader', () => ( {
} ) );

jest.mock( '../../src/lib/custom-deploy/custom-deploy', () => ( {
gates: jest.fn(),
validateFile: jest.fn(),
renameFile: jest.fn(),
promptToContinue: jest.fn().mockResolvedValue( true ),
isSupportedApp: jest.fn().mockResolvedValue( true ),
} ) );

jest.mock( '../../src/lib/cli/command', () => {
Expand Down Expand Up @@ -85,7 +90,9 @@ describe( 'vip-app-deploy', () => {
it( 'should call expected functions', async () => {
await appDeployCmd( args, opts );

expect( gates ).toHaveBeenCalledTimes( 1 );
expect( isSupportedApp ).toHaveBeenCalledTimes( 1 );

expect( validateFile ).toHaveBeenCalledTimes( 1 );

expect( promptToContinue ).not.toHaveBeenCalled();

Expand Down
13 changes: 11 additions & 2 deletions src/bin/vip-app-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import {
WithId,
UploadArguments,
} from '../lib/client-file-uploader';
import { validateCustomDeployKey, gates } from '../lib/custom-deploy/custom-deploy';
import {
isSupportedApp,
validateCustomDeployKey,
validateFile,
} from '../lib/custom-deploy/custom-deploy';
import { trackEventWithEnv } from '../lib/tracker';

const CUSTOM_DEPLOY_KEY = process.env.CUSTOM_DEPLOY_KEY || '';
Expand Down Expand Up @@ -120,12 +124,17 @@ export async function appDeployCmd( arg: string[] = [], opts: Record< string, un
const envId = env.id as number;
const track = trackEventWithEnv.bind( null, appId, envId );

if ( ! isSupportedApp( app ) ) {
await track( 'deploy_app_command_error', { error_type: 'unsupported-app' } );
exit.withError( 'The type of application you specified does not currently support deploys.' );
}

if ( CUSTOM_DEPLOY_KEY ) {
debug( 'Validating custom deploy key...' );
await validateCustomDeployKey( CUSTOM_DEPLOY_KEY, envId );
}

await gates( app, env, fileMeta );
await validateFile( app, env, fileMeta );

await track( 'deploy_app_command_execute' );

Expand Down
7 changes: 1 addition & 6 deletions src/lib/custom-deploy/custom-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function validateCustomDeployKey(
/**
* @param {FileMeta} fileMeta
*/
export async function gates( app: App, env: AppEnvironment, fileMeta: FileMeta ) {
export async function validateFile( app: App, env: AppEnvironment, fileMeta: FileMeta ) {
const { fileName, basename, isCompressed } = fileMeta;
const appId = env.appId as number;
const envId = env.id as number;
Expand Down Expand Up @@ -75,11 +75,6 @@ export async function gates( app: App, env: AppEnvironment, fileMeta: FileMeta )
exit.withError( error as Error );
}

if ( ! isSupportedApp( app ) ) {
await track( 'deploy_app_command_error', { error_type: 'unsupported-app' } );
exit.withError( 'The type of application you specified does not currently support deploys.' );
}

try {
await checkFileAccess( fileName );
} catch ( err ) {
Expand Down

0 comments on commit 0de4395

Please sign in to comment.