1
- jest . mock ( "./pipelines" ) ;
2
-
3
1
import { disableVerboseLogging , enableVerboseLogging } from "../../logger" ;
4
2
5
3
import {
6
- IAzureRepoPipelineConfig ,
4
+ createPipelineForDefinition ,
5
+ definitionForAzureRepoPipeline ,
6
+ definitionForGithubRepoPipeline ,
7
+ getBuildApiClient ,
7
8
GithubRepoPipelineConfig ,
9
+ IAzureRepoPipelineConfig ,
10
+ queueBuild ,
8
11
RepositoryTypes
9
12
} from "./pipelines" ;
10
-
11
13
import {
12
14
BuildDefinition ,
13
15
BuildRepository ,
14
16
YamlProcess
15
17
} from "azure-devops-node-api/interfaces/BuildInterfaces" ;
18
+ import * as azdoClient from "../azdoClient" ;
16
19
17
20
beforeAll ( ( ) => {
18
21
enableVerboseLogging ( ) ;
@@ -22,9 +25,15 @@ afterAll(() => {
22
25
disableVerboseLogging ( ) ;
23
26
} ) ;
24
27
25
- describe ( "It builds an azure repo pipeline definition" , ( ) => {
26
- const { definitionForAzureRepoPipeline } = jest . requireActual ( "./pipelines" ) ;
28
+ describe ( "test getBuildApiClient function" , ( ) => {
29
+ it ( "positive test" , async ( ) => {
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ jest . spyOn ( azdoClient , "getBuildApi" ) . mockResolvedValueOnce ( { } as any ) ;
32
+ await expect ( getBuildApiClient ( "org" , "token" ) ) . toBeDefined ( ) ;
33
+ } ) ;
34
+ } ) ;
27
35
36
+ describe ( "It builds an azure repo pipeline definition" , ( ) => {
28
37
test ( "pipeline definition is well-formed" , ( ) => {
29
38
const sampleAzureConfig = {
30
39
branchFilters : [ "master" ] ,
@@ -70,8 +79,6 @@ describe("It builds an azure repo pipeline definition", () => {
70
79
} ) ;
71
80
72
81
describe ( "It builds a github repo pipeline definition" , ( ) => {
73
- const { definitionForGithubRepoPipeline } = jest . requireActual ( "./pipelines" ) ;
74
-
75
82
test ( "pipeline definition is well-formed" , ( ) => {
76
83
const sampleGithubConfig = {
77
84
branchFilters : [ "master" ] ,
@@ -122,3 +129,67 @@ describe("It builds a github repo pipeline definition", () => {
122
129
}
123
130
} ) ;
124
131
} ) ;
132
+
133
+ describe ( "test createPipelineForDefinition function" , ( ) => {
134
+ it ( "positive test" , async ( ) => {
135
+ const result = await createPipelineForDefinition (
136
+ {
137
+ createDefinition : ( ) => {
138
+ return { } ;
139
+ }
140
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
141
+ } as any ,
142
+ "project" ,
143
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
144
+ { } as any
145
+ ) ;
146
+ expect ( result ) . toBeDefined ( ) ;
147
+ } ) ;
148
+ it ( "negative test" , async ( ) => {
149
+ await expect (
150
+ createPipelineForDefinition (
151
+ {
152
+ createDefinition : ( ) => {
153
+ throw Error ( "fake" ) ;
154
+ }
155
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
156
+ } as any ,
157
+ "project" ,
158
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
159
+ { } as any
160
+ )
161
+ ) . rejects . toThrow ( ) ;
162
+ } ) ;
163
+ } ) ;
164
+
165
+ describe ( "test queueBuild function" , ( ) => {
166
+ it ( "positive test" , async ( ) => {
167
+ const result = await queueBuild (
168
+ {
169
+ queueBuild : ( ) => {
170
+ return { } ;
171
+ }
172
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
173
+ } as any ,
174
+ "project" ,
175
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
176
+ { } as any
177
+ ) ;
178
+ expect ( result ) . toBeDefined ( ) ;
179
+ } ) ;
180
+ it ( "negative test" , async ( ) => {
181
+ await expect (
182
+ queueBuild (
183
+ {
184
+ queueBuild : ( ) => {
185
+ throw Error ( "fake" ) ;
186
+ }
187
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
188
+ } as any ,
189
+ "project" ,
190
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
191
+ { } as any
192
+ )
193
+ ) . rejects . toThrow ( ) ;
194
+ } ) ;
195
+ } ) ;
0 commit comments