-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-post.test.ts
74 lines (72 loc) · 2.08 KB
/
create-post.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Stack } from 'aws-cdk-lib';
import { Match, Template } from 'aws-cdk-lib/assertions';
import { AttributeType, Table } from 'aws-cdk-lib/aws-dynamodb';
import { CreatePost } from '../../src/components/create-post';
import { Api } from '../../src/constructs/api';
import { Monitoring } from '../../src/constructs/monitoring';
/**
* In this test we are testing the "CreatePost" construct
* and asserting that certain things unique to this construct are set
*/
test('resources are created with expected properties', () => {
const stack = new Stack();
const monitor = new Monitoring(stack, 'Monitor');
new CreatePost(stack, 'CreatePost', {
api: new Api(stack, 'Api', {
monitor,
}),
monitor,
table: new Table(stack, 'Table', {
partitionKey: {
name: 'pk',
type: AttributeType.STRING,
},
}),
});
const template = Template.fromStack(stack);
template.hasResourceProperties('AWS::Lambda::Function', {
Environment: {
Variables: {
LOG_LEVEL: 'DEBUG',
POWERTOOLS_LOGGER_LOG_EVENT: 'true',
POWERTOOLS_SERVICE_NAME: 'CreateFunction',
POWERTOOLS_METRICS_NAMESPACE: 'blogApp',
ENV: 'dev',
TABLE_NAME: { Ref: 'TableCD117FA1' },
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
},
},
TracingConfig: { Mode: 'Active' },
Layers: [
{
'Fn::Join': [
'',
Match.arrayWith([
Match.stringLikeRegexp('AWSLambdaPowertoolsTypeScript'),
]),
],
},
],
});
template.hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Statement: Match.arrayWith([
Match.objectLike({
Action: Match.arrayWith([
'xray:PutTraceSegments',
'xray:PutTelemetryRecords',
]),
}),
Match.objectLike({
Action: Match.arrayWith([
'dynamodb:BatchWriteItem',
'dynamodb:PutItem',
'dynamodb:UpdateItem',
'dynamodb:DeleteItem',
'dynamodb:DescribeTable',
]),
}),
]),
},
});
});