-
Notifications
You must be signed in to change notification settings - Fork 11
/
eventTypes.test.js
73 lines (62 loc) · 1.98 KB
/
eventTypes.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
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 createEventTypeConfig = {
name: 'test.event'
}
const eventTypeConfig = {
space: 'testspace',
name: 'test.event'
}
test('should add an event type to the gateway', () => {
return eventGateway.createEventType(createEventTypeConfig).then(response => {
expect(response).toEqual(eventTypeConfig)
})
})
test('should return list of event types', () => {
return eventGateway.listEventTypes().then(response => {
expect(response).toEqual([eventTypeConfig])
})
})
test('should return filtered list of event types', () => {
return eventGateway.listEventTypes({ 'metadata.foo': 'bar' }).then(response => {
expect(response).toEqual([])
})
})
test('should fail to re-add the same event type', () => {
return eventGateway.createEventType(createEventTypeConfig).catch(err => {
expect(err).toEqual(
new Error('Failed to create test.event event type due the error: Event Type "test.event" already exists.')
)
})
})
test('should remove the added event type', () => {
return eventGateway.deleteEventType({ name: 'test.event' }).then(response => {
expect(response).toBeUndefined()
})
})
test('should fail to remove a non-existing event type', () => {
return eventGateway.deleteEventType({ name: 'non.existing' }).catch(err => {
expect(err).toEqual(
new Error('Failed to delete non.existing event type due the error: Event Type "non.existing" not found.')
)
})
})