diff --git a/src/index.js b/src/index.js index ecd66bd..5e997ab 100644 --- a/src/index.js +++ b/src/index.js @@ -106,9 +106,9 @@ module.exports = function (serverless) { Properties: { StageName: deployment.Properties.StageName, Description: `${deployment.Properties.StageName} stage of ${serverless.service.service}`, - RestApiId: { + RestApiId: _.get(serverless, 'service.provider.apiGateway.restApiId', { Ref: 'ApiGatewayRestApi' - }, + }), DeploymentId: { Ref: deploymentKey }, diff --git a/test/mock/serverless.js b/test/mock/serverless.js index 4f00bcc..a8193f4 100644 --- a/test/mock/serverless.js +++ b/test/mock/serverless.js @@ -2,7 +2,7 @@ const sinon = require('sinon'); -module.exports = (service, stageName, deploymentKey, stageSettings) => ({ +module.exports = (service, stageName, deploymentKey, stageSettings, apiGateway) => ({ service: { service: service, provider: { @@ -16,7 +16,8 @@ module.exports = (service, stageName, deploymentKey, stageSettings) => ({ } } } - } + }, + apiGateway }, custom: { stageSettings: stageSettings diff --git a/test/spec/index.spec.js b/test/spec/index.spec.js index 9754a67..cd7fa69 100644 --- a/test/spec/index.spec.js +++ b/test/spec/index.spec.js @@ -488,4 +488,19 @@ describe('The `serverless-api-stage` plugin', function () { }); }); }); + describe('Using non default restApiId`', function () { + let serverless, pluginInstance; + beforeEach(function () { + serverless = mockServerless('service', 'testing', 'Deployment', {}, {restApiId: 'foobar'}); + pluginInstance = new ApiStagePlugin(serverless); + }); + describe('When the `before:deploy:deploy` hook is executed', function () { + beforeEach(function () { + pluginInstance.hooks['before:deploy:deploy'](); + }); + it('Adds an API Gateway Stage resource to the CloudFormation template with specified variables and settings', function () { + expect(serverless.service.provider.compiledCloudFormationTemplate.Resources.ApiGatewayStageTesting.Properties.RestApiId).to.equal(serverless.service.provider.apiGateway.restApiId); + }); + }); + }); });