@@ -5,7 +5,6 @@ import { cliux } from '@contentstack/cli-utilities';
55import { githubAdapterMockData } from '../mock/index' ;
66import { GitHub , BaseClass } from '../../../src/adapters' ;
77import { BaseCommand } from '../../../src/base-command' ;
8- import { exit } from 'process' ;
98import fs from 'fs' ;
109
1110describe ( 'GitHub' , ( ) => {
@@ -79,34 +78,116 @@ describe('GitHub', () => {
7978 } ) ;
8079
8180 describe ( 'Redeploy existing project' , ( ) => {
82- it ( 'should abort github flow for existing project and flag redeploy-last-upload is passed' , async ( ) => {
81+ let sandbox ;
82+ let processExitStub ;
83+
84+ beforeEach ( ( ) => {
85+ sandbox = createSandbox ( ) ;
86+
87+ processExitStub = sandbox . stub ( process , 'exit' ) . callsFake ( ( code ) => {
88+ throw new Error ( code ) ;
89+ } ) ;
90+
91+ } ) ;
92+
93+ afterEach ( ( ) => {
94+ sandbox . restore ( ) ;
95+ } ) ;
96+
97+ it ( 'should successfully run github flow for existing project when flag redeploy-latest is passed ' , async ( ) => {
98+ let adapterConstructorOptions = {
99+ config : {
100+ isExistingProject : true ,
101+ 'redeploy-latest' : true ,
102+ } ,
103+ } ;
104+
105+ await new GitHub ( adapterConstructorOptions ) . run ( ) ;
106+
107+ expect ( initApolloClientStub . calledOnce ) . to . be . true ;
108+ expect ( createNewDeploymentStub . calledOnce ) . to . be . true ;
109+ expect ( prepareLaunchConfigStub . calledOnce ) . to . be . true ;
110+ expect ( showLogsStub . calledOnce ) . to . be . true ;
111+ expect ( showDeploymentUrlStub . calledOnce ) . to . be . true ;
112+ expect ( showSuggestionStub . calledOnce ) . to . be . true ;
113+ } ) ;
114+
115+ it ( 'should abort github flow for existing project when flag redeploy-last-upload is passed' , async ( ) => {
83116 const adapterConstructorOptions = {
84117 config : {
85118 isExistingProject : true ,
86119 'redeploy-last-upload' : true ,
87120 } ,
88121 } ;
89- const exitStub = stub ( process , 'exit' ) ;
90- const githubInstance = new GitHub ( adapterConstructorOptions ) ;
122+ let exitStatusCode ;
91123
92- await githubInstance . handleExistingProject ( ) ;
124+ try {
125+ await new GitHub ( adapterConstructorOptions ) . run ( ) ;
126+ } catch ( err ) {
127+ exitStatusCode = err . message ;
128+ }
93129
94- expect ( exitStub . calledOnceWithExactly ( 1 ) ) . to . be . true ;
130+ expect ( processExitStub . calledOnceWithExactly ( 1 ) ) . to . be . true ;
131+ expect ( exitStatusCode ) . to . equal ( '1' ) ;
132+ expect ( initApolloClientStub . calledOnce ) . to . be . true ;
133+ expect ( createNewDeploymentStub . calledOnce ) . to . be . false ;
134+ expect ( prepareLaunchConfigStub . calledOnce ) . to . be . false ;
135+ expect ( showLogsStub . calledOnce ) . to . be . false ;
136+ expect ( showDeploymentUrlStub . calledOnce ) . to . be . false ;
137+ expect ( showSuggestionStub . calledOnce ) . to . be . false ;
95138 } ) ;
96139
97- it ( 'should run github flow for existing project and flag redeploy- latest is passed ' , async ( ) => {
98- let adapterConstructorOptions = {
140+ it ( 'should show prompt and successfully redeploy with "latest commit" if the option to redeploy is selected, when --redeploy- latest flag is not passed ' , async ( ) => {
141+ const adapterConstructorOptions = {
99142 config : {
100- isExistingProject : true ,
101- 'redeploy-latest' : true ,
143+ isExistingProject : true
102144 } ,
103145 } ;
146+ inquireStub . withArgs ( {
147+ type : 'confirm' ,
148+ name : 'deployLatestCommit' ,
149+ message : 'Redeploy latest commit?' ,
150+ } ) . resolves ( true ) ;
104151
105152 await new GitHub ( adapterConstructorOptions ) . run ( ) ;
106153
107154 expect ( initApolloClientStub . calledOnce ) . to . be . true ;
108155 expect ( createNewDeploymentStub . calledOnce ) . to . be . true ;
156+ expect ( prepareLaunchConfigStub . calledOnce ) . to . be . true ;
157+ expect ( showLogsStub . calledOnce ) . to . be . true ;
158+ expect ( showDeploymentUrlStub . calledOnce ) . to . be . true ;
159+ expect ( showSuggestionStub . calledOnce ) . to . be . true ;
109160 } ) ;
161+
162+ it ( 'should exit if "No" is selected for prompt to redeploy, when --redeploy-latest flag is not passed' , async ( ) => {
163+ const adapterConstructorOptions = {
164+ config : {
165+ isExistingProject : true
166+ } ,
167+ } ;
168+ inquireStub . withArgs ( {
169+ type : 'confirm' ,
170+ name : 'deployLatestCommit' ,
171+ message : 'Redeploy latest commit?' ,
172+ } ) . resolves ( false ) ;
173+ let exitStatusCode ;
174+
175+ try {
176+ await new GitHub ( adapterConstructorOptions ) . run ( ) ;
177+ } catch ( err ) {
178+ exitStatusCode = err . message ;
179+ }
180+
181+ expect ( processExitStub . calledOnceWithExactly ( 1 ) ) . to . be . true ;
182+ expect ( exitStatusCode ) . to . equal ( '1' ) ;
183+ expect ( initApolloClientStub . calledOnce ) . to . be . true ;
184+ expect ( createNewDeploymentStub . calledOnce ) . to . be . false ;
185+ expect ( prepareLaunchConfigStub . calledOnce ) . to . be . false ;
186+ expect ( showLogsStub . calledOnce ) . to . be . false ;
187+ expect ( showDeploymentUrlStub . calledOnce ) . to . be . false ;
188+ expect ( showSuggestionStub . calledOnce ) . to . be . false ;
189+ } ) ;
190+
110191 } ) ;
111192
112193 describe ( 'Deploy new project' , ( ) => {
0 commit comments