1
1
import axios from "axios"
2
- import { getApiKey , getURLWithSearchParams , login , logout } from "./api"
2
+ import {
3
+ MockTemplate ,
4
+ MockTemplateVersionParameter1 ,
5
+ MockWorkspace ,
6
+ MockWorkspaceBuild ,
7
+ } from "testHelpers/entities"
8
+ import * as api from "./api"
3
9
import * as TypesGen from "./typesGenerated"
4
10
5
11
describe ( "api.ts" , ( ) => {
@@ -12,7 +18,7 @@ describe("api.ts", () => {
12
18
jest . spyOn ( axios , "post" ) . mockResolvedValueOnce ( { data : loginResponse } )
13
19
14
20
// when
15
- const result = await login ( "test" , "123" )
21
+ const result = await api . login ( "test" , "123" )
16
22
17
23
// then
18
24
expect ( axios . post ) . toHaveBeenCalled ( )
@@ -33,7 +39,7 @@ describe("api.ts", () => {
33
39
axios . post = axiosMockPost
34
40
35
41
try {
36
- await login ( "test" , "123" )
42
+ await api . login ( "test" , "123" )
37
43
} catch ( error ) {
38
44
expect ( error ) . toStrictEqual ( expectedError )
39
45
}
@@ -49,7 +55,7 @@ describe("api.ts", () => {
49
55
axios . post = axiosMockPost
50
56
51
57
// when
52
- await logout ( )
58
+ await api . logout ( )
53
59
54
60
// then
55
61
expect ( axiosMockPost ) . toHaveBeenCalled ( )
@@ -68,7 +74,7 @@ describe("api.ts", () => {
68
74
axios . post = axiosMockPost
69
75
70
76
try {
71
- await logout ( )
77
+ await api . logout ( )
72
78
} catch ( error ) {
73
79
expect ( error ) . toStrictEqual ( expectedError )
74
80
}
@@ -87,7 +93,7 @@ describe("api.ts", () => {
87
93
axios . post = axiosMockPost
88
94
89
95
// when
90
- const result = await getApiKey ( )
96
+ const result = await api . getApiKey ( )
91
97
92
98
// then
93
99
expect ( axiosMockPost ) . toHaveBeenCalled ( )
@@ -107,7 +113,7 @@ describe("api.ts", () => {
107
113
axios . post = axiosMockPost
108
114
109
115
try {
110
- await getApiKey ( )
116
+ await api . getApiKey ( )
111
117
} catch ( error ) {
112
118
expect ( error ) . toStrictEqual ( expectedError )
113
119
}
@@ -133,7 +139,7 @@ describe("api.ts", () => {
133
139
] ) (
134
140
`Workspaces - getURLWithSearchParams(%p, %p) returns %p` ,
135
141
( basePath , filter , expected ) => {
136
- expect ( getURLWithSearchParams ( basePath , filter ) ) . toBe ( expected )
142
+ expect ( api . getURLWithSearchParams ( basePath , filter ) ) . toBe ( expected )
137
143
} ,
138
144
)
139
145
} )
@@ -150,8 +156,38 @@ describe("api.ts", () => {
150
156
] ) (
151
157
`Users - getURLWithSearchParams(%p, %p) returns %p` ,
152
158
( basePath , filter , expected ) => {
153
- expect ( getURLWithSearchParams ( basePath , filter ) ) . toBe ( expected )
159
+ expect ( api . getURLWithSearchParams ( basePath , filter ) ) . toBe ( expected )
154
160
} ,
155
161
)
156
162
} )
163
+
164
+ describe ( "update" , ( ) => {
165
+ it ( "creates a build with start and the latest template" , async ( ) => {
166
+ jest
167
+ . spyOn ( api , "postWorkspaceBuild" )
168
+ . mockResolvedValueOnce ( MockWorkspaceBuild )
169
+ jest . spyOn ( api , "getTemplate" ) . mockResolvedValueOnce ( MockTemplate )
170
+ await api . updateWorkspace ( MockWorkspace )
171
+ expect ( api . postWorkspaceBuild ) . toHaveBeenCalledWith ( MockWorkspace . id , {
172
+ transition : "start" ,
173
+ template_version_id : MockTemplate . active_version_id ,
174
+ rich_parameter_values : [ ] ,
175
+ } )
176
+ } )
177
+
178
+ it ( "fails when having missing parameters" , async ( ) => {
179
+ jest
180
+ . spyOn ( api , "postWorkspaceBuild" )
181
+ . mockResolvedValueOnce ( MockWorkspaceBuild )
182
+ jest . spyOn ( api , "getTemplate" ) . mockResolvedValueOnce ( MockTemplate )
183
+ jest . spyOn ( api , "getWorkspaceBuildParameters" ) . mockResolvedValueOnce ( [ ] )
184
+ jest
185
+ . spyOn ( api , "getTemplateVersionRichParameters" )
186
+ . mockResolvedValueOnce ( [ MockTemplateVersionParameter1 ] )
187
+
188
+ await expect ( api . updateWorkspace ( MockWorkspace ) ) . rejects . toThrow (
189
+ api . MissingBuildParameters ,
190
+ )
191
+ } )
192
+ } )
157
193
} )
0 commit comments