diff --git a/lib/plugins/aws/package/compile/events/websockets/index.js b/lib/plugins/aws/package/compile/events/websockets/index.js index 942209b76ea..9379042566f 100644 --- a/lib/plugins/aws/package/compile/events/websockets/index.js +++ b/lib/plugins/aws/package/compile/events/websockets/index.js @@ -32,7 +32,7 @@ class AwsCompileWebsockets { ); this.hooks = { - 'package:compileEvents': () => { + 'package:compileEvents': async () => { this.validated = this.validate(); if (this.validated.events.length === 0) { diff --git a/lib/plugins/aws/package/compile/events/websockets/lib/api.js b/lib/plugins/aws/package/compile/events/websockets/lib/api.js index 687236acc6b..6660e043e89 100644 --- a/lib/plugins/aws/package/compile/events/websockets/lib/api.js +++ b/lib/plugins/aws/package/compile/events/websockets/lib/api.js @@ -1,7 +1,6 @@ 'use strict'; const _ = require('lodash'); -const BbPromise = require('bluebird'); module.exports = { compileApi() { @@ -9,7 +8,7 @@ module.exports = { // immediately return if we're using an external websocket API id if (apiGateway.websocketApiId) { - return BbPromise.resolve(); + return; } this.websocketsApiLogicalId = this.provider.naming.getWebsocketsApiLogicalId(); @@ -46,7 +45,5 @@ module.exports = { this.provider.naming.getRoleLogicalId() ].Properties.Policies[0].PolicyDocument.Statement.push(websocketsPolicy); } - - return BbPromise.resolve(); }, }; diff --git a/lib/plugins/aws/package/compile/events/websockets/lib/authorizers.js b/lib/plugins/aws/package/compile/events/websockets/lib/authorizers.js index 88f78e282b9..4d3efcbaaf9 100644 --- a/lib/plugins/aws/package/compile/events/websockets/lib/authorizers.js +++ b/lib/plugins/aws/package/compile/events/websockets/lib/authorizers.js @@ -1,7 +1,6 @@ 'use strict'; const _ = require('lodash'); -const BbPromise = require('bluebird'); module.exports = { compileAuthorizers() { @@ -27,6 +26,6 @@ module.exports = { }); }); - return BbPromise.resolve(); + return; }, }; diff --git a/lib/plugins/aws/package/compile/events/websockets/lib/deployment.js b/lib/plugins/aws/package/compile/events/websockets/lib/deployment.js index 608ad352737..2f0c1724243 100644 --- a/lib/plugins/aws/package/compile/events/websockets/lib/deployment.js +++ b/lib/plugins/aws/package/compile/events/websockets/lib/deployment.js @@ -2,7 +2,6 @@ const _ = require('lodash'); const crypto = require('crypto'); -const BbPromise = require('bluebird'); const pickWebsocketsTemplatePart = require('./pickWebsocketsTemplatePart'); module.exports = { @@ -71,7 +70,5 @@ module.exports = { Ref: this.websocketsDeploymentLogicalId, }; } - - return BbPromise.resolve(); }, }; diff --git a/lib/plugins/aws/package/compile/events/websockets/lib/integrations.js b/lib/plugins/aws/package/compile/events/websockets/lib/integrations.js index 7006151d83c..09ebeb44045 100644 --- a/lib/plugins/aws/package/compile/events/websockets/lib/integrations.js +++ b/lib/plugins/aws/package/compile/events/websockets/lib/integrations.js @@ -1,7 +1,6 @@ 'use strict'; const _ = require('lodash'); -const BbPromise = require('bluebird'); module.exports = { compileIntegrations() { @@ -35,7 +34,5 @@ module.exports = { }, }); }); - - return BbPromise.resolve(); }, }; diff --git a/lib/plugins/aws/package/compile/events/websockets/lib/permissions.js b/lib/plugins/aws/package/compile/events/websockets/lib/permissions.js index d534ff8621b..c0cdfb859f8 100644 --- a/lib/plugins/aws/package/compile/events/websockets/lib/permissions.js +++ b/lib/plugins/aws/package/compile/events/websockets/lib/permissions.js @@ -1,7 +1,6 @@ 'use strict'; const _ = require('lodash'); -const BbPromise = require('bluebird'); module.exports = { compilePermissions() { @@ -65,7 +64,5 @@ module.exports = { ); } }); - - return BbPromise.resolve(); }, }; diff --git a/lib/plugins/aws/package/compile/events/websockets/lib/routes.js b/lib/plugins/aws/package/compile/events/websockets/lib/routes.js index b19febca63d..da4031af7b5 100644 --- a/lib/plugins/aws/package/compile/events/websockets/lib/routes.js +++ b/lib/plugins/aws/package/compile/events/websockets/lib/routes.js @@ -1,7 +1,6 @@ 'use strict'; const _ = require('lodash'); -const BbPromise = require('bluebird'); module.exports = { compileRoutes() { @@ -44,7 +43,5 @@ module.exports = { routeTemplate ); }); - - return BbPromise.resolve(); }, }; diff --git a/lib/plugins/aws/package/compile/events/websockets/lib/stage.js b/lib/plugins/aws/package/compile/events/websockets/lib/stage.js index 8fcfca89833..74038bc125b 100644 --- a/lib/plugins/aws/package/compile/events/websockets/lib/stage.js +++ b/lib/plugins/aws/package/compile/events/websockets/lib/stage.js @@ -8,7 +8,7 @@ const defaultLogLevel = 'INFO'; const validLogLevels = new Set(['INFO', 'ERROR']); module.exports = { - compileStage() { + async compileStage() { return BbPromise.try(() => { const { service, provider } = this.serverless.service; const stage = this.options.stage; diff --git a/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/api.test.js b/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/api.test.js index 1cedbb8873b..ea87b825839 100644 --- a/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/api.test.js +++ b/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/api.test.js @@ -33,72 +33,70 @@ describe('#compileApi()', () => { }; }); - it('should create a websocket api resource', () => - awsCompileWebsocketsEvents.compileApi().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; + it('should create a websocket api resource', () => { + awsCompileWebsocketsEvents.compileApi(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; - expect(resources.WebsocketsApi).to.deep.equal({ - Type: 'AWS::ApiGatewayV2::Api', - Properties: { - Name: 'dev-my-service-websockets', - RouteSelectionExpression: '$request.body.action', - Description: 'Serverless Websockets', - ProtocolType: 'WEBSOCKET', - }, - }); - })); + expect(resources.WebsocketsApi).to.deep.equal({ + Type: 'AWS::ApiGatewayV2::Api', + Properties: { + Name: 'dev-my-service-websockets', + RouteSelectionExpression: '$request.body.action', + Description: 'Serverless Websockets', + ProtocolType: 'WEBSOCKET', + }, + }); + }); it('should ignore API resource creation if there is predefined websocketApi config', () => { awsCompileWebsocketsEvents.serverless.service.provider.apiGateway = { websocketApiId: '5ezys3sght', }; - return awsCompileWebsocketsEvents.compileApi().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; + awsCompileWebsocketsEvents.compileApi(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; - expect(resources).to.not.have.property('WebsocketsApi'); - }); + expect(resources).to.not.have.property('WebsocketsApi'); }); - it('should add the websockets policy', () => - awsCompileWebsocketsEvents.compileApi().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; + it('should add the websockets policy', () => { + awsCompileWebsocketsEvents.compileApi(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; - expect(resources[roleLogicalId]).to.deep.equal({ - Properties: { - Policies: [ - { - PolicyDocument: { - Statement: [ - { - Action: ['execute-api:ManageConnections'], - Effect: 'Allow', - Resource: [ - { 'Fn::Sub': 'arn:${AWS::Partition}:execute-api:*:*:*/@connections/*' }, - ], - }, - ], - }, + expect(resources[roleLogicalId]).to.deep.equal({ + Properties: { + Policies: [ + { + PolicyDocument: { + Statement: [ + { + Action: ['execute-api:ManageConnections'], + Effect: 'Allow', + Resource: [ + { 'Fn::Sub': 'arn:${AWS::Partition}:execute-api:*:*:*/@connections/*' }, + ], + }, + ], }, - ], - }, - }); - })); + }, + ], + }, + }); + }); it('should NOT add the websockets policy if role resource does not exist', () => { awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate.Resources = {}; - return awsCompileWebsocketsEvents.compileApi().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; + awsCompileWebsocketsEvents.compileApi(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; - expect(resources[roleLogicalId]).to.deep.equal(undefined); - }); + expect(resources[roleLogicalId]).to.deep.equal(undefined); }); }); diff --git a/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/authorizers.test.js b/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/authorizers.test.js index aa644744b1d..9cf51b2bfdf 100644 --- a/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/authorizers.test.js +++ b/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/authorizers.test.js @@ -47,44 +47,43 @@ describe('#compileAuthorizers()', () => { }); it('should create an authorizer resource', () => { - return awsCompileWebsocketsEvents.compileAuthorizers().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; - - expect(resources).to.deep.equal({ - AuthWebsocketsAuthorizer: { - Type: 'AWS::ApiGatewayV2::Authorizer', - Properties: { - ApiId: { - Ref: 'WebsocketsApi', - }, - Name: 'auth', - AuthorizerType: 'REQUEST', - AuthorizerUri: { - 'Fn::Join': [ - '', - [ - 'arn:', - { - Ref: 'AWS::Partition', - }, - ':apigateway:', - { - Ref: 'AWS::Region', - }, - ':lambda:path/2015-03-31/functions/', - { - 'Fn::GetAtt': ['AuthLambdaFunction', 'Arn'], - }, - '/invocations', - ], + awsCompileWebsocketsEvents.compileAuthorizers(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; + + expect(resources).to.deep.equal({ + AuthWebsocketsAuthorizer: { + Type: 'AWS::ApiGatewayV2::Authorizer', + Properties: { + ApiId: { + Ref: 'WebsocketsApi', + }, + Name: 'auth', + AuthorizerType: 'REQUEST', + AuthorizerUri: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':apigateway:', + { + Ref: 'AWS::Region', + }, + ':lambda:path/2015-03-31/functions/', + { + 'Fn::GetAtt': ['AuthLambdaFunction', 'Arn'], + }, + '/invocations', ], - }, - IdentitySource: ['route.request.header.Auth'], + ], }, + IdentitySource: ['route.request.header.Auth'], }, - }); + }, }); }); @@ -93,14 +92,13 @@ describe('#compileAuthorizers()', () => { websocketApiId: '5ezys3sght', }; - return awsCompileWebsocketsEvents.compileAuthorizers().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; + awsCompileWebsocketsEvents.compileAuthorizers(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; - expect(resources.AuthWebsocketsAuthorizer.Properties).to.contain({ - ApiId: '5ezys3sght', - }); + expect(resources.AuthWebsocketsAuthorizer.Properties).to.contain({ + ApiId: '5ezys3sght', }); }); }); @@ -135,13 +133,12 @@ describe('#compileAuthorizers()', () => { ], }; - return awsCompileWebsocketsEvents.compileAuthorizers().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; + awsCompileWebsocketsEvents.compileAuthorizers(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; - expect(resources).to.deep.equal({}); - }); + expect(resources).to.deep.equal({}); }); }); }); diff --git a/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/deployment.test.js b/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/deployment.test.js index e6cd01f6a59..b1cb4c04041 100644 --- a/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/deployment.test.js +++ b/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/deployment.test.js @@ -39,52 +39,50 @@ describe('#compileDeployment()', () => { ], }; - return awsCompileWebsocketsEvents.compileDeployment().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; - const outputs = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Outputs; - - const deploymentLogicalId = Object.keys(resources)[0]; - - expect(deploymentLogicalId).to.match(/WebsocketsDeployment/); - expect(resources[deploymentLogicalId]).to.deep.equal({ - Type: 'AWS::ApiGatewayV2::Deployment', - DependsOn: ['SconnectWebsocketsRoute', 'SdisconnectWebsocketsRoute'], - Properties: { - ApiId: { - Ref: 'WebsocketsApi', - }, - Description: 'Serverless Websockets', + awsCompileWebsocketsEvents.compileDeployment(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; + const outputs = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate.Outputs; + + const deploymentLogicalId = Object.keys(resources)[0]; + + expect(deploymentLogicalId).to.match(/WebsocketsDeployment/); + expect(resources[deploymentLogicalId]).to.deep.equal({ + Type: 'AWS::ApiGatewayV2::Deployment', + DependsOn: ['SconnectWebsocketsRoute', 'SdisconnectWebsocketsRoute'], + Properties: { + ApiId: { + Ref: 'WebsocketsApi', }, - }); - expect(outputs).to.deep.equal({ - ServiceEndpointWebsocket: { - Description: 'URL of the service endpoint', - Value: { - 'Fn::Join': [ - '', - [ - 'wss://', - { - Ref: 'WebsocketsApi', - }, - '.execute-api.', - { - Ref: 'AWS::Region', - }, - '.', - { - Ref: 'AWS::URLSuffix', - }, - '/dev', - ], + Description: 'Serverless Websockets', + }, + }); + expect(outputs).to.deep.equal({ + ServiceEndpointWebsocket: { + Description: 'URL of the service endpoint', + Value: { + 'Fn::Join': [ + '', + [ + 'wss://', + { + Ref: 'WebsocketsApi', + }, + '.execute-api.', + { + Ref: 'AWS::Region', + }, + '.', + { + Ref: 'AWS::URLSuffix', + }, + '/dev', ], - }, + ], }, - }); + }, }); }); @@ -105,23 +103,22 @@ describe('#compileDeployment()', () => { websocketApiId: 'xyz123abc', }; - return awsCompileWebsocketsEvents.compileDeployment().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; - - const deploymentLogicalId = Object.keys(resources)[0]; - - expect(deploymentLogicalId).to.match(/WebsocketsDeployment/); - expect(resources[deploymentLogicalId]).to.deep.equal({ - Type: 'AWS::ApiGatewayV2::Deployment', - DependsOn: ['SconnectWebsocketsRoute', 'SdisconnectWebsocketsRoute'], - Properties: { - ApiId: 'xyz123abc', - StageName: awsCompileWebsocketsEvents.provider.getStage(), - Description: 'Serverless Websockets', - }, - }); + awsCompileWebsocketsEvents.compileDeployment(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; + + const deploymentLogicalId = Object.keys(resources)[0]; + + expect(deploymentLogicalId).to.match(/WebsocketsDeployment/); + expect(resources[deploymentLogicalId]).to.deep.equal({ + Type: 'AWS::ApiGatewayV2::Deployment', + DependsOn: ['SconnectWebsocketsRoute', 'SdisconnectWebsocketsRoute'], + Properties: { + ApiId: 'xyz123abc', + StageName: awsCompileWebsocketsEvents.provider.getStage(), + Description: 'Serverless Websockets', + }, }); }); @@ -140,14 +137,13 @@ describe('#compileDeployment()', () => { }; return awsCompileWebsocketsEvents.compileStage().then(() => { - return awsCompileWebsocketsEvents.compileDeployment().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; - - expect(resources.WebsocketsDeploymentStage.Properties.DeploymentId).to.deep.equal({ - Ref: awsCompileWebsocketsEvents.websocketsDeploymentLogicalId, - }); + awsCompileWebsocketsEvents.compileDeployment(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; + + expect(resources.WebsocketsDeploymentStage.Properties.DeploymentId).to.deep.equal({ + Ref: awsCompileWebsocketsEvents.websocketsDeploymentLogicalId, }); }); }); diff --git a/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/integrations.test.js b/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/integrations.test.js index e2b2631d966..de54f104be9 100644 --- a/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/integrations.test.js +++ b/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/integrations.test.js @@ -32,71 +32,70 @@ describe('#compileIntegrations()', () => { ], }; - return awsCompileWebsocketsEvents.compileIntegrations().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; + awsCompileWebsocketsEvents.compileIntegrations(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; - expect(resources).to.deep.equal({ - FirstWebsocketsIntegration: { - Type: 'AWS::ApiGatewayV2::Integration', - Properties: { - ApiId: { - Ref: 'WebsocketsApi', - }, - IntegrationType: 'AWS_PROXY', - IntegrationUri: { - 'Fn::Join': [ - '', - [ - 'arn:', - { - Ref: 'AWS::Partition', - }, - ':apigateway:', - { - Ref: 'AWS::Region', - }, - ':lambda:path/2015-03-31/functions/', - { - 'Fn::GetAtt': ['FirstLambdaFunction', 'Arn'], - }, - '/invocations', - ], + expect(resources).to.deep.equal({ + FirstWebsocketsIntegration: { + Type: 'AWS::ApiGatewayV2::Integration', + Properties: { + ApiId: { + Ref: 'WebsocketsApi', + }, + IntegrationType: 'AWS_PROXY', + IntegrationUri: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':apigateway:', + { + Ref: 'AWS::Region', + }, + ':lambda:path/2015-03-31/functions/', + { + 'Fn::GetAtt': ['FirstLambdaFunction', 'Arn'], + }, + '/invocations', ], - }, + ], }, }, - SecondWebsocketsIntegration: { - Type: 'AWS::ApiGatewayV2::Integration', - Properties: { - ApiId: { - Ref: 'WebsocketsApi', - }, - IntegrationType: 'AWS_PROXY', - IntegrationUri: { - 'Fn::Join': [ - '', - [ - 'arn:', - { - Ref: 'AWS::Partition', - }, - ':apigateway:', - { - Ref: 'AWS::Region', - }, - ':lambda:path/2015-03-31/functions/', - { - 'Fn::GetAtt': ['SecondLambdaFunction', 'Arn'], - }, - '/invocations', - ], + }, + SecondWebsocketsIntegration: { + Type: 'AWS::ApiGatewayV2::Integration', + Properties: { + ApiId: { + Ref: 'WebsocketsApi', + }, + IntegrationType: 'AWS_PROXY', + IntegrationUri: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':apigateway:', + { + Ref: 'AWS::Region', + }, + ':lambda:path/2015-03-31/functions/', + { + 'Fn::GetAtt': ['SecondLambdaFunction', 'Arn'], + }, + '/invocations', ], - }, + ], }, }, - }); + }, }); }); }); diff --git a/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/permissions.test.js b/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/permissions.test.js index 4b42778ed2c..93100ee5902 100644 --- a/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/permissions.test.js +++ b/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/permissions.test.js @@ -32,35 +32,34 @@ describe('#compilePermissions()', () => { ], }; - return awsCompileWebsocketsEvents.compilePermissions().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; + awsCompileWebsocketsEvents.compilePermissions(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; - expect(resources).to.deep.equal({ - FirstLambdaPermissionWebsockets: { - Type: 'AWS::Lambda::Permission', - DependsOn: ['WebsocketsApi', 'FirstLambdaFunction'], - Properties: { - FunctionName: { - 'Fn::GetAtt': ['FirstLambdaFunction', 'Arn'], - }, - Action: 'lambda:InvokeFunction', - Principal: 'apigateway.amazonaws.com', + expect(resources).to.deep.equal({ + FirstLambdaPermissionWebsockets: { + Type: 'AWS::Lambda::Permission', + DependsOn: ['WebsocketsApi', 'FirstLambdaFunction'], + Properties: { + FunctionName: { + 'Fn::GetAtt': ['FirstLambdaFunction', 'Arn'], }, + Action: 'lambda:InvokeFunction', + Principal: 'apigateway.amazonaws.com', }, - SecondLambdaPermissionWebsockets: { - Type: 'AWS::Lambda::Permission', - DependsOn: ['WebsocketsApi', 'SecondLambdaFunction'], - Properties: { - FunctionName: { - 'Fn::GetAtt': ['SecondLambdaFunction', 'Arn'], - }, - Action: 'lambda:InvokeFunction', - Principal: 'apigateway.amazonaws.com', + }, + SecondLambdaPermissionWebsockets: { + Type: 'AWS::Lambda::Permission', + DependsOn: ['WebsocketsApi', 'SecondLambdaFunction'], + Properties: { + FunctionName: { + 'Fn::GetAtt': ['SecondLambdaFunction', 'Arn'], }, + Action: 'lambda:InvokeFunction', + Principal: 'apigateway.amazonaws.com', }, - }); + }, }); }); @@ -78,35 +77,34 @@ describe('#compilePermissions()', () => { ], }; - return awsCompileWebsocketsEvents.compilePermissions().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; + awsCompileWebsocketsEvents.compilePermissions(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; - expect(resources).to.deep.equal({ - FirstLambdaPermissionWebsockets: { - Type: 'AWS::Lambda::Permission', - DependsOn: ['WebsocketsApi', 'FirstLambdaFunction'], - Properties: { - FunctionName: { - 'Fn::GetAtt': ['FirstLambdaFunction', 'Arn'], - }, - Action: 'lambda:InvokeFunction', - Principal: 'apigateway.amazonaws.com', + expect(resources).to.deep.equal({ + FirstLambdaPermissionWebsockets: { + Type: 'AWS::Lambda::Permission', + DependsOn: ['WebsocketsApi', 'FirstLambdaFunction'], + Properties: { + FunctionName: { + 'Fn::GetAtt': ['FirstLambdaFunction', 'Arn'], }, + Action: 'lambda:InvokeFunction', + Principal: 'apigateway.amazonaws.com', }, - AuthLambdaPermissionWebsockets: { - Type: 'AWS::Lambda::Permission', - DependsOn: ['WebsocketsApi', 'AuthLambdaPermissionWebsockets'], - Properties: { - FunctionName: { - 'Fn::GetAtt': ['AuthLambdaPermissionWebsockets', 'Arn'], - }, - Action: 'lambda:InvokeFunction', - Principal: 'apigateway.amazonaws.com', + }, + AuthLambdaPermissionWebsockets: { + Type: 'AWS::Lambda::Permission', + DependsOn: ['WebsocketsApi', 'AuthLambdaPermissionWebsockets'], + Properties: { + FunctionName: { + 'Fn::GetAtt': ['AuthLambdaPermissionWebsockets', 'Arn'], }, + Action: 'lambda:InvokeFunction', + Principal: 'apigateway.amazonaws.com', }, - }); + }, }); }); }); diff --git a/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/routes.test.js b/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/routes.test.js index 36123794ad5..23d99e82039 100644 --- a/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/routes.test.js +++ b/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/routes.test.js @@ -32,55 +32,54 @@ describe('#compileRoutes()', () => { ], }; - return awsCompileWebsocketsEvents.compileRoutes().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; + awsCompileWebsocketsEvents.compileRoutes(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; - expect(resources).to.deep.equal({ - SconnectWebsocketsRoute: { - Type: 'AWS::ApiGatewayV2::Route', - Properties: { - ApiId: { - Ref: 'WebsocketsApi', - }, - RouteKey: '$connect', - AuthorizationType: 'NONE', - Target: { - 'Fn::Join': [ - '/', - [ - 'integrations', - { - Ref: 'FirstWebsocketsIntegration', - }, - ], + expect(resources).to.deep.equal({ + SconnectWebsocketsRoute: { + Type: 'AWS::ApiGatewayV2::Route', + Properties: { + ApiId: { + Ref: 'WebsocketsApi', + }, + RouteKey: '$connect', + AuthorizationType: 'NONE', + Target: { + 'Fn::Join': [ + '/', + [ + 'integrations', + { + Ref: 'FirstWebsocketsIntegration', + }, ], - }, + ], }, }, - SdisconnectWebsocketsRoute: { - Type: 'AWS::ApiGatewayV2::Route', - Properties: { - ApiId: { - Ref: 'WebsocketsApi', - }, - RouteKey: '$disconnect', - AuthorizationType: 'NONE', - Target: { - 'Fn::Join': [ - '/', - [ - 'integrations', - { - Ref: 'SecondWebsocketsIntegration', - }, - ], + }, + SdisconnectWebsocketsRoute: { + Type: 'AWS::ApiGatewayV2::Route', + Properties: { + ApiId: { + Ref: 'WebsocketsApi', + }, + RouteKey: '$disconnect', + AuthorizationType: 'NONE', + Target: { + 'Fn::Join': [ + '/', + [ + 'integrations', + { + Ref: 'SecondWebsocketsIntegration', + }, ], - }, + ], }, }, - }); + }, }); }); @@ -95,35 +94,34 @@ describe('#compileRoutes()', () => { ], }; - return awsCompileWebsocketsEvents.compileRoutes().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; + awsCompileWebsocketsEvents.compileRoutes(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; - expect(resources).to.deep.equal({ - SconnectWebsocketsRoute: { - Type: 'AWS::ApiGatewayV2::Route', - Properties: { - ApiId: { - Ref: 'WebsocketsApi', - }, - RouteKey: '$connect', - AuthorizationType: 'NONE', - RouteResponseSelectionExpression: '$default', - Target: { - 'Fn::Join': [ - '/', - [ - 'integrations', - { - Ref: 'FirstWebsocketsIntegration', - }, - ], + expect(resources).to.deep.equal({ + SconnectWebsocketsRoute: { + Type: 'AWS::ApiGatewayV2::Route', + Properties: { + ApiId: { + Ref: 'WebsocketsApi', + }, + RouteKey: '$connect', + AuthorizationType: 'NONE', + RouteResponseSelectionExpression: '$default', + Target: { + 'Fn::Join': [ + '/', + [ + 'integrations', + { + Ref: 'FirstWebsocketsIntegration', + }, ], - }, + ], }, }, - }); + }, }); }); @@ -140,39 +138,38 @@ describe('#compileRoutes()', () => { ], }; - return awsCompileWebsocketsEvents.compileRoutes().then(() => { - const resources = - awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate - .Resources; + awsCompileWebsocketsEvents.compileRoutes(); + const resources = + awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources; - expect(resources).to.deep.equal({ - SconnectWebsocketsRoute: { - Type: 'AWS::ApiGatewayV2::Route', - Properties: { - ApiId: { - Ref: 'WebsocketsApi', - }, - RouteKey: '$connect', - AuthorizationType: 'CUSTOM', - AuthorizerId: { - Ref: awsCompileWebsocketsEvents.provider.naming.getWebsocketsAuthorizerLogicalId( - 'auth' - ), - }, - Target: { - 'Fn::Join': [ - '/', - [ - 'integrations', - { - Ref: 'FirstWebsocketsIntegration', - }, - ], + expect(resources).to.deep.equal({ + SconnectWebsocketsRoute: { + Type: 'AWS::ApiGatewayV2::Route', + Properties: { + ApiId: { + Ref: 'WebsocketsApi', + }, + RouteKey: '$connect', + AuthorizationType: 'CUSTOM', + AuthorizerId: { + Ref: awsCompileWebsocketsEvents.provider.naming.getWebsocketsAuthorizerLogicalId( + 'auth' + ), + }, + Target: { + 'Fn::Join': [ + '/', + [ + 'integrations', + { + Ref: 'FirstWebsocketsIntegration', + }, ], - }, + ], }, }, - }); + }, }); }); });