forked from dherault/serverless-offline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpApi-cors-default.test.js
45 lines (38 loc) · 1.26 KB
/
httpApi-cors-default.test.js
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
// tests based on:
// https://dev.to/piczmar_0/serverless-authorizers---custom-rest-authorizer-16
import { resolve } from 'path'
import fetch from 'node-fetch'
import { joinUrl, setup, teardown } from '../_testHelpers/index.js'
jest.setTimeout(30000)
describe('HttpApi Cors Default Tests', () => {
// init
beforeAll(() =>
setup({
servicePath: resolve(__dirname),
}),
)
// cleanup
afterAll(() => teardown())
test('Fetch OPTIONS with any origin', async () => {
const url = joinUrl(TEST_BASE_URL, '/dev/user')
const options = {
method: 'OPTIONS',
headers: {
origin: 'http://www.mytestapp.com',
'access-control-request-headers': 'authorization,content-type',
'access-control-request-method': 'GET',
},
}
const response = await fetch(url, options)
expect(response.status).toEqual(204)
expect(response.headers.get('access-control-allow-origin')).toEqual(
'http://www.mytestapp.com',
)
expect(response.headers.get('access-control-allow-methods')).toEqual(
'OPTIONS,GET,POST,PUT,DELETE,PATCH',
)
expect(response.headers.get('access-control-allow-headers')).toEqual(
'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent',
)
})
})