1616import  {  beforeEach ,  suite ,  test ,  TestContext  }  from  'node:test' 
1717import  {  MockAgent ,  setGlobalDispatcher  }  from  'undici' 
1818
19+ import  {  CatalogItemTypeDefinition  }  from  '@mia-platform/console-types' 
1920import  {  HTTPClient  }  from  './http-client' 
2021import  {  internalEndpoint ,  MarketplaceClient ,  MarketplaceClientInternal  }  from  './marketplaceClient' 
2122
2223const  tenantID  =  'tenantID' 
2324const  itemID  =  'itemid' 
25+ const  itdName  =  'itdName' 
2426const  search  =  'item1' 
2527const  type  =  'example' 
2628const  version  =  '1.0.1' 
@@ -34,6 +36,48 @@ const publicItems = [
3436  {  itemId : 'item-id-2' ,  name : 'item2' ,  tenantId : 'public'  } , 
3537] 
3638
39+ const  itemTypeDefinitions : CatalogItemTypeDefinition [ ]  =  [ 
40+   { 
41+     apiVersion : 'software-catalog.mia-platform.eu/v1' , 
42+     kind : 'item-type-definition' , 
43+     metadata : { 
44+       namespace : {  scope : 'tenant' ,  id : 'mia-platform'  } , 
45+       displayName : 'Plugin ITD' , 
46+       name : 'plugin' , 
47+       visibility : {  scope : 'console'  } , 
48+     } , 
49+     spec : { 
50+       isVersioningSupported : true , 
51+       type : 'plugin' , 
52+       scope : 'tenant' , 
53+       validation : { 
54+         mechanism : 'json-schema' , 
55+         schema : {  type : 'object'  } , 
56+       } , 
57+     } , 
58+     __v : 1 , 
59+   } , 
60+   { 
61+     apiVersion : 'software-catalog.mia-platform.eu/v1' , 
62+     kind : 'item-type-definition' , 
63+     metadata : { 
64+       namespace : {  scope : 'tenant' ,  id : 'my-company'  } , 
65+       displayName : 'Custom Workload ITD' , 
66+       name : 'custom-workload' , 
67+       visibility : {  scope : 'tenant' ,  ids : [  'my-company'  ]  } , 
68+     } , 
69+     spec : { 
70+       type : 'custom-workload' , 
71+       scope : 'tenant' , 
72+       validation : { 
73+         mechanism : 'json-schema' , 
74+         schema : {  type : 'object'  } , 
75+       } , 
76+     } , 
77+     __v : 1 , 
78+   } , 
79+ ] 
80+ 
3781suite ( 'Marketplace Internal Client' ,  ( )  =>  { 
3882  const  client  =  MarketplaceClientInternal ( '' ,  '' ) 
3983  let  agent : MockAgent 
@@ -167,6 +211,62 @@ suite('Marketplace Internal Client', () => {
167211    } ) . reply ( 500 ,  {  error : 'Internal Server Error'  } ) 
168212    await  t . assert . rejects ( async  ( )  =>  await  client . marketplaceItemInfo ( tenantID ,  itemID ,  version ) ,  {  name : 'Error'  } ) 
169213  } ) 
214+ 
215+   test ( 'list marketplace Item Type Definitions' ,  async  ( t : TestContext )  =>  { 
216+     agent . get ( internalEndpoint ) . intercept ( { 
217+       path : '/api/marketplace/item-type-definitions' , 
218+       method : 'GET' , 
219+       query : { 
220+         perPage : 200 , 
221+         per_page : 200 , 
222+         page : 1 , 
223+       } , 
224+     } ) . reply ( 200 ,  itemTypeDefinitions ) 
225+     t . assert . deepEqual ( await  client . listMarketplaceItemTypeDefinitions ( ) ,  itemTypeDefinitions ) 
226+ 
227+     agent . get ( internalEndpoint ) . intercept ( { 
228+       path : '/api/marketplace/item-type-definitions' , 
229+       method : 'GET' , 
230+       query : { 
231+         perPage : 200 , 
232+         per_page : 200 , 
233+         page : 1 , 
234+         namespace : 'mia-platform,my-company' , 
235+         name : 'plugin,custom-workload' , 
236+         displayName : 'Plugin,Custom Workload' , 
237+       } , 
238+     } ) . reply ( 200 ,  itemTypeDefinitions ) 
239+     t . assert . deepEqual ( await  client . listMarketplaceItemTypeDefinitions ( 'mia-platform,my-company' ,  'plugin,custom-workload' ,  'Plugin,Custom Workload' ) ,  itemTypeDefinitions ) 
240+   } ) 
241+ 
242+   test ( 'list marketplace Item Type Definitions must throw if the API call fails' ,  async  ( t : TestContext )  =>  { 
243+     agent . get ( internalEndpoint ) . intercept ( { 
244+       path : '/api/marketplace/item-type-definitions' , 
245+       method : 'GET' , 
246+       query : { 
247+         perPage : 200 , 
248+         per_page : 200 , 
249+         page : 1 , 
250+       } , 
251+     } ) . reply ( 500 ,  {  error : 'Internal Server Error'  } ) 
252+     await  t . assert . rejects ( async  ( )  =>  await  client . listMarketplaceItemTypeDefinitions ( ) ,  {  name : 'Error'  } ) 
253+   } ) 
254+ 
255+   test ( 'marketplace Item Type Definition info' ,  async  ( t : TestContext )  =>  { 
256+     agent . get ( internalEndpoint ) . intercept ( { 
257+       path : `/api/tenants/${ tenantID } ${ itdName }  , 
258+       method : 'GET' , 
259+     } ) . reply ( 200 ,  itemTypeDefinitions . at ( 0 ) ) 
260+     t . assert . deepEqual ( await  client . marketplaceItemTypeDefinitionInfo ( tenantID ,  itdName ) ,  itemTypeDefinitions . at ( 0 ) ) 
261+   } ) 
262+ 
263+   test ( 'marketplace Item Type Definitions info must throw if the API call fails' ,  async  ( t : TestContext )  =>  { 
264+     agent . get ( internalEndpoint ) . intercept ( { 
265+       path : `/api/tenants/${ tenantID } ${ itdName }  , 
266+       method : 'GET' , 
267+     } ) . reply ( 500 ,  {  error : 'Internal Server Error'  } ) 
268+     await  t . assert . rejects ( async  ( )  =>  await  client . marketplaceItemTypeDefinitionInfo ( tenantID ,  itdName ) ,  {  name : 'Error'  } ) 
269+   } ) 
170270} ) 
171271
172272suite ( 'Marketplace Client' ,  ( )  =>  { 
@@ -279,4 +379,60 @@ suite('Marketplace Client', () => {
279379    } ) . reply ( 500 ,  {  error : 'Internal Server Error'  } ) 
280380    await  t . assert . rejects ( async  ( )  =>  await  client . marketplaceItemInfo ( tenantID ,  itemID ,  version ) ,  {  name : 'Error'  } ) 
281381  } ) 
382+ 
383+   test ( 'list marketplace Item Type Definitions' ,  async  ( t : TestContext )  =>  { 
384+     agent . get ( mockedEndpoint ) . intercept ( { 
385+       path : '/api/marketplace/item-type-definitions' , 
386+       method : 'GET' , 
387+       query : { 
388+         perPage : 200 , 
389+         per_page : 200 , 
390+         page : 1 , 
391+       } , 
392+     } ) . reply ( 200 ,  itemTypeDefinitions ) 
393+     t . assert . deepEqual ( await  client . listMarketplaceItemTypeDefinitions ( ) ,  itemTypeDefinitions ) 
394+ 
395+     agent . get ( mockedEndpoint ) . intercept ( { 
396+       path : '/api/marketplace/item-type-definitions' , 
397+       method : 'GET' , 
398+       query : { 
399+         perPage : 200 , 
400+         per_page : 200 , 
401+         page : 1 , 
402+         namespace : 'mia-platform,my-company' , 
403+         name : 'plugin,custom-workload' , 
404+         displayName : 'Plugin,Custom Workload' , 
405+       } , 
406+     } ) . reply ( 200 ,  itemTypeDefinitions ) 
407+     t . assert . deepEqual ( await  client . listMarketplaceItemTypeDefinitions ( 'mia-platform,my-company' ,  'plugin,custom-workload' ,  'Plugin,Custom Workload' ) ,  itemTypeDefinitions ) 
408+   } ) 
409+ 
410+   test ( 'list marketplace Item Type Definitions must throw if the API call fails' ,  async  ( t : TestContext )  =>  { 
411+     agent . get ( mockedEndpoint ) . intercept ( { 
412+       path : '/api/marketplace/item-type-definitions' , 
413+       method : 'GET' , 
414+       query : { 
415+         perPage : 200 , 
416+         per_page : 200 , 
417+         page : 1 , 
418+       } , 
419+     } ) . reply ( 500 ,  {  error : 'Internal Server Error'  } ) 
420+     await  t . assert . rejects ( async  ( )  =>  await  client . listMarketplaceItemTypeDefinitions ( ) ,  {  name : 'Error'  } ) 
421+   } ) 
422+ 
423+   test ( 'marketplace Item Type Definition info' ,  async  ( t : TestContext )  =>  { 
424+     agent . get ( mockedEndpoint ) . intercept ( { 
425+       path : `/api/tenants/${ tenantID } ${ itdName }  , 
426+       method : 'GET' , 
427+     } ) . reply ( 200 ,  itemTypeDefinitions . at ( 0 ) ) 
428+     t . assert . deepEqual ( await  client . marketplaceItemTypeDefinitionInfo ( tenantID ,  itdName ) ,  itemTypeDefinitions . at ( 0 ) ) 
429+   } ) 
430+ 
431+   test ( 'marketplace Item Type Definitions info must throw if the API call fails' ,  async  ( t : TestContext )  =>  { 
432+     agent . get ( mockedEndpoint ) . intercept ( { 
433+       path : `/api/tenants/${ tenantID } ${ itdName }  , 
434+       method : 'GET' , 
435+     } ) . reply ( 500 ,  {  error : 'Internal Server Error'  } ) 
436+     await  t . assert . rejects ( async  ( )  =>  await  client . marketplaceItemTypeDefinitionInfo ( tenantID ,  itdName ) ,  {  name : 'Error'  } ) 
437+   } ) 
282438} ) 
0 commit comments