-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathbasic-api-key.e2e.test.ts
More file actions
62 lines (53 loc) · 1.91 KB
/
basic-api-key.e2e.test.ts
File metadata and controls
62 lines (53 loc) · 1.91 KB
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
import { synthesize } from './helpers/synthesize';
import {
countResourcesByType,
expectAuthenticationType,
expectDataSourceOfType,
expectResourceWithProperties,
findOneResourceByType,
getGraphQlApi,
} from './helpers/assertions';
describe('examples/basic-api-key', () => {
let result: ReturnType<typeof synthesize>;
beforeAll(() => {
result = synthesize('examples/basic-api-key');
});
afterAll(() => {
result.cleanup();
});
it('produces a GraphQLApi with API_KEY authentication', () => {
const { resource } = getGraphQlApi(result.template);
expect(resource.Properties?.Name).toBe('basic-api-key');
expectAuthenticationType(result.template, 'API_KEY');
});
it('creates a default API key with the configured description', () => {
expectResourceWithProperties(result.template, 'AWS::AppSync::ApiKey', {
Description: 'Default API key',
});
});
it('creates a GraphQLSchema bound to the API', () => {
findOneResourceByType(result.template, 'AWS::AppSync::GraphQLSchema');
});
it('creates the DynamoDB data source with an IAM role', () => {
const ds = expectDataSourceOfType(result.template, 'AMAZON_DYNAMODB');
expect(ds.resource.Properties?.Name).toBe('users');
// Each AppSync data source needs an IAM role so AppSync can read/write
expect(
countResourcesByType(result.template, 'AWS::IAM::Role'),
).toBeGreaterThan(0);
});
it('creates the Query.getUser resolver wired to the data source', () => {
expectResourceWithProperties(result.template, 'AWS::AppSync::Resolver', {
TypeName: 'Query',
FieldName: 'getUser',
Kind: 'UNIT',
});
});
it('does not create any additional auth provider resources', () => {
// API_KEY only — no Cognito, no Lambda authorizer
const api = getGraphQlApi(result.template);
expect(
api.resource.Properties?.AdditionalAuthenticationProviders,
).toBeUndefined();
});
});