11'use strict' ;
22
33const Assert = require ( 'chai' ) . assert ;
4- const { Before, Given, Then } = require ( '@cucumber/cucumber' ) ;
4+ const { Before, Given, Then, When } = require ( '@cucumber/cucumber' ) ;
55const request = require ( 'screwdriver-request' ) ;
66const sdapi = require ( '../support/sdapi' ) ;
77
@@ -16,13 +16,50 @@ Before(
1616 this . repoName = 'functional-metadata' ;
1717 this . pipelineId = null ;
1818 this . eventId = null ;
19+ this . previousEventId = null ;
1920 this . meta = null ;
21+ this . buildMeta = null ;
2022 this . jwt = null ;
2123 }
2224) ;
2325
2426Given ( / ^ a m e t a d a t a s t a r t s w i t h a n e m p t y o b j e c t $ / , { timeout : TIMEOUT } , ( ) => null ) ;
2527
28+ When ( / ^ t h e B O O Z j o b i s " ( d i s a b l e d | e n a b l e d ) " $ / , { timeout : TIMEOUT } , function step ( jobState ) {
29+ const jobName = 'fourth' ;
30+
31+ return request ( {
32+ url : `${ this . instance } /${ this . namespace } /pipelines/${ this . pipelineId } /jobs?jobName=${ jobName } ` ,
33+ method : 'GET' ,
34+ context : {
35+ token : this . jwt
36+ }
37+ } )
38+ . then ( resp => {
39+ Assert . equal ( resp . statusCode , 200 ) ;
40+ Assert . equal ( resp . body . length , 1 ) ;
41+ Assert . equal ( resp . body [ 0 ] . name , jobName ) ;
42+
43+ return resp . body [ 0 ] . id ;
44+ } )
45+ . then ( jobId => {
46+ return request ( {
47+ url : `${ this . instance } /${ this . namespace } /jobs/${ jobId } ` ,
48+ method : 'PUT' ,
49+ json : {
50+ state : jobState . toUpperCase ( ) ,
51+ stateChangeMessage : `${ jobState } for testing`
52+ } ,
53+ context : {
54+ token : this . jwt
55+ }
56+ } ) ;
57+ } )
58+ . then ( resp => {
59+ Assert . equal ( resp . statusCode , 200 ) ;
60+ } ) ;
61+ } ) ;
62+
2663Then ( / ^ t h e " ( B A R | B A Z ) " j o b i s s t a r t e d $ / , { timeout : TIMEOUT } , function step ( jobName ) {
2764 switch ( jobName ) {
2865 case 'BAR' :
@@ -46,6 +83,8 @@ Then(/^the "(BAR|BAZ)" job is started$/, { timeout: TIMEOUT }, function step(job
4683 } )
4784 . then ( build => {
4885 this . buildId = build . id ;
86+ this . eventId = build . eventId ;
87+ this . previousEventId = build . eventId ;
4988 } ) ;
5089} ) ;
5190
@@ -54,15 +93,18 @@ Then(/^add the { "(.*)": "(.*)" } to metadata/, function step(key, value) {
5493 this . expectedMeta [ key ] = value ;
5594} ) ;
5695
57- Then ( / ^ i n t h e b u i l d , t h e { " (?: .* ) " : " (?: .* ) " } i s a v a i l a b l e f r o m m e t a d a t a $ / , ( ) => null ) ;
58-
5996Then ( / ^ t h e b u i l d s u c c e e d e d $ / , { timeout : TIMEOUT } , function step ( ) {
6097 return this . waitForBuild ( this . buildId ) . then ( resp => {
98+ this . buildMeta = resp . body . meta ;
6199 Assert . equal ( resp . body . status , 'SUCCESS' ) ;
62100 Assert . equal ( resp . statusCode , 200 ) ;
63101 } ) ;
64102} ) ;
65103
104+ Then ( / ^ i n t h e b u i l d , t h e { " ( .* ) " : " ( .* ) " } i s a v a i l a b l e f r o m m e t a d a t a $ / , function step ( key , value ) {
105+ Assert . equal ( this . buildMeta [ key ] , value ) ;
106+ } ) ;
107+
66108Then ( / ^ t h e e v e n t i s d o n e $ / , { timeout : TIMEOUT } , function step ( ) {
67109 return request ( {
68110 url : `${ this . instance } /${ this . namespace } /jobs/${ this . thirdJobId } /builds` ,
@@ -85,3 +127,44 @@ Then(/^a record of the metadata is stored$/, { timeout: TIMEOUT }, function step
85127 Assert . equal ( this . meta [ key ] , this . expectedMeta [ key ] ) ;
86128 } ) ;
87129} ) ;
130+
131+ When ( / ^ t h e ( d e t a c h e d ) ? " ( B A M | B O O Z ) " j o b i s s t a r t e d $ / , { timeout : TIMEOUT } , function step ( detached , jobName ) {
132+ let startFrom = jobName ;
133+
134+ if ( detached ) {
135+ startFrom = 'detached' ;
136+ } else {
137+ startFrom = 'fourth' ;
138+ }
139+
140+ return request ( {
141+ url : `${ this . instance } /${ this . namespace } /events` ,
142+ method : 'POST' ,
143+ json : {
144+ pipelineId : this . pipelineId ,
145+ startFrom,
146+ parentEventId : this . previousEventId ,
147+ groupEventId : this . previousEventId
148+ } ,
149+ context : {
150+ token : this . jwt
151+ }
152+ } )
153+ . then ( resp => {
154+ Assert . equal ( resp . statusCode , 201 ) ;
155+ this . eventId = resp . body . id ;
156+ } )
157+ . then ( ( ) =>
158+ request ( {
159+ url : `${ this . instance } /${ this . namespace } /events/${ this . eventId } /builds` ,
160+ method : 'GET' ,
161+ context : {
162+ token : this . jwt
163+ }
164+ } )
165+ )
166+ . then ( resp => {
167+ Assert . equal ( resp . statusCode , 200 ) ;
168+ this . buildId = resp . body [ 0 ] . id ;
169+ } ) ;
170+ } ) ;
0 commit comments