11const APP_ROOT = '..' ;
22const given = require ( `${ APP_ROOT } /test/steps/given` ) ;
33const expect = require ( 'chai' ) . expect ;
4- const { restApiExists } = require ( `${ APP_ROOT } /src/restApiId` ) ;
4+ const { restApiExists, retrieveRestApiId } = require ( `${ APP_ROOT } /src/restApiId` ) ;
55const ApiGatewayCachingSettings = require ( `${ APP_ROOT } /src/ApiGatewayCachingSettings` ) ;
66
77describe ( 'Finding the REST API' , ( ) => {
88 let result ;
99
1010 describe ( 'when the REST API ID has been specified in the settings' , ( ) => {
11- before ( ( ) => {
11+ before ( async ( ) => {
1212 let serverless = given
1313 . a_serverless_instance ( )
1414 . withApiGatewayCachingConfig ( { restApiId : given . a_rest_api_id ( ) } ) ;
1515
1616 let settings = new ApiGatewayCachingSettings ( serverless ) ;
1717
18- result = restApiExists ( serverless , settings ) ;
18+ result = await restApiExists ( serverless , settings ) ;
1919 } ) ;
2020
2121 it ( 'should return that the REST API exists' , ( ) => {
@@ -24,30 +24,54 @@ describe('Finding the REST API', () => {
2424 } ) ;
2525
2626 describe ( 'when the REST API ID has already been defined in serverless configuration' , ( ) => {
27- before ( ( ) => {
27+ before ( async ( ) => {
2828 let serverless = given
2929 . a_serverless_instance ( )
3030 . withProviderRestApiId ( given . a_rest_api_id ( ) ) ;
31+ settings = new ApiGatewayCachingSettings ( serverless ) ;
3132
32- result = restApiExists ( serverless ) ;
33+ result = await restApiExists ( serverless , settings ) ;
3334 } ) ;
3435
3536 it ( 'should return that the REST API exists' , ( ) => {
3637 expect ( result ) . to . be . true ;
3738 } ) ;
3839 } ) ;
3940
41+ describe ( 'when the CloudFormation stack has already been deployed and it output a RestApiIdForApigCaching' , ( ) => {
42+ let restApiId , serverless , settings ;
43+ before ( async ( ) => {
44+ serverless = given
45+ . a_serverless_instance ( ) ;
46+
47+ settings = new ApiGatewayCachingSettings ( serverless ) ;
48+ restApiId = given . a_rest_api_id_for_deployment ( serverless , settings ) ;
49+
50+ result = await restApiExists ( serverless , settings ) ;
51+ } ) ;
52+
53+ it ( 'should return that the REST API exists' , ( ) => {
54+ expect ( result ) . to . be . true ;
55+ } ) ;
56+
57+ it ( 'should return the value of the REST API id' , async ( ) => {
58+ const retrievedRestApiId = await retrieveRestApiId ( serverless , settings ) ;
59+ expect ( retrievedRestApiId ) . to . equal ( restApiId ) ;
60+ } ) ;
61+ } ) ;
62+
4063 describe ( 'when the REST API has not been defined in serverless configuration' , ( ) => {
4164 describe ( 'and there are HTTP handler functions' , ( ) => {
42- before ( ( ) => {
65+ before ( async ( ) => {
4366 let functionWithHttpEndpoint = given
4467 . a_serverless_function ( 'get-cat-by-paw-id' )
4568 . withHttpEndpoint ( 'get' , '/cat/{pawId}' ) ;
4669 serverless = given
4770 . a_serverless_instance ( )
4871 . withFunction ( functionWithHttpEndpoint ) ;
72+ settings = new ApiGatewayCachingSettings ( serverless ) ;
4973
50- result = restApiExists ( serverless ) ;
74+ result = await restApiExists ( serverless , settings ) ;
5175 } ) ;
5276
5377 it ( 'should return that the REST API does exist' , ( ) => {
@@ -56,10 +80,12 @@ describe('Finding the REST API', () => {
5680 } ) ;
5781
5882 describe ( 'and there are no HTTP handler functions' , ( ) => {
59- before ( ( ) => {
83+ before ( async ( ) => {
6084 serverless = given . a_serverless_instance ( ) ;
85+ settings = new ApiGatewayCachingSettings ( serverless ) ;
86+ given . the_rest_api_id_is_not_set_for_deployment ( serverless , settings ) ;
6187
62- result = restApiExists ( serverless ) ;
88+ result = await restApiExists ( serverless , settings ) ;
6389 } ) ;
6490
6591 it ( 'should return that the REST API does not exist' , ( ) => {
0 commit comments