From 0de4395cb6eb52853a81aa1888a8c185e3d64d0a Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Tue, 5 Mar 2024 15:37:48 -0700 Subject: [PATCH] Move stuff around, rename gates() to validateFile() --- __tests__/bin/vip-app-deploy.js | 15 +++++++++++---- src/bin/vip-app-deploy.ts | 13 +++++++++++-- src/lib/custom-deploy/custom-deploy.ts | 7 +------ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/__tests__/bin/vip-app-deploy.js b/__tests__/bin/vip-app-deploy.js index 07ba1cfcaf..26aead5be8 100644 --- a/__tests__/bin/vip-app-deploy.js +++ b/__tests__/bin/vip-app-deploy.js @@ -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' ), @@ -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', () => { @@ -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(); diff --git a/src/bin/vip-app-deploy.ts b/src/bin/vip-app-deploy.ts index 6833cc03d6..f1b4ea5ebd 100755 --- a/src/bin/vip-app-deploy.ts +++ b/src/bin/vip-app-deploy.ts @@ -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 || ''; @@ -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' ); diff --git a/src/lib/custom-deploy/custom-deploy.ts b/src/lib/custom-deploy/custom-deploy.ts index f3a07021f0..2460aa72c9 100644 --- a/src/lib/custom-deploy/custom-deploy.ts +++ b/src/lib/custom-deploy/custom-deploy.ts @@ -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; @@ -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 ) {