/
api-stack.test.ts
48 lines (41 loc) · 1.29 KB
/
api-stack.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
import { describe, it, beforeAll } from '@jest/globals'
import * as cdk from 'aws-cdk-lib'
import { Template } from 'aws-cdk-lib/assertions'
import { ExampleAPIStack } from '../ExampleAPI'
import fs from 'node:fs'
const getTemplate = (): Template => {
const app = new cdk.App()
const stack = new ExampleAPIStack(app, 'MyTestStack', {
env: {
account: '1234567890',
region: 'eu-west-2'
}
},
{
hostedZoneDomain: 'dummy.domain.name',
serviceDataBucketName: 'test-stack-stub-bucket-name',
identity: {
verifiers: []
}
})
const template = Template.fromStack(stack)
fs.writeFileSync('src/tests/template.json', JSON.stringify(template, null, 2))
return template
}
describe('REST API using Harness as Test Bed', () => {
let template: Template
beforeAll(() => {
template = getTemplate()
})
it('Creates an AWS ApiGateway RestApi with the correct title and description', () => {
template.hasResourceProperties('AWS::ApiGateway::RestApi', {
Description: 'Example API - https://github.com/connected-web/openapi-rest-api',
Name: 'Example API'
})
})
it('Creates a AWS ApiGateway Method with the operationId - getStatus', () => {
template.hasResourceProperties('AWS::ApiGateway::Method', {
OperationName: 'getStatus'
})
})
})