-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment.test.ts
More file actions
77 lines (66 loc) · 2.85 KB
/
Copy pathcomment.test.ts
File metadata and controls
77 lines (66 loc) · 2.85 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { APIGatewayProxyEvent } from 'aws-lambda';
import { handler } from './comment';
import * as piiRedaction from '../shared/utils/pii-redaction';
import * as awsUtils from '../shared/utils/awsUtils';
import * as googleSheetsUtils from '../shared/utils/googleSheetsUtils';
describe('comment Lambda', () => {
jest.spyOn(awsUtils, 'getSsmParam').mockImplementation(jest.fn());
jest.spyOn(piiRedaction, 'redactPii').mockImplementation(jest.fn());
jest.spyOn(googleSheetsUtils, 'createFeedback').mockImplementation(jest.fn());
jest.spyOn(googleSheetsUtils, 'updateFeedback').mockImplementation(jest.fn());
jest.spyOn(googleSheetsUtils, 'getAuthClient').mockImplementation(jest.fn());
beforeEach(() => jest.resetAllMocks());
it("returns a response containing the 'Access-Control-Allow-Origin':'*' header to enable CORS", async () => {
const testEvent = {
body: JSON.stringify({
feedbackId: 1,
comment: 'test comment'
})
} as APIGatewayProxyEvent;
const response = await handler(testEvent);
expect(response.statusCode).toBe(200);
expect(response.headers['Access-Control-Allow-Origin']).toBe('*');
});
describe('expected 500 errors', () => {
beforeAll(() => jest.spyOn(console, 'error').mockImplementation(jest.fn()));
afterAll(() => jest.spyOn(console, 'error').mockRestore());
it('returns a 500 response when the request is missing the comment', async () => {
const testEvent = {
body: JSON.stringify({
feedbackId: 1
})
} as APIGatewayProxyEvent;
const response = await handler(testEvent);
expect(response.statusCode).toBe(500);
expect(JSON.parse(response.body).message).toBe(
'Failed to save comment: Submission is missing comment'
);
});
it('returns a 500 response when the request is missing both the feedbackId and the pageURL', async () => {
const testEvent = {
body: JSON.stringify({
rating: false,
comment: 'test comment'
})
} as APIGatewayProxyEvent;
const response = await handler(testEvent);
expect(response.statusCode).toBe(500);
expect(JSON.parse(response.body).message).toBe(
'Failed to save comment: If submission is missing feedbackId, then it must include pageURL and rating.'
);
});
it('returns a 500 response when the request is missing both the feedbackId and the rating', async () => {
const testEvent = {
body: JSON.stringify({
pageUrl: 'example.com',
comment: 'test comment'
})
} as APIGatewayProxyEvent;
const response = await handler(testEvent);
expect(response.statusCode).toBe(500);
expect(JSON.parse(response.body).message).toBe(
'Failed to save comment: If submission is missing feedbackId, then it must include pageURL and rating.'
);
});
});
});