-
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.
- Loading branch information
1 parent
edc0bad
commit 78db9ae
Showing
4 changed files
with
348 additions
and
173 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,106 @@ | ||
import { deployAppCmd, renameFile, gates, promptToContinue } from '../../src/bin/vip-deploy-app'; | ||
import * as exit from '../../src/lib/cli/exit'; | ||
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( 'fs', () => ( { | ||
...jest.requireActual( 'fs' ), | ||
existsSync: jest.fn().mockReturnValue( true ), | ||
} ) ); | ||
|
||
jest.mock( '../../src/bin/vip-deploy-app', () => ( { | ||
...jest.requireActual( '../../src/bin/vip-deploy-app' ), | ||
gates: jest.fn(), | ||
renameFile: jest.fn(), | ||
promptToContinue: jest.fn(), | ||
} ) ); | ||
|
||
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( () => {} ); | ||
|
||
const args = [ '/vip/skeleton.zip' ]; | ||
const opts = { | ||
app: { | ||
id: 1, | ||
organization: { | ||
id: 2, | ||
}, | ||
}, | ||
env: { | ||
id: 3, | ||
type: 'develop', | ||
}, | ||
}; | ||
|
||
describe( 'vip-deploy-app', () => { | ||
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( 'deployAppCmd', () => { | ||
it( 'should call validation functions', async () => { | ||
await deployAppCmd( args, opts ); | ||
|
||
expect( gates ).toHaveBeenCalledTimes( 1 ); | ||
} ); | ||
|
||
it( 'should not prompt if --force is passed in', async () => { | ||
opts.force = true; | ||
await deployAppCmd( args, opts ); | ||
|
||
expect( promptToContinue ).not.toHaveBeenCalled(); | ||
} ); | ||
|
||
it( 'should rename file', async () => { | ||
await deployAppCmd( args, opts ); | ||
|
||
expect( renameFile ).toHaveBeenCalledTimes( 1 ); | ||
} ); | ||
} ); | ||
} ); |
Oops, something went wrong.