@@ -325,10 +325,25 @@ describe("CFUtil", () => {
325325 describe ( "when creating service" , ( ) => {
326326 const SPACE_GUID = "spaceGuid1" ;
327327 const NON_EXISTING_SERVICE_INSTANCE = "nonExistingServiceInstance" ;
328+ const SERVICE = "service1" ;
328329 const SERVICE_INSTANCE = "serviceInstance1" ;
329- const PLAN = "serviceInstancePlan " ;
330+ const PLAN = "app-runtime " ;
330331
331- it ( "should create a service with parameters" , async ( ) => {
332+ it ( "should create a service" , async ( ) => {
333+ await createService ( TestUtil . getResource ( "service_offerings.json" ) , TestUtil . getResource ( "service_plans.json" ) ) ;
334+ } ) ;
335+
336+ it ( "shouldn't find a plan by name" , async ( ) => {
337+ await expect ( createService ( TestUtil . getResource ( "service_offerings.json" ) , JSON . stringify ( { resources : [ { name : "app-something" } ] } ) ) )
338+ . to . be . rejectedWith ( "Cannot find a plan by name 'app-runtime' for service 'service1'" ) ;
339+ } ) ;
340+
341+ it ( "ahouldn't find service offering" , async ( ) => {
342+ await expect ( createService ( JSON . stringify ( { resources : [ ] } ) , TestUtil . getResource ( "service_plans.json" ) ) )
343+ . to . be . rejectedWith ( "Cannot find a service offering by name 'service1'" ) ;
344+ } ) ;
345+
346+ async function createService ( serviceOfferings : string , plans : string ) {
332347 let call = 0 ;
333348 const credentialsJson = JSON . parse ( TestUtil . getResource ( "credentials_bs.json" ) ) ;
334349 const CFUtil = await esmock ( "../src/util/cfUtil.js" , { } , {
@@ -342,8 +357,10 @@ describe("CFUtil", () => {
342357 } else {
343358 return TestUtil . getStdOut ( TestUtil . getResource ( "service_instances_bs.json" ) ) ;
344359 }
345- } else if ( args [ 1 ] === `/v3/service_plans?names=${ PLAN } &space_guids=${ SPACE_GUID } ` ) {
346- return TestUtil . getStdOut ( TestUtil . getResource ( "service_plans.json" ) ) ;
360+ } else if ( args [ 1 ] === `/v3/service_offerings?names=${ SERVICE } ` ) {
361+ return TestUtil . getStdOut ( serviceOfferings ) ;
362+ } else if ( args [ 1 ] === `/v3/service_plans?service_offering_guids=B8F4D0AC-9F30-4C18-B808-D8C1C6E2646E` ) {
363+ return TestUtil . getStdOut ( plans ) ;
347364 }
348365 }
349366 }
@@ -368,7 +385,8 @@ describe("CFUtil", () => {
368385 spaceGuids : [ SPACE_GUID ] ,
369386 names : [ NON_EXISTING_SERVICE_INSTANCE ]
370387 } , {
371- serviceName : SERVICE_INSTANCE ,
388+ serviceName : SERVICE ,
389+ serviceInstanceName : SERVICE_INSTANCE ,
372390 planName : PLAN ,
373391 spaceGuid : SPACE_GUID ,
374392 tags : [ "tag1" ]
@@ -380,33 +398,22 @@ describe("CFUtil", () => {
380398 name : "serviceInstance1"
381399 }
382400 } ) ;
383- } ) ;
401+ }
384402
385403 } ) ;
386404
387405 describe ( "when getting space" , ( ) => {
388406 it ( "should get space from cf if not specified in options" , async ( ) => {
389407 const CFUtil = await esmock ( "../src/util/cfUtil.js" , { } , {
390- "@sap/cf-tools/out/src/cli.js" : {
391- Cli : {
392- execute : ( args : string [ ] ) => {
393- if ( args [ 1 ] === `/v3/spaces?names=${ SPACE_NAME } ` ) {
394- return TestUtil . getStdOut ( TestUtil . getResource ( "spaces.json" ) )
395- }
396- }
397- }
398- } ,
399- "@sap/cf-tools/out/src/cf-local.js" : {
400- cfGetTarget : ( ) => Promise . resolve ( { space : SPACE_NAME , "api endpoint" : "apiEndpoint" , "api version" : "apiVersion" , user : "user" } )
408+ "@sap/cf-tools/out/src/utils.js" : {
409+ getSpaceGuidThrowIfUndefined : ( ) => Promise . resolve ( "spaceGuid1" )
401410 }
402411 } ) ;
403- const SPACE_NAME = "spaceName1"
404- const spaceGuid = await CFUtil . getSpaceGuid ( ) ;
405- expect ( spaceGuid ) . to . equal ( "spaceGuid1" ) ;
412+ expect ( await CFUtil . getSpaceGuid ( ) ) . to . equal ( "spaceGuid1" ) ;
406413 } ) ;
407414
408415 it ( "should return space guid specified in options" , async ( ) => {
409- expect ( await CFUtil . getSpaceGuid ( "spaceGuid1 " ) ) . to . equal ( "spaceGuid1 " ) ;
416+ expect ( await CFUtil . getSpaceGuid ( "spaceGuid2 " ) ) . to . equal ( "spaceGuid2 " ) ;
410417 } ) ;
411418 } ) ;
412419
0 commit comments