|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const expect = require('chai').expect; |
| 4 | +const Serverless = require('serverless/lib/Serverless'); |
| 5 | +const AwsProvider = require('serverless/lib/plugins/aws/provider/awsProvider'); |
| 6 | +const ServerlessStepFunctions = require('./../../../index'); |
| 7 | + |
| 8 | +describe('#compileDeployment()', () => { |
| 9 | + let serverless; |
| 10 | + let serverlessStepFunctions; |
| 11 | + |
| 12 | + beforeEach(() => { |
| 13 | + serverless = new Serverless(); |
| 14 | + serverless.setProvider('aws', new AwsProvider(serverless)); |
| 15 | + serverless.service.provider.compiledCloudFormationTemplate = { |
| 16 | + Resources: {}, |
| 17 | + Outputs: {}, |
| 18 | + }; |
| 19 | + const options = { |
| 20 | + stage: 'dev', |
| 21 | + region: 'us-east-1', |
| 22 | + }; |
| 23 | + serverlessStepFunctions = new ServerlessStepFunctions(serverless, options); |
| 24 | + serverlessStepFunctions.apiGatewayRestApiLogicalId = 'ApiGatewayRestApi'; |
| 25 | + serverlessStepFunctions.apiGatewayMethodLogicalIds |
| 26 | + = ['method-dependency1', 'method-dependency2']; |
| 27 | + }); |
| 28 | + |
| 29 | + it('should create a deployment resource', () => serverlessStepFunctions |
| 30 | + .compileDeployment().then(() => { |
| 31 | + const apiGatewayDeploymentLogicalId = Object |
| 32 | + .keys(serverlessStepFunctions.serverless.service.provider |
| 33 | + .compiledCloudFormationTemplate.Resources)[0]; |
| 34 | + |
| 35 | + expect( |
| 36 | + serverlessStepFunctions.serverless.service.provider.compiledCloudFormationTemplate |
| 37 | + .Resources[apiGatewayDeploymentLogicalId] |
| 38 | + ).to.deep.equal({ |
| 39 | + Type: 'AWS::ApiGateway::Deployment', |
| 40 | + DependsOn: ['method-dependency1', 'method-dependency2'], |
| 41 | + Properties: { |
| 42 | + RestApiId: { Ref: serverlessStepFunctions.apiGatewayRestApiLogicalId }, |
| 43 | + StageName: 'dev', |
| 44 | + }, |
| 45 | + }); |
| 46 | + }) |
| 47 | + ); |
| 48 | + |
| 49 | + it('should add service endpoint output', () => |
| 50 | + serverlessStepFunctions.compileDeployment().then(() => { |
| 51 | + expect( |
| 52 | + serverlessStepFunctions.serverless.service.provider.compiledCloudFormationTemplate |
| 53 | + .Outputs.ServiceEndpoint |
| 54 | + ).to.deep.equal({ |
| 55 | + Description: 'URL of the service endpoint', |
| 56 | + Value: { |
| 57 | + 'Fn::Join': [ |
| 58 | + '', |
| 59 | + [ |
| 60 | + 'https://', |
| 61 | + { Ref: serverlessStepFunctions.apiGatewayRestApiLogicalId }, |
| 62 | + '.execute-api.us-east-1.amazonaws.com/dev', |
| 63 | + ], |
| 64 | + ], |
| 65 | + }, |
| 66 | + }); |
| 67 | + }) |
| 68 | + ); |
| 69 | +}); |
0 commit comments