forked from ucfopen/Obojobo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_caliper_event.test.js
More file actions
96 lines (80 loc) · 2.64 KB
/
Copy pathvalidate_caliper_event.test.js
File metadata and controls
96 lines (80 loc) · 2.64 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import ValidateCaliper from '../../../../server/routes/api/events/validate_caliper_event'
import CaliperConstants from '../../../../server/routes/api/events/caliper_constants'
describe('Validate Caliper Events', () => {
test('validateArguments checks parameters for required arguments', () => {
const required = ['type', 'name']
const params = {
type: 'mockCaliperEvent',
name: 'A Mock Event',
actor: { type: 'mockActor' }
}
expect(() => {
ValidateCaliper.validateArguments({ required }, params, 'mockActor')
}).not.toThrowError()
})
test('validateArguments throws error if required param is missing', () => {
const required = ['type', 'name']
const params = {
type: 'mockCaliperEvent',
actor: { type: 'mockActor' }
}
expect(() => {
ValidateCaliper.validateArguments({ required }, params, 'mockActor')
}).toThrowError('Missing required arguments: name')
})
test('validateArguments throws error if param is not required or optional', () => {
const required = ['type', 'name']
const params = {
type: 'mockCaliperEvent',
name: 'A Mock Event',
mockParam: 'Will throw an Error',
actor: { type: 'mockActor' }
}
expect(() => {
ValidateCaliper.validateArguments({ required }, params, 'mockActor')
}).toThrowError('Invalid arguments: mockParam')
})
test('validateArguments throws error if actor does not have type', () => {
const required = ['type', 'name']
const params = {
type: 'mockCaliperEvent',
name: 'A Mock Event',
actor: {}
}
expect(() => {
ValidateCaliper.validateArguments({ required }, params, 'mockActor')
}).toThrowError(
'Invalid actor type. Must provide actor of type mockActor\nMissing required arguments: actor.type'
)
})
test('validateArguments throws error if user actor does not have id', () => {
const required = ['type', 'name']
const params = {
type: 'mockCaliperEvent',
name: 'A Mock Event',
actor: { type: CaliperConstants.ACTOR_USER }
}
expect(() => {
ValidateCaliper.validateArguments({ required }, params, CaliperConstants.ACTOR_USER)
}).toThrowError('Missing required arguments: actor.id')
})
test('assignOptions builds additional parameters', () => {
const object = {
peppers: ['ghost', 'jalapeno'],
sessionIds: {
sessionId: 'mockSessionId',
launchId: 'mockLaunchId'
}
}
const options = ValidateCaliper.assignOptions(object)
expect(options).toEqual({
sessionId: 'mockSessionId',
launchId: 'mockLaunchId'
})
})
test('assignOptions builds additional parameters with nothing in object', () => {
const object = {}
const options = ValidateCaliper.assignOptions(object)
expect(options).toEqual({})
})
})