@@ -3,12 +3,11 @@ import * as _ from "lodash";
33import { SinonSandbox , SinonMock , createSandbox } from "sinon" ;
44import * as fsextra from "fs-extra" ;
55import * as cfLocal from "../src/cf-local" ;
6- import { ITarget , ServiceInfo , ServiceInstanceInfo , eFilters , CF_PAGE_SIZE } from "../src/types" ;
6+ import { ITarget , ServiceInstanceInfo , eFilters , PlanInfo } from "../src/types" ;
77import * as cli from "../src/cli" ;
88import { getInstanceMetadata , isTargetSet , getInstanceCredentials , createServiceInstance , getServicesInstancesFilteredByType } from "../src/cfServicesUtil" ;
99import { expect , assert } from "chai" ;
1010import { fail } from "assert" ;
11- import { cfGetConfigFilePath } from "../src/utils" ;
1211
1312describe ( 'services unit package tests' , ( ) => {
1413 let sandbox : SinonSandbox ;
@@ -37,54 +36,55 @@ describe('services unit package tests', () => {
3736 } ) ;
3837
3938 describe ( "getServicesInstancesFilteredByType" , ( ) => {
40- const spaceGuid = 'space-d2ff128b-e2a8-25f7-828a-24be6173db7b' ;
41-
42- beforeEach ( ( ) => {
43- fsExtraMock . expects ( "readFile" ) . withExactArgs ( cfGetConfigFilePath ( ) , "utf8" ) . resolves ( `{"SpaceFields": {
44- "GUID": "${ spaceGuid } "
45- }}` ) ;
46- } ) ;
4739
4840 const types = [ 'saas-registry' , 'audolog' ] ;
49- const services : ServiceInfo [ ] = [ {
41+ const plans : PlanInfo [ ] = [ {
5042 description : 'description1' ,
5143 guid : 'd2ff128b-e1a8-15f7-828a-24be6173db7b' ,
52- label : types [ 0 ] ,
53- service_plans_url : '/v2/services/d2ff128b-A1a8-45f7-828a-24be6173db7b/service_plans'
44+ label : 'plan-1' ,
45+ service_offering : {
46+ description : 'service description' ,
47+ guid : 'service-guid-1' ,
48+ name : types [ 0 ]
49+ }
5450 } , {
5551 description : 'description2' ,
56- guid : 'd2ff128b-e2a8-25f7-828a-24be6173db7b' ,
57- label : types [ 1 ] ,
58- service_plans_url : '/v2/services/d2ff128b-s1a8-45f7-828a-24be6173db7b/service_plans'
52+ guid : 'other-e1a8-15f7-828a-24be6173db7b' ,
53+ label : 'plan-2' ,
54+ service_offering : {
55+ description : 'service description' ,
56+ guid : 'service-guid-2' ,
57+ name : types [ 1 ]
58+ }
5959 } ] ;
6060 const instances : ServiceInstanceInfo [ ] = [ { label : "label1" , serviceName : types [ 1 ] } , { label : "label3" , serviceName : types [ 0 ] } ] ;
61- const query = { 'filters' : [ { key : eFilters . names , value : _ . join ( _ . map ( types , encodeURIComponent ) ) } , { key : eFilters . space_guids , value : spaceGuid } ] , per_page : CF_PAGE_SIZE } ;
61+ const query = { 'filters' : [ { key : eFilters . service_offering_names , value : _ . join ( _ . map ( types , encodeURIComponent ) ) } ] } ;
6262
6363 it ( "ok:: verify query parameters" , async ( ) => {
64- mockCfLocal . expects ( "cfGetServices " ) . withExactArgs ( query ) . resolves ( services ) ;
64+ mockCfLocal . expects ( "cfGetServicePlansList " ) . withExactArgs ( query ) . resolves ( plans ) ;
6565 const servicesQuery = {
6666 'filters' : [ {
67- key : eFilters . service_offering_guids , value : _ . join ( _ . map ( services , 'guid' ) )
67+ key : eFilters . service_plan_guids , value : _ . join ( _ . map ( plans , 'guid' ) )
6868 } ]
6969 } ;
7070 mockCfLocal . expects ( "cfGetManagedServiceInstances" ) . withExactArgs ( servicesQuery ) . resolves ( instances ) ;
7171 assert . deepEqual ( _ . map ( await getServicesInstancesFilteredByType ( types ) , 'label' ) , [ instances [ 0 ] . label , instances [ 1 ] . label ] ) ;
7272 } ) ;
7373
7474 it ( "ok:: nothing match requested services" , async ( ) => {
75- mockCfLocal . expects ( "cfGetServices" ) . withExactArgs ( query ) . resolves ( [ ] ) ;
76- expect ( _ . size ( await getServicesInstancesFilteredByType ( types ) ) ) . to . be . equal ( 0 ) ;
75+ const query = { 'filters' : [ { key : eFilters . service_offering_names , value : encodeURIComponent ( 'my type' ) } ] } ;
76+ mockCfLocal . expects ( "cfGetServicePlansList" ) . withExactArgs ( query ) . resolves ( undefined ) ;
77+ expect ( _ . size ( await getServicesInstancesFilteredByType ( [ 'my type' ] ) ) ) . to . be . equal ( 0 ) ;
7778 } ) ;
7879
7980 it ( "ok:: undefined services requested" , async ( ) => {
80- const query = { 'filters' : [ { key : eFilters . names , value : _ . join ( _ . map ( null , encodeURIComponent ) ) } , { key : eFilters . space_guids , value : spaceGuid } ] , per_page : CF_PAGE_SIZE } ;
81- mockCfLocal . expects ( "cfGetServices " ) . withExactArgs ( query ) . resolves ( [ ] ) ;
81+ const query = { 'filters' : [ { key : eFilters . service_offering_names , value : _ . join ( _ . map ( null , encodeURIComponent ) ) } ] } ;
82+ mockCfLocal . expects ( "cfGetServicePlansList " ) . withExactArgs ( query ) . resolves ( [ ] ) ;
8283 expect ( _ . size ( await getServicesInstancesFilteredByType ( null ) ) ) . to . be . equal ( 0 ) ;
8384 } ) ;
8485
8586 it ( "exception:: cfGetManagedServiceInstances throws error" , async ( ) => {
86- const query = { 'filters' : [ { key : eFilters . names , value : _ . join ( _ . map ( types , encodeURIComponent ) ) } , { key : eFilters . space_guids , value : spaceGuid } ] , per_page : CF_PAGE_SIZE } ;
87- mockCfLocal . expects ( "cfGetServices" ) . withExactArgs ( query ) . resolves ( services ) ;
87+ mockCfLocal . expects ( "cfGetServicePlansList" ) . withExactArgs ( query ) . resolves ( plans ) ;
8888 const error = new Error ( "cfGetManagedServiceInstances failed" ) ;
8989 mockCfLocal . expects ( "cfGetManagedServiceInstances" ) . throws ( error ) ;
9090 try {
0 commit comments