-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* BYOR: Add `vip deploy app` * Add logic to rename on upload to prevent file being overwritten * Add --message parameter * Add --force to options * Add validation checks + tests * Mekk typescript * Add constant & remove `currentUserCanDeployForApp()` * `gates()`: Add check to ensure file is compressed before uploading * Instead of fs copying, just change key on AWS upload and change deploy message when done * Rename cmd to `vip app deploy` * Allow hashing with sha256 * Rename steps * Adjust to sentence case --------- Co-authored-by: Caleb Burks <[email protected]>
- Loading branch information
1 parent
756ff79
commit 5d862dd
Showing
11 changed files
with
572 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
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/manual-deploy/manual-deploy'; | ||
import { validateDeployFileExt, validateFilename } from '../../src/lib/validations/manual-deploy'; | ||
|
||
jest.mock( '../../src/lib/client-file-uploader', () => ( { | ||
...jest.requireActual( '../../src/lib/client-file-uploader' ), | ||
getFileMeta: jest | ||
.fn() | ||
.mockResolvedValue( { fileName: '/vip/skeleton.zip', basename: 'skeleton.zip' } ), | ||
uploadImportSqlFileToS3: jest.fn(), | ||
} ) ); | ||
|
||
jest.mock( '../../src/lib/manual-deploy/manual-deploy', () => ( { | ||
gates: jest.fn(), | ||
renameFile: jest.fn(), | ||
promptToContinue: jest.fn().mockResolvedValue( true ), | ||
} ) ); | ||
|
||
jest.mock( '../../src/lib/cli/command', () => { | ||
const commandMock = { | ||
argv: () => commandMock, | ||
examples: () => commandMock, | ||
option: () => commandMock, | ||
}; | ||
return jest.fn( () => commandMock ); | ||
} ); | ||
|
||
const exitSpy = jest.spyOn( exit, 'withError' ); | ||
jest.spyOn( process, 'exit' ).mockImplementation( () => {} ); | ||
jest.spyOn( console, 'error' ).mockImplementation( () => {} ); | ||
|
||
const args = [ '/vip/skeleton.zip' ]; | ||
const opts = { | ||
app: { | ||
id: 1, | ||
organization: { | ||
id: 2, | ||
}, | ||
}, | ||
env: { | ||
id: 3, | ||
type: 'develop', | ||
}, | ||
force: true, | ||
}; | ||
|
||
describe( 'vip-app-deploy', () => { | ||
describe( 'validations', () => { | ||
beforeEach( async () => { | ||
exitSpy.mockClear(); | ||
} ); | ||
|
||
it.each( [ '$t2.tar.gz', 'vip-go!!skeleton.zip', '1-(vip).tgz' ] )( | ||
'fails if the deploy file has has invalid characters', | ||
async basename => { | ||
validateFilename( basename ); | ||
expect( exitSpy ).toHaveBeenCalledWith( | ||
'Error: The characters used in the name of a file for manual deploys are limited to [0-9,a-z,A-Z,-,_,.]' | ||
); | ||
} | ||
); | ||
|
||
it.each( [ 'test-repo.rar', 'vip-go-skeleton.sql', 'vip.test' ] )( | ||
'fails if the deploy file has an invalid extension', | ||
async basename => { | ||
validateDeployFileExt( basename ); | ||
expect( exitSpy ).toHaveBeenCalledWith( | ||
'Invalid file extension. Please provide a .zip, .tar.gz, or a .tgz file.' | ||
); | ||
} | ||
); | ||
|
||
it.each( [ 'test-repo.tar.gz', 'vip-go-skeleton.zip', 'vip.tgz' ] )( | ||
'passes if the deploy file has a valid extension', | ||
async basename => { | ||
validateDeployFileExt( basename ); | ||
expect( exitSpy ).not.toHaveBeenCalled(); | ||
} | ||
); | ||
} ); | ||
|
||
describe( 'appDeployCmd', () => { | ||
it( 'should call expected functions', async () => { | ||
await appDeployCmd( args, opts ); | ||
|
||
expect( gates ).toHaveBeenCalledTimes( 1 ); | ||
|
||
expect( promptToContinue ).not.toHaveBeenCalled(); | ||
|
||
expect( uploadImportSqlFileToS3 ).toHaveBeenCalledTimes( 1 ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as Types from '../graphqlTypes'; | ||
|
||
export type StartDeployMutationVariables = Types.Exact< { | ||
input?: Types.InputMaybe< Types.AppEnvironmentDeployInput >; | ||
} >; | ||
|
||
export type StartDeployMutation = { | ||
__typename?: 'Mutation'; | ||
startDeploy?: { | ||
__typename?: 'AppEnvironmentDeployPayload'; | ||
message?: string | null; | ||
success?: boolean | null; | ||
app?: { __typename?: 'App'; id?: number | null; name?: string | null } | null; | ||
} | null; | ||
}; |
Oops, something went wrong.