-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-post.test.ts
91 lines (88 loc) · 2.46 KB
/
get-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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { Stack } from 'aws-cdk-lib';
import { Match, Template } from 'aws-cdk-lib/assertions';
import { AttributeType, Table } from 'aws-cdk-lib/aws-dynamodb';
import { GetPost } from '../../src/components/get-post';
import { Network } from '../../src/components/network';
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', () => {
// GIVEN
const stack = new Stack();
const monitor = new Monitoring(stack, 'Monitor');
const network = new Network(stack, 'Network');
// WHEN
new GetPost(stack, 'CreatePost', {
api: new Api(stack, 'Api', {
vpc: network.cluster.vpc,
monitor,
}),
cluster: network.cluster,
monitor,
table: new Table(stack, 'Table', {
partitionKey: {
name: 'pk',
type: AttributeType.STRING,
},
}),
});
// THEN
const template = Template.fromStack(stack);
template.hasResourceProperties('AWS::ECS::TaskDefinition', {
ContainerDefinitions: Match.arrayWith([
Match.objectLike({
Name: 'getPost',
Environment: [
{
Name: 'TABLE_NAME',
Value: { Ref: 'TableCD117FA1' },
},
{
Name: 'AWS_EMF_AGENT_ENDPOINT',
Value: 'tcp://127.0.0.1:25888',
},
{
Name: 'LOG_LEVEL',
Value: 'DEBUG',
},
{
Name: 'POWERTOOLS_SERVICE_NAME',
Value: 'GetPostService',
},
{
Name: 'POWERTOOLS_METRICS_NAMESPACE',
Value: 'blogApp',
},
{
Name: 'ENV',
Value: 'dev',
},
],
}),
]),
});
template.hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: Match.objectLike({
Statement: Match.arrayWith([
Match.objectLike({
Action: 'cloudwatch:PutMetricData',
}),
Match.objectLike({
Action: Match.arrayWith([
'dynamodb:BatchGetItem',
'dynamodb:GetRecords',
'dynamodb:GetShardIterator',
'dynamodb:Query',
'dynamodb:GetItem',
'dynamodb:Scan',
'dynamodb:ConditionCheckItem',
'dynamodb:DescribeTable',
]),
}),
]),
}),
});
});