1111 */
1212
1313import mockAxios from 'axios' ;
14+ import { dump } from 'js-yaml' ;
1415
1516import { container } from '@/inversify.config' ;
1617import { dashboardBackendPrefix } from '@/services/backend-client/const' ;
@@ -23,11 +24,7 @@ import {
2324 DevWorkspaceClient ,
2425 REGISTRY_URL ,
2526} from '@/services/workspace-client/devworkspace/devWorkspaceClient' ;
26-
27- const mockFetchData = jest . fn ( ) ;
28- jest . mock ( '@/services/registry/fetchData' , ( ) => ( {
29- fetchData : ( ...args : unknown [ ] ) => mockFetchData ( ...args ) ,
30- } ) ) ;
27+ import { EDITOR_DEVFILE_API_QUERY } from '@/store/DevfileRegistries/const' ;
3128
3229describe ( 'DevWorkspace client editor update' , ( ) => {
3330 const namespace = 'admin-che' ;
@@ -134,53 +131,49 @@ describe('DevWorkspace client editor update', () => {
134131
135132 describe ( 'DevWorkspaceTemplate with plugin registry URL' , ( ) => {
136133 it ( 'should return patch for an editor if it has been updated' , async ( ) => {
137- const template = getVSCodeDevWorkspaceTemplate ( '1000m' ) ;
134+ const editor = getVSCodeEditorDefinition ( '1000m' ) as devfileApi . Devfile ;
135+ const template = getVSCodeDevWorkspaceTemplate ( '500m' ) ;
138136 template . metadata . annotations = {
139137 'che.eclipse.org/components-update-policy' : 'managed' ,
140138 'che.eclipse.org/plugin-registry-url' :
141- 'https://192.168.64.24.nip.io/plugin-registry/v3/plugins/ che-incubator/che-code/latest /devfile.yaml' ,
139+ 'https://192.168.64.24.nip.io/che-incubator/che-code/devfile.yaml' ,
142140 } ;
143141
144- const mockPatch = mockAxios . get as jest . Mock ;
145- mockPatch . mockResolvedValueOnce ( new Promise ( resolve => resolve ( { data : template } ) ) ) ;
142+ const mockGet = mockAxios . get as jest . Mock ;
143+ mockGet . mockResolvedValueOnce ( new Promise ( resolve => resolve ( { data : template } ) ) ) ;
146144
147- // if cpuLimit changed from '1000m' to '500m'
148- const newTemplate = getVSCodeDevWorkspaceTemplate ( '500m' ) ;
149- newTemplate . metadata . annotations = {
150- 'che.eclipse.org/components-update-policy' : 'managed' ,
151- 'che.eclipse.org/plugin-registry-url' :
152- 'https://192.168.64.24.nip.io/plugin-registry/v3/plugins/che-incubator/che-code/latest/devfile.yaml' ,
153- } ;
145+ const mockPost = mockAxios . post as jest . Mock ;
146+ mockPost . mockResolvedValueOnce ( new Promise ( resolve => resolve ( { data : dump ( editor ) } ) ) ) ;
154147
155- const editors : devfileApi . Devfile [ ] = [ getVSCodeEditorDefinition ( ) as devfileApi . Devfile ] ;
156- const editorName = newTemplate . metadata . name ;
148+ const editorName = template . metadata . name ;
157149
158150 const patch = await client . checkForTemplatesUpdate (
159151 editorName ,
160152 namespace ,
161- editors ,
153+ [ editor ] ,
162154 pluginRegistryUrl ,
163155 pluginRegistryInternalUrl ,
164156 undefined ,
165157 ) ;
166158
167- expect ( mockPatch . mock . calls ) . toEqual ( [
159+ expect ( mockGet . mock . calls ) . toEqual ( [
168160 [ `${ dashboardBackendPrefix } /namespace/${ namespace } /devworkspacetemplates/${ editorName } ` ] ,
169161 ] ) ;
170162
171- expect ( patch ) . toEqual ( [
172- {
173- op : 'replace' ,
174- path : '/metadata/annotations' ,
175- value : {
176- [ COMPONENT_UPDATE_POLICY ] : 'managed' ,
177- [ REGISTRY_URL ] : 'che-incubator/che-code/latest' ,
163+ expect ( mockPost . mock . calls ) . toEqual ( [
164+ [
165+ `${ dashboardBackendPrefix } /data/resolver` ,
166+ {
167+ url : 'https://192.168.64.24.nip.io/che-incubator/che-code/devfile.yaml' ,
178168 } ,
179- } ,
169+ ] ,
170+ ] ) ;
171+
172+ expect ( patch ) . toEqual ( [
180173 {
181174 op : 'replace' ,
182175 path : '/spec' ,
183- value : newTemplate . spec ,
176+ value : getVSCodeDevWorkspaceTemplate ( '1000m' ) . spec ,
184177 } ,
185178 ] ) ;
186179 } ) ;
@@ -196,16 +189,13 @@ describe('DevWorkspace client editor update', () => {
196189 const mockPatch = mockAxios . get as jest . Mock ;
197190 mockPatch . mockResolvedValueOnce ( new Promise ( resolve => resolve ( { data : template } ) ) ) ;
198191
199- // if cpuLimit changed from '1000m' to '500m'
200- const newTemplate = getVSCodeDevWorkspaceTemplate ( '500m' ) ;
201- newTemplate . metadata . annotations = {
202- 'che.eclipse.org/components-update-policy' : 'managed' ,
203- 'che.eclipse.org/plugin-registry-url' :
204- 'https://192.168.64.24.nip.io/custom-registry/v3/plugins/che-incubator/che-code/latest/devfile.yaml' ,
205- } ;
192+ const editors : devfileApi . Devfile [ ] = [
193+ getVSCodeEditorDefinition ( '1000m' ) as devfileApi . Devfile ,
194+ ] ;
195+ const editorName = template . metadata . name ;
206196
207- const editors : devfileApi . Devfile [ ] = [ getVSCodeEditorDefinition ( ) as devfileApi . Devfile ] ;
208- const editorName = newTemplate . metadata . name ;
197+ const mockPost = mockAxios . post as jest . Mock ;
198+ mockPost . mockResolvedValueOnce ( new Promise ( resolve => resolve ( { data : editors [ 0 ] } ) ) ) ;
209199
210200 const patch = await client . checkForTemplatesUpdate (
211201 editorName ,
@@ -216,8 +206,13 @@ describe('DevWorkspace client editor update', () => {
216206 undefined ,
217207 ) ;
218208
219- expect ( mockPatch . mock . calls ) . toEqual ( [
220- [ `${ dashboardBackendPrefix } /namespace/${ namespace } /devworkspacetemplates/${ editorName } ` ] ,
209+ expect ( mockPost . mock . calls ) . toEqual ( [
210+ [
211+ `${ dashboardBackendPrefix } /data/resolver` ,
212+ {
213+ url : 'https://192.168.64.24.nip.io/custom-registry/v3/plugins/che-incubator/che-code/latest/devfile.yaml' ,
214+ } ,
215+ ] ,
221216 ] ) ;
222217
223218 expect ( patch ) . toEqual ( [ ] ) ;
@@ -230,10 +225,6 @@ describe('DevWorkspace client editor update', () => {
230225 'che.eclipse.org/plugin-registry-url' :
231226 'https://192.168.64.24.nip.io/plugin-registry/v3/plugins/che-incubator/che-code/latest/devfile.yaml' ,
232227 } ;
233-
234- const mockPatch = mockAxios . get as jest . Mock ;
235- mockPatch . mockResolvedValueOnce ( new Promise ( resolve => resolve ( { data : template } ) ) ) ;
236-
237228 // if cpuLimit changed from '1000m' to '500m'
238229 const newTemplate = getVSCodeDevWorkspaceTemplate ( '500m' ) ;
239230 newTemplate . metadata . annotations = {
@@ -242,6 +233,9 @@ describe('DevWorkspace client editor update', () => {
242233 'https://192.168.64.24.nip.io/plugin-registry/v3/plugins/che-incubator/che-code/latest/devfile.yaml' ,
243234 } ;
244235
236+ const mockGet = mockAxios . get as jest . Mock ;
237+ mockGet . mockResolvedValueOnce ( new Promise ( resolve => resolve ( { data : template } ) ) ) ;
238+
245239 const editors : devfileApi . Devfile [ ] = [ getVSCodeEditorDefinition ( ) as devfileApi . Devfile ] ;
246240 const editorName = newTemplate . metadata . name ;
247241
@@ -254,7 +248,7 @@ describe('DevWorkspace client editor update', () => {
254248 undefined ,
255249 ) ;
256250
257- expect ( mockPatch . mock . calls ) . toEqual ( [
251+ expect ( mockGet . mock . calls ) . toEqual ( [
258252 [ `${ dashboardBackendPrefix } /namespace/${ namespace } /devworkspacetemplates/${ editorName } ` ] ,
259253 ] ) ;
260254
@@ -264,7 +258,7 @@ describe('DevWorkspace client editor update', () => {
264258 path : '/metadata/annotations' ,
265259 value : {
266260 [ COMPONENT_UPDATE_POLICY ] : 'managed' ,
267- [ REGISTRY_URL ] : ' che-incubator/che-code/latest' ,
261+ [ REGISTRY_URL ] : ` ${ EDITOR_DEVFILE_API_QUERY } che-incubator/che-code/latest` ,
268262 } ,
269263 } ,
270264 ] ) ;
@@ -311,7 +305,7 @@ describe('DevWorkspace client editor update', () => {
311305 path : '/metadata/annotations' ,
312306 value : {
313307 [ COMPONENT_UPDATE_POLICY ] : 'managed' ,
314- [ REGISTRY_URL ] : ' che-incubator/custom-editor/latest' ,
308+ [ REGISTRY_URL ] : ` ${ EDITOR_DEVFILE_API_QUERY } che-incubator/custom-editor/latest` ,
315309 } ,
316310 } ,
317311 ] ) ;
0 commit comments