@@ -11,31 +11,32 @@ import UnifyReleaseService from "../../src/services/unifyReleaseService";
1111
1212//# Tests
1313describe ( 'UnifyReleaseService' , ( ) => {
14- var configStub : StubbedInstance < IAzureDevOpsConfiguration > = null ;
14+ var configStub : IAzureDevOpsConfiguration = null ;
1515 beforeEach ( ( ) => {
16- configStub = StubInterface < IAzureDevOpsConfiguration > ( ) ;
17- configStub . teamFoundationCollectionUri = "organizationUrl" ;
18- configStub . teamFoundationProject = "project" ;
19- configStub . accessToken = "token" ;
20- configStub . waitForAllTriggeredBuilds = true ;
21- configStub . currentBuildId = 1 ;
22- configStub . releaseTag = "releaseTag" ;
23- configStub . definition1 = "1" ;
24- configStub . definition2 = "2" ;
25- configStub . definition3 = "3" ;
26- configStub . definition4 = "4" ;
27- configStub . definition5 = "5" ;
16+ configStub = {
17+ teamFoundationCollectionUri : "organizationUrl" ,
18+ teamFoundationProject : "project" ,
19+ accessToken : "token" ,
20+ waitForAllTriggeredBuilds : true ,
21+ currentBuildId : 1 ,
22+ releaseTag : "releaseTag" ,
23+ definition1 : "1" ,
24+ definition2 : "2" ,
25+ definition3 : "3" ,
26+ definition4 : "4" ,
27+ definition5 : "5" ,
28+ releaseOnCancel : false ,
29+ releaseOnError : false
30+ }
2831 } )
2932
3033 describe ( 'unifyRelease' , ( ) => {
31- var relatedBuildsStub = null ;
3234 var buildServiceStub : StubbedInstance < IBuildService > = null
3335 beforeEach ( ( ) => {
34- relatedBuildsStub = new Map < string , Build > ( ) ;
3536 buildServiceStub = StubInterface < IBuildService > ( ) ;
3637 } )
3738
38- function createBuildServiceStubs ( relatedBuilds : Build [ ] ) {
39+ function setBuildServiceStubs ( relatedBuilds : Build [ ] ) {
3940 let triggeredBuild : Build = {
4041 id : 1 ,
4142 definition : {
@@ -44,8 +45,11 @@ describe('UnifyReleaseService', () => {
4445 status : BuildStatus . InProgress ,
4546 sourceVersion : "sourceVersion"
4647 } ;
47-
48- var allBuilds = [ triggeredBuild ] . concat ( relatedBuilds ) ;
48+ var relatedBuildsStub = new Map < string , Build > ( ) ;
49+ relatedBuildsStub . set ( triggeredBuild . definition . id . toString ( ) , triggeredBuild ) ;
50+ relatedBuilds . forEach ( build => {
51+ relatedBuildsStub . set ( build . definition . id . toString ( ) , build ) ;
52+ } ) ;
4953
5054 buildServiceStub . getBuildInfo
5155 . withArgs (
@@ -56,8 +60,8 @@ describe('UnifyReleaseService', () => {
5660 . withArgs (
5761 configStub . teamFoundationCollectionUri , configStub . accessToken , configStub . teamFoundationProject , "sourceVersion" , configStub . waitForAllTriggeredBuilds , [ configStub . definition1 , configStub . definition2 , configStub . definition3 , configStub . definition4 , configStub . definition5 ] )
5862 . returns ( Promise . resolve ( relatedBuildsStub ) ) ;
59-
6063 }
64+
6165 it ( "Should create tag if all last related builds are Completed and Succeeded or Partially Suceeded" , async ( ) => {
6266
6367 let build2 : Build = {
@@ -79,8 +83,8 @@ describe('UnifyReleaseService', () => {
7983 sourceVersion : "sourceVersion"
8084 } ;
8185
82- createBuildServiceStubs ( [ build2 , build3 ] ) ;
83-
86+ setBuildServiceStubs ( [ build2 , build3 ] ) ;
87+
8488 let buildServiceCreateTagSpy = buildServiceStub . addBuildTag
8589 . withArgs ( configStub . teamFoundationCollectionUri , configStub . teamFoundationProject , configStub . accessToken , configStub . currentBuildId , configStub . releaseTag ) ;
8690
@@ -91,45 +95,209 @@ describe('UnifyReleaseService', () => {
9195 expect ( buildServiceCreateTagSpy . calledOnce ) . equal ( true ) ;
9296 } ) ;
9397
94- it ( "Should not create tag if there's a last Build Cancelling and with flag release on cancel on" , async ( ) => {
95- expect ( true , "Not Implemented" ) . false ;
98+ it ( "Should create tag if there's a last Build Cancelling and with flag release on cancel on" , async ( ) => {
99+ let build2 : Build = {
100+ id : 2 ,
101+ definition : {
102+ id : 2 ,
103+ } ,
104+ status : BuildStatus . Cancelling ,
105+ sourceVersion : "sourceVersion"
106+ } ;
107+
108+ setBuildServiceStubs ( [ build2 ] ) ;
109+
110+ let buildServiceCreateTagSpy = buildServiceStub . addBuildTag
111+ . withArgs ( configStub . teamFoundationCollectionUri , configStub . teamFoundationProject , configStub . accessToken , configStub . currentBuildId , configStub . releaseTag ) ;
112+
113+ configStub . releaseOnCancel = true ;
114+ var unifyReleaseService = new UnifyReleaseService ( buildServiceStub , configStub ) ;
115+
116+ await unifyReleaseService . unifyRelease ( ) ;
117+
118+ expect ( buildServiceCreateTagSpy . calledOnce ) . equal ( true ) ;
96119 } ) ;
97120
98121 it ( "Should not create tag if there's a last Build Cancelling and with flag release on cancel off" , async ( ) => {
99- expect ( true , "Not Implemented" ) . false ;
122+ let build2 : Build = {
123+ id : 2 ,
124+ definition : {
125+ id : 2 ,
126+ } ,
127+ status : BuildStatus . Cancelling ,
128+ sourceVersion : "sourceVersion"
129+ } ;
130+
131+ setBuildServiceStubs ( [ build2 ] ) ;
132+
133+ let buildServiceCreateTagSpy = buildServiceStub . addBuildTag
134+ . withArgs ( configStub . teamFoundationCollectionUri , configStub . teamFoundationProject , configStub . accessToken , configStub . currentBuildId , configStub . releaseTag ) ;
135+
136+ configStub . releaseOnCancel = false ;
137+ var unifyReleaseService = new UnifyReleaseService ( buildServiceStub , configStub ) ;
138+
139+ await unifyReleaseService . unifyRelease ( ) ;
140+
141+ expect ( buildServiceCreateTagSpy . calledOnce ) . equal ( false ) ;
100142 } ) ;
101143
102- it ( "Should not create tag if there's a last Build Cancelling and with flag release on cancel on" , async ( ) => {
103- expect ( true , "Not Implemented" ) . false ;
144+ it ( "Should create tag if there's a last Build Cancelled and with flag release on cancel on" , async ( ) => {
145+ let build2 : Build = {
146+ id : 2 ,
147+ definition : {
148+ id : 2 ,
149+ } ,
150+ result : BuildResult . Canceled ,
151+ sourceVersion : "sourceVersion"
152+ } ;
153+
154+ setBuildServiceStubs ( [ build2 ] ) ;
155+
156+ let buildServiceCreateTagSpy = buildServiceStub . addBuildTag
157+ . withArgs ( configStub . teamFoundationCollectionUri , configStub . teamFoundationProject , configStub . accessToken , configStub . currentBuildId , configStub . releaseTag ) ;
158+
159+ configStub . releaseOnCancel = true ;
160+ var unifyReleaseService = new UnifyReleaseService ( buildServiceStub , configStub ) ;
161+
162+ await unifyReleaseService . unifyRelease ( ) ;
163+
164+ expect ( buildServiceCreateTagSpy . calledOnce ) . equal ( true ) ;
104165 } ) ;
105166
106- it ( "Should not create tag if there's a last Build cancelled and with flag release on cancel off" , async ( ) => {
107- expect ( true , "Not Implemented" ) . false ;
167+ it ( "Should not create tag if there's a last Build Cancelled and with flag release on cancel off" , async ( ) => {
168+ let build2 : Build = {
169+ id : 2 ,
170+ definition : {
171+ id : 2 ,
172+ } ,
173+ result : BuildResult . Canceled ,
174+ sourceVersion : "sourceVersion"
175+ } ;
176+
177+ setBuildServiceStubs ( [ build2 ] ) ;
178+
179+ let buildServiceCreateTagSpy = buildServiceStub . addBuildTag
180+ . withArgs ( configStub . teamFoundationCollectionUri , configStub . teamFoundationProject , configStub . accessToken , configStub . currentBuildId , configStub . releaseTag ) ;
181+
182+ configStub . releaseOnCancel = false ;
183+ var unifyReleaseService = new UnifyReleaseService ( buildServiceStub , configStub ) ;
184+
185+ await unifyReleaseService . unifyRelease ( ) ;
186+
187+ expect ( buildServiceCreateTagSpy . calledOnce ) . equal ( false ) ;
108188 } ) ;
109189
110- it ( "Should not create tag if there's a last Build failed and with flag release on failure on" , async ( ) => {
111- expect ( true , "Not Implemented" ) . false ;
190+ it ( "Should create tag if there's a last Build failed and with flag release on failure on" , async ( ) => {
191+ let build2 : Build = {
192+ id : 2 ,
193+ definition : {
194+ id : 2 ,
195+ } ,
196+ result : BuildResult . Failed ,
197+ sourceVersion : "sourceVersion"
198+ } ;
199+
200+ setBuildServiceStubs ( [ build2 ] ) ;
201+
202+ let buildServiceCreateTagSpy = buildServiceStub . addBuildTag
203+ . withArgs ( configStub . teamFoundationCollectionUri , configStub . teamFoundationProject , configStub . accessToken , configStub . currentBuildId , configStub . releaseTag ) ;
204+
205+ configStub . releaseOnError = true ;
206+ var unifyReleaseService = new UnifyReleaseService ( buildServiceStub , configStub ) ;
207+
208+ await unifyReleaseService . unifyRelease ( ) ;
209+
210+ expect ( buildServiceCreateTagSpy . calledOnce ) . equal ( true ) ;
112211 } ) ;
113212
114213 it ( "Should not create tag if there's a last Build failed and with flag release on failure off" , async ( ) => {
115- expect ( true , "Not Implemented" ) . false ;
116- } ) ;
214+ let build2 : Build = {
215+ id : 2 ,
216+ definition : {
217+ id : 2 ,
218+ } ,
219+ result : BuildResult . Failed ,
220+ sourceVersion : "sourceVersion"
221+ } ;
117222
223+ setBuildServiceStubs ( [ build2 ] ) ;
118224
119- it ( "Should not create tag if there's a last Build with Status Queued" , async ( ) => {
120- expect ( true , "Not Implemented" ) . false ;
225+ let buildServiceCreateTagSpy = buildServiceStub . addBuildTag
226+ . withArgs ( configStub . teamFoundationCollectionUri , configStub . teamFoundationProject , configStub . accessToken , configStub . currentBuildId , configStub . releaseTag ) ;
227+
228+ configStub . releaseOnError = false ;
229+ var unifyReleaseService = new UnifyReleaseService ( buildServiceStub , configStub ) ;
230+
231+ await unifyReleaseService . unifyRelease ( ) ;
232+
233+ expect ( buildServiceCreateTagSpy . calledOnce ) . equal ( false ) ;
121234 } ) ;
122235
236+
123237 it ( "Should not create tag if there's a last Build with Status NotStarted" , async ( ) => {
124- expect ( true , "Not Implemented" ) . false ;
238+ let build2 : Build = {
239+ id : 2 ,
240+ definition : {
241+ id : 2 ,
242+ } ,
243+ status : BuildStatus . NotStarted ,
244+ sourceVersion : "sourceVersion"
245+ } ;
246+
247+ setBuildServiceStubs ( [ build2 ] ) ;
248+
249+ let buildServiceCreateTagSpy = buildServiceStub . addBuildTag
250+ . withArgs ( configStub . teamFoundationCollectionUri , configStub . teamFoundationProject , configStub . accessToken , configStub . currentBuildId , configStub . releaseTag ) ;
251+
252+ var unifyReleaseService = new UnifyReleaseService ( buildServiceStub , configStub ) ;
253+
254+ await unifyReleaseService . unifyRelease ( ) ;
255+
256+ expect ( buildServiceCreateTagSpy . calledOnce ) . equal ( false ) ;
125257 } ) ;
126258
127259 it ( "Should not create tag if there's a last Build with Status InProgress" , async ( ) => {
128- expect ( true , "Not Implemented" ) . false ;
260+ let build2 : Build = {
261+ id : 2 ,
262+ definition : {
263+ id : 2 ,
264+ } ,
265+ status : BuildStatus . InProgress ,
266+ sourceVersion : "sourceVersion"
267+ } ;
268+
269+ setBuildServiceStubs ( [ build2 ] ) ;
270+
271+ let buildServiceCreateTagSpy = buildServiceStub . addBuildTag
272+ . withArgs ( configStub . teamFoundationCollectionUri , configStub . teamFoundationProject , configStub . accessToken , configStub . currentBuildId , configStub . releaseTag ) ;
273+
274+ var unifyReleaseService = new UnifyReleaseService ( buildServiceStub , configStub ) ;
275+
276+ await unifyReleaseService . unifyRelease ( ) ;
277+
278+ expect ( buildServiceCreateTagSpy . calledOnce ) . equal ( false ) ;
129279 } ) ;
130280
131281 it ( "Should not create tag if there's a last Build with Status PostPoned" , async ( ) => {
132- expect ( true , "Not Implemented" ) . false ;
282+ let build2 : Build = {
283+ id : 2 ,
284+ definition : {
285+ id : 2 ,
286+ } ,
287+ status : BuildStatus . Postponed ,
288+ sourceVersion : "sourceVersion"
289+ } ;
290+
291+ setBuildServiceStubs ( [ build2 ] ) ;
292+
293+ let buildServiceCreateTagSpy = buildServiceStub . addBuildTag
294+ . withArgs ( configStub . teamFoundationCollectionUri , configStub . teamFoundationProject , configStub . accessToken , configStub . currentBuildId , configStub . releaseTag ) ;
295+
296+ var unifyReleaseService = new UnifyReleaseService ( buildServiceStub , configStub ) ;
297+
298+ await unifyReleaseService . unifyRelease ( ) ;
299+
300+ expect ( buildServiceCreateTagSpy . calledOnce ) . equal ( false ) ;
133301 } ) ;
134302 } ) ;
135303} ) ;
0 commit comments