-
Notifications
You must be signed in to change notification settings - Fork 11
/
cors.test.js
83 lines (72 loc) · 2.24 KB
/
cors.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
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
const SDK = require('../lib/index')
const eventGatewayProcess = require('./utils/eventGatewayProcess')
let eventGateway
let eventGatewayProcessId
beforeAll(() =>
eventGatewayProcess
.spawn({
configPort: 4001,
apiPort: 4002
})
.then(processInfo => {
eventGatewayProcessId = processInfo.id
eventGateway = new SDK({
space: 'testspace',
url: `https://localhost:${processInfo.apiPort}`,
configurationUrl: `https://localhost:${processInfo.configPort}`
})
}))
afterAll(() => {
eventGatewayProcess.shutDown(eventGatewayProcessId)
})
const createCORSConfig = {
method: 'GET',
path: '/test',
allowedOrigins: ['https://example.com']
}
const corsConfig = {
space: 'testspace',
corsId: 'GET%2Ftest',
method: 'GET',
path: '/test',
allowedOrigins: ['https://example.com'],
allowedHeaders: ['Origin', 'Accept', 'Content-Type'],
allowedMethods: ['HEAD', 'GET', 'POST'],
allowCredentials: false
}
test('should add an event type to the gateway', () => {
return eventGateway.createCORS(createCORSConfig).then(response => {
expect(response).toEqual(corsConfig)
})
})
test('should return list of CORS configurations', () => {
return eventGateway.listCORS().then(response => {
expect(response).toEqual([corsConfig])
})
})
test('should return filtered list of CORS configurations', () => {
return eventGateway.listCORS({ 'metadata.foo': 'bar' }).then(response => {
expect(response).toEqual([])
})
})
test('should fail to re-add the same CORS configuration', () => {
return eventGateway.createCORS(createCORSConfig).catch(err => {
expect(err).toEqual(
new Error('Failed to create CORS configuration due the error: CORS configuration "GET%2Ftest" already exists.')
)
})
})
test('should remove the added CORS configuration', () => {
return eventGateway.deleteCORS({ corsId: 'GET%2Ftest' }).then(response => {
expect(response).toBeUndefined()
})
})
test('should fail to remove a non-existing function', () => {
return eventGateway.deleteCORS({ corsId: 'GET%2Ftest' }).catch(err => {
expect(err).toEqual(
new Error(
'Failed to delete GET%2Ftest CORS configuration due the error: CORS configuration "GET%2Ftest" not found.'
)
)
})
})