@@ -80,7 +80,7 @@ describe("syncSpecsLogs", () => {
8080
8181 it ( 'should return proper request option for polling' , ( ) => {
8282 let options = getOptions ( auth , build_id ) ;
83- expect ( options . url ) . to . equal ( `${ config . buildUrl } ${ build_id } ` ) ;
83+ expect ( options . url ) . to . equal ( `${ config . buildUrlV2 } ${ build_id } ` ) ;
8484 expect ( options . auth . user ) . to . equal ( auth . username ) ;
8585 expect ( options . auth . password ) . to . equal ( auth . access_key ) ;
8686 expect ( options . headers [ "Content-Type" ] ) . to . equal ( "application/json" ) ;
@@ -216,35 +216,38 @@ describe("syncSpecsLogs", () => {
216216
217217 context ( "showSpecsStatus" , ( ) => {
218218 const showSpecsStatus = syncSpecsLogs . __get__ ( "showSpecsStatus" ) ;
219+ const buildCreatedStatusCode = 202
220+ const buildRunningStatusCode = 204
221+ const buildCompletedStatusCode = 200
219222
220223 it ( 'should not print initial log for running specs when it is the 1st polling response' , ( ) => {
221- let data = JSON . stringify ( [ "created" ] )
224+ let data = JSON . stringify ( { "specData" : [ "created" ] , "buildData" : { "duration" : "NA" , "parallels" : "NA" } } )
222225 var printInitialLog = sandbox . stub ( ) ;
223226 syncSpecsLogs . __set__ ( 'printInitialLog' , printInitialLog ) ;
224227
225- showSpecsStatus ( data ) ;
228+ showSpecsStatus ( data , buildCreatedStatusCode ) ;
226229
227230 expect ( printInitialLog . calledOnce ) . to . be . false ;
228231 } ) ;
229232
230233 it ( 'should print spec details when spec related data is sent in polling response' , ( ) => {
231234 let specResult = JSON . stringify ( { "path" : "path" } )
232- let data = JSON . stringify ( [ specResult ] )
235+ let data = JSON . stringify ( { "specData" : [ specResult ] , "buildData" : { "duration" : "NA" , "parallels" : "NA" } } )
233236 var printSpecData = sandbox . stub ( ) ;
234237 syncSpecsLogs . __set__ ( 'printSpecData' , printSpecData ) ;
235- showSpecsStatus ( data ) ;
238+ showSpecsStatus ( data , buildRunningStatusCode ) ;
236239 expect ( printSpecData . calledOnce ) . to . be . true ;
237240 } ) ;
238241
239242 it ( 'should print initial and spec details when spec related data is sent in polling response' , ( ) => {
240243 let specResult = JSON . stringify ( { "path" : "path" } )
241244 syncSpecsLogs . __set__ ( 'buildStarted' , false )
242- let data = JSON . stringify ( [ "created" , specResult ] )
245+ let data = JSON . stringify ( { "specData" : [ specResult ] , "buildData" : { "duration" : "NA" , "parallels" : "NA" } } )
243246 var printSpecData = sandbox . stub ( ) ;
244247 syncSpecsLogs . __set__ ( 'printSpecData' , printSpecData ) ;
245248 var printInitialLog = sandbox . stub ( ) ;
246249 syncSpecsLogs . __set__ ( 'printInitialLog' , printInitialLog ) ;
247- showSpecsStatus ( data ) ;
250+ showSpecsStatus ( data , buildCreatedStatusCode ) ;
248251 expect ( printSpecData . calledOnce ) . to . be . true ;
249252 expect ( printInitialLog . calledOnce ) . to . be . true ;
250253 } ) ;
@@ -253,18 +256,38 @@ describe("syncSpecsLogs", () => {
253256 let specResult = JSON . stringify ( { "path" : "path" } )
254257 let customError = { id : "custom_error_1" , type : "custom_errors_to_print" , level : "warn" , should_be_unique : true , message : "custom error message" }
255258 syncSpecsLogs . __set__ ( 'buildStarted' , false )
256- let data = JSON . stringify ( [ "created" , specResult , customError ] )
259+ let data = JSON . stringify ( { "specData" : [ "created" , specResult , customError ] , "buildData" : { "duration" : "NA" , "parallels" : "NA" } } )
257260 var printSpecData = sandbox . stub ( ) ;
258261 syncSpecsLogs . __set__ ( 'printSpecData' , printSpecData ) ;
259262 var printInitialLog = sandbox . stub ( ) ;
260263 syncSpecsLogs . __set__ ( 'printInitialLog' , printInitialLog ) ;
261264 var addCustomErrorToPrint = sandbox . stub ( ) ;
262265 syncSpecsLogs . __set__ ( 'addCustomErrorToPrint' , addCustomErrorToPrint ) ;
263- showSpecsStatus ( data ) ;
266+ showSpecsStatus ( data , buildRunningStatusCode ) ;
264267 expect ( printSpecData . calledOnce ) . to . be . true ;
265268 expect ( printInitialLog . calledOnce ) . to . be . true ;
266269 expect ( addCustomErrorToPrint . calledOnce ) . to . be . true ;
267270 } ) ;
271+
272+ it ( 'should add custom error, print initial and spec details when spec related data and duration is sent in polling response' , ( ) => {
273+ let specResult = JSON . stringify ( { "path" : "path" } )
274+ let customError = { id : "custom_error_1" , type : "custom_errors_to_print" , level : "warn" , should_be_unique : true , message : "custom error message" }
275+ var loggerInfoSpy = sinon . spy ( logger , 'info' ) ;
276+ syncSpecsLogs . __set__ ( 'buildStarted' , false )
277+ let data = JSON . stringify ( { "specData" : [ "created" , specResult , customError ] , "buildData" : { "duration" : { "total_duration" : "87" } , "parallels" : "2" } } )
278+ var printSpecData = sandbox . stub ( ) ;
279+ syncSpecsLogs . __set__ ( 'printSpecData' , printSpecData ) ;
280+ var printInitialLog = sandbox . stub ( ) ;
281+ syncSpecsLogs . __set__ ( 'printInitialLog' , printInitialLog ) ;
282+ var addCustomErrorToPrint = sandbox . stub ( ) ;
283+ syncSpecsLogs . __set__ ( 'addCustomErrorToPrint' , addCustomErrorToPrint ) ;
284+ showSpecsStatus ( data , buildCompletedStatusCode ) ;
285+ expect ( printSpecData . calledOnce ) . to . be . true ;
286+ expect ( printInitialLog . calledOnce ) . to . be . true ;
287+ expect ( addCustomErrorToPrint . calledOnce ) . to . be . true ;
288+ sinon . assert . calledWith ( loggerInfoSpy , 'Done in 87 seconds with 2 parallels.\n' ) ;
289+ loggerInfoSpy . restore ( ) ;
290+ } ) ;
268291 } ) ;
269292
270293 context ( "printSpecsStatus" , ( ) => {
0 commit comments