@@ -5,9 +5,9 @@ import { cliux } from '@contentstack/cli-utilities';
55import fs from 'fs' ;
66import { FileUpload , BaseClass } from '../../../src/adapters' ;
77import { BaseCommand } from '../../../src/base-command' ;
8- import e from 'express' ;
98import { isNull } from 'util' ;
109import { log } from 'console' ;
10+ import { FileUploadMethod } from '../../../src/types/launch' ;
1111
1212describe ( 'File Upload' , ( ) => {
1313 let inquireStub , exitStub , prepareApiClientsStub , prepareConfigStub , getConfigStub ;
@@ -77,7 +77,23 @@ describe('File Upload', () => {
7777 } ) ;
7878
7979 describe ( 'Redeploy existing project' , ( ) => {
80- it ( 'should run file upload flow for existing project where flag passed is redeploy-latest' , async ( ) => {
80+ let sandbox ;
81+ let processExitStub ;
82+
83+ beforeEach ( ( ) => {
84+ sandbox = createSandbox ( ) ;
85+
86+ processExitStub = sandbox . stub ( process , 'exit' ) . callsFake ( ( code ) => {
87+ throw new Error ( code ) ;
88+ } ) ;
89+
90+ } ) ;
91+
92+ afterEach ( ( ) => {
93+ sandbox . restore ( ) ;
94+ } ) ;
95+
96+ it ( 'should run file upload flow successfully for existing project where flag passed is redeploy-latest' , async ( ) => {
8197 let adapterConstructorOptions = {
8298 config : {
8399 isExistingProject : true ,
@@ -98,7 +114,7 @@ describe('File Upload', () => {
98114 expect ( showSuggestionStub . calledOnce ) . to . be . true ;
99115 } ) ;
100116
101- it ( 'should run file upload flow for existing project where flag passed is redeploy-last-upload' , async ( ) => {
117+ it ( 'should run file upload flow successfully for existing project where flag passed is redeploy-last-upload' , async ( ) => {
102118 let adapterConstructorOptions = {
103119 config : {
104120 isExistingProject : true ,
@@ -118,8 +134,126 @@ describe('File Upload', () => {
118134 expect ( showDeploymentUrlStub . calledOnce ) . to . be . true ;
119135 expect ( showSuggestionStub . calledOnce ) . to . be . true ;
120136 } ) ;
121- } ) ;
122137
138+ it ( 'should exit with an error message when both --redeploy-last-upload and --redeploy-latest flags are passed' , async ( ) => {
139+ let adapterConstructorOptions = {
140+ config : {
141+ isExistingProject : true ,
142+ currentConfig : { uid : '123244' , organizationUid : 'bltxxxxxxxx' } ,
143+ 'redeploy-last-upload' : true ,
144+ 'redeploy-latest' : true ,
145+ } ,
146+ } ;
147+ let exitStatusCode ;
148+
149+ try {
150+ await new FileUpload ( adapterConstructorOptions ) . run ( ) ;
151+ } catch ( err ) {
152+ exitStatusCode = err . message ;
153+ }
154+
155+ expect ( processExitStub . calledOnceWithExactly ( 1 ) ) . to . be . true ;
156+ expect ( exitStatusCode ) . to . equal ( '1' ) ;
157+ expect ( initApolloClientStub . calledOnce ) . to . be . true ;
158+ expect ( createSignedUploadUrlStub . calledOnce ) . to . be . false ;
159+ expect ( archiveStub . calledOnce ) . to . be . false ;
160+ expect ( uploadFileStub . calledOnce ) . to . be . false ;
161+ expect ( createNewDeploymentStub . calledOnce ) . to . be . false ;
162+ expect ( prepareLaunchConfigStub . calledOnce ) . to . be . false ;
163+ expect ( showLogsStub . calledOnce ) . to . be . false ;
164+ expect ( showDeploymentUrlStub . calledOnce ) . to . be . false ;
165+ expect ( showSuggestionStub . calledOnce ) . to . be . false ;
166+ } ) ;
167+
168+ it ( 'should show prompt and successfully redeploy with "new file" if the option to redeploy with new file is selected, when --redeploy-latest and --redeploy-last-upload flags are not passed' , async ( ) => {
169+ let adapterConstructorOptions = {
170+ config : {
171+ isExistingProject : true ,
172+ currentConfig : { uid : '123244' , organizationUid : 'bltxxxxxxxx' } ,
173+ } ,
174+ } ;
175+ inquireStub . withArgs ( {
176+ type : 'confirm' ,
177+ name : 'deployLatestCommit' ,
178+ message : 'Do you want to redeploy this existing Launch project?' ,
179+ } ) . resolves ( true ) ;
180+ inquireStub . resolves ( FileUploadMethod . NewFile ) ;
181+
182+ await new FileUpload ( adapterConstructorOptions ) . run ( ) ;
183+
184+ expect ( initApolloClientStub . calledOnce ) . to . be . true ;
185+ expect ( createSignedUploadUrlStub . calledOnce ) . to . be . true ;
186+ expect ( archiveStub . calledOnce ) . to . be . true ;
187+ expect ( uploadFileStub . calledOnce ) . to . be . true ;
188+ expect ( createNewDeploymentStub . calledOnce ) . to . be . true ;
189+ expect ( prepareLaunchConfigStub . calledOnce ) . to . be . true ;
190+ expect ( showLogsStub . calledOnce ) . to . be . true ;
191+ expect ( showDeploymentUrlStub . calledOnce ) . to . be . true ;
192+ expect ( showSuggestionStub . calledOnce ) . to . be . true ;
193+ } ) ;
194+
195+ it ( 'should show prompt and successfully redeploy with "last file upload" if the option to redeploy with last file upload is selected, when --redeploy-latest and --redeploy-last-upload flags are not passed' , async ( ) => {
196+ let adapterConstructorOptions = {
197+ config : {
198+ isExistingProject : true ,
199+ currentConfig : { uid : '123244' , organizationUid : 'bltxxxxxxxx' } ,
200+ } ,
201+ } ;
202+ inquireStub . withArgs ( {
203+ type : 'confirm' ,
204+ name : 'deployLatestCommit' ,
205+ message : 'Do you want to redeploy this existing Launch project?' ,
206+ } ) . resolves ( true ) ;
207+ inquireStub . resolves ( FileUploadMethod . LastFileUpload ) ;
208+
209+ await new FileUpload ( adapterConstructorOptions ) . run ( ) ;
210+
211+ expect ( initApolloClientStub . calledOnce ) . to . be . true ;
212+ expect ( createSignedUploadUrlStub . calledOnce ) . to . be . false ;
213+ expect ( archiveStub . calledOnce ) . to . be . false ;
214+ expect ( uploadFileStub . calledOnce ) . to . be . false ;
215+ expect ( createNewDeploymentStub . calledOnce ) . to . be . true ;
216+ expect ( prepareLaunchConfigStub . calledOnce ) . to . be . true ;
217+ expect ( showLogsStub . calledOnce ) . to . be . true ;
218+ expect ( showDeploymentUrlStub . calledOnce ) . to . be . true ;
219+ expect ( showSuggestionStub . calledOnce ) . to . be . true ;
220+ } ) ;
221+
222+ it ( 'should exit if "No" is selected for prompt to redeploy, when --redeploy-latest and --redeploy-last-upload flags are not passed' , async ( ) => {
223+ let adapterConstructorOptions = {
224+ config : {
225+ isExistingProject : true ,
226+ currentConfig : { uid : '123244' , organizationUid : 'bltxxxxxxxx' } ,
227+ } ,
228+ } ;
229+ inquireStub . withArgs ( {
230+ type : 'confirm' ,
231+ name : 'deployLatestCommit' ,
232+ message : 'Do you want to redeploy this existing Launch project?' ,
233+ } ) . resolves ( false ) ;
234+ let exitStatusCode ;
235+
236+ try {
237+ await new FileUpload ( adapterConstructorOptions ) . run ( ) ;
238+ } catch ( err ) {
239+ exitStatusCode = err . message ;
240+ }
241+
242+ expect ( processExitStub . calledOnceWithExactly ( 1 ) ) . to . be . true ;
243+ expect ( exitStatusCode ) . to . equal ( '1' ) ;
244+ expect ( initApolloClientStub . calledOnce ) . to . be . true ;
245+ expect ( createSignedUploadUrlStub . calledOnce ) . to . be . false ;
246+ expect ( archiveStub . calledOnce ) . to . be . false ;
247+ expect ( uploadFileStub . calledOnce ) . to . be . false ;
248+ expect ( createNewDeploymentStub . calledOnce ) . to . be . false ;
249+ expect ( prepareLaunchConfigStub . calledOnce ) . to . be . false ;
250+ expect ( showLogsStub . calledOnce ) . to . be . false ;
251+ expect ( showDeploymentUrlStub . calledOnce ) . to . be . false ;
252+ expect ( showSuggestionStub . calledOnce ) . to . be . false ;
253+ } ) ;
254+
255+ } ) ;
256+
123257 describe ( 'Deploy new project' , ( ) => {
124258 let adapterConstructorOptions = {
125259 config : {
0 commit comments