Skip to content

Commit 129c0ee

Browse files
authored
test(AWS Websocket): Refactor API tests (#10466)
1 parent 46d090a commit 129c0ee

File tree

2 files changed

+31
-118
lines changed

2 files changed

+31
-118
lines changed

test/unit/lib/plugins/aws/package/compile/events/websockets/index.test.js

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ describe('AwsCompileWebsocketsEvents', () => {
114114
});
115115

116116
describe('test/unit/lib/plugins/aws/package/compile/events/websockets/index.test.js', () => {
117-
describe.skip('TODO: regular configuration', () => {
117+
describe('regular configuration', () => {
118+
let cfTemplate;
119+
let awsNaming;
118120
before(async () => {
119-
await runServerless({
121+
({ cfTemplate, awsNaming } = await runServerless({
120122
fixture: 'function',
121123
command: 'package',
122124

@@ -131,23 +133,39 @@ describe('test/unit/lib/plugins/aws/package/compile/events/websockets/index.test
131133
},
132134
},
133135
},
134-
});
136+
}));
135137
});
136138

137139
it('should create a websocket api resource', () => {
138-
// Replaces
139-
// https://github.com/serverless/serverless/blob/f64f7c68abb1d6837ecaa6173f4b605cf3975acf/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/api.test.js#L37-L52
140+
const websocketsApiName = awsNaming.getWebsocketsApiName();
141+
expect(cfTemplate.Resources.WebsocketsApi).to.deep.equal({
142+
Type: 'AWS::ApiGatewayV2::Api',
143+
Properties: {
144+
Name: websocketsApiName,
145+
RouteSelectionExpression: '$request.body.action',
146+
Description: 'Serverless Websockets',
147+
ProtocolType: 'WEBSOCKET',
148+
},
149+
});
140150
});
141151

142152
it('should configure expected IAM', () => {
143-
// Replaces
144-
// https://github.com/serverless/serverless/blob/f64f7c68abb1d6837ecaa6173f4b605cf3975acf/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/api.test.js#L66-L91
153+
const id = awsNaming.getRoleLogicalId();
154+
expect(
155+
cfTemplate.Resources[id].Properties.Policies[0].PolicyDocument.Statement
156+
).to.deep.include({
157+
Effect: 'Allow',
158+
Action: ['execute-api:ManageConnections'],
159+
Resource: [{ 'Fn::Sub': 'arn:${AWS::Partition}:execute-api:*:*:*/@connections/*' }],
160+
});
145161
});
146162
});
147163

148-
describe.skip('TODO: external websocket API', () => {
164+
describe('external websocket API', () => {
165+
let cfTemplate;
166+
let awsNaming;
149167
before(async () => {
150-
await runServerless({
168+
({ cfTemplate, awsNaming } = await runServerless({
151169
fixture: 'function',
152170
command: 'package',
153171

@@ -170,17 +188,16 @@ describe('test/unit/lib/plugins/aws/package/compile/events/websockets/index.test
170188
},
171189
},
172190
},
173-
});
191+
}));
174192
});
175193

176194
it('should not create a websocket api resource', () => {
177-
// Replaces
178-
// https://github.com/serverless/serverless/blob/f64f7c68abb1d6837ecaa6173f4b605cf3975acf/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/api.test.js#L54-L64
195+
expect(cfTemplate.Resources.WebsocketsApi).to.equal(undefined);
179196
});
180197

181198
it('should not configure IAM policies with custom roles', () => {
182-
// Replaces
183-
// https://github.com/serverless/serverless/blob/f64f7c68abb1d6837ecaa6173f4b605cf3975acf/test/unit/lib/plugins/aws/package/compile/events/websockets/lib/api.test.js#L93-L103
199+
const id = awsNaming.getRoleLogicalId();
200+
expect(cfTemplate.Resources[id]).to.equal(undefined);
184201
});
185202
});
186203
});

test/unit/lib/plugins/aws/package/compile/events/websockets/lib/api.test.js

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)