-
Notifications
You must be signed in to change notification settings - Fork 8k
/
settings.js
104 lines (97 loc) · 3.69 KB
/
settings.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import expect from 'expect.js';
import { Settings } from '../settings';
describe('settings module', () => {
describe('Settings class', () => {
describe('fromUpstreamJson factory method', () => {
describe('when no upstream JSON is specified', () => {
it('returns the correct Settings instance', () => {
const settings = Settings.fromUpstreamJson();
const actionTypes = settings.actionTypes;
expect(actionTypes.email.enabled).to.be(false);
expect(actionTypes.webhook.enabled).to.be(true);
expect(actionTypes.index.enabled).to.be(true);
expect(actionTypes.logging.enabled).to.be(true);
expect(actionTypes.hipchat.enabled).to.be(false);
expect(actionTypes.slack.enabled).to.be(true);
expect(actionTypes.jira.enabled).to.be(false);
expect(actionTypes.pagerduty.enabled).to.be(false);
});
});
describe('when upstream JSON contains a configured action type', () => {
it('returns the correct Settings instance', () => {
const upstreamJson = {
persistent: {
xpack: {
notification: {
email: {
account: {
foo: {},
bar: {}
},
default_account: 'bar'
}
}
}
},
defaults: {
xpack: {
notification: {
email: {
account: {
scooby: {},
scrappy: {}
},
default_account: 'scooby'
}
}
}
}
};
const settings = Settings.fromUpstreamJson(upstreamJson);
const actionTypes = settings.actionTypes;
expect(actionTypes.email.enabled).to.be(true);
expect(actionTypes.email.accounts.scooby.default).to.be(true);
expect(actionTypes.email.accounts.scrappy).to.be.an('object');
expect(actionTypes.email.accounts.foo).to.be.an('object');
expect(actionTypes.email.accounts.bar).to.be.an('object');
});
});
});
describe('downstreamJson getter method', () => {
it('returns correct JSON for client', () => {
const upstreamJson = {
defaults: {
xpack: {
notification: {
email: {
account: {
scooby: {},
scrappy: {}
},
default_account: 'scooby'
}
}
}
}
};
const settings = Settings.fromUpstreamJson(upstreamJson);
const json = settings.downstreamJson;
expect(json.action_types.email.enabled).to.be(true);
expect(json.action_types.email.accounts.scooby.default).to.be(true);
expect(json.action_types.email.accounts.scrappy).to.be.an('object');
expect(json.action_types.webhook.enabled).to.be(true);
expect(json.action_types.index.enabled).to.be(true);
expect(json.action_types.logging.enabled).to.be(true);
expect(json.action_types.hipchat.enabled).to.be(false);
expect(json.action_types.slack.enabled).to.be(true);
expect(json.action_types.jira.enabled).to.be(false);
expect(json.action_types.pagerduty.enabled).to.be(false);
});
});
});
});