Skip to content
This repository was archived by the owner on May 18, 2025. It is now read-only.

Commit 7ae1b37

Browse files
committedApr 12, 2018
add notif UTs
1 parent 8371774 commit 7ae1b37

File tree

2 files changed

+179
-0
lines changed

2 files changed

+179
-0
lines changed
 
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
Copyright 2016 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
var notifications = require('../../../src/notifications');
18+
19+
var ContentRules = notifications.ContentRules;
20+
var PushRuleVectorState = notifications.PushRuleVectorState;
21+
22+
var expect = require('expect');
23+
var test_utils = require('../../test-utils');
24+
25+
var NORMAL_RULE = {
26+
actions: [
27+
"notify",
28+
{ set_tweak: "highlight", value: false },
29+
],
30+
enabled: true,
31+
pattern: "vdh2",
32+
rule_id: "vdh2",
33+
};
34+
35+
var LOUD_RULE = {
36+
actions: [
37+
"notify",
38+
{ set_tweak: "highlight" },
39+
{ set_tweak: "sound", value: "default" },
40+
],
41+
enabled: true,
42+
pattern: "vdh2",
43+
rule_id: "vdh2",
44+
};
45+
46+
var USERNAME_RULE = {
47+
actions: [
48+
"notify",
49+
{ set_tweak: "sound", value: "default" },
50+
{ set_tweak: "highlight" },
51+
],
52+
default: true,
53+
enabled: true,
54+
pattern: "richvdh",
55+
rule_id: ".m.rule.contains_user_name",
56+
};
57+
58+
59+
60+
describe("ContentRules", function() {
61+
beforeEach(function() {
62+
test_utils.beforeEach(this);
63+
});
64+
65+
describe("parseContentRules", function() {
66+
it("should handle there being no keyword rules", function() {
67+
var rules = { 'global': { 'content': [
68+
USERNAME_RULE,
69+
]}};
70+
var parsed = ContentRules.parseContentRules(rules);
71+
expect(parsed.rules).toEqual([]);
72+
expect(parsed.vectorState).toEqual(PushRuleVectorState.ON);
73+
expect(parsed.externalRules).toEqual([]);
74+
});
75+
76+
it("should parse regular keyword notifications", function() {
77+
var rules = { 'global': { 'content': [
78+
NORMAL_RULE,
79+
USERNAME_RULE,
80+
]}};
81+
82+
var parsed = ContentRules.parseContentRules(rules);
83+
expect(parsed.rules.length).toEqual(1);
84+
expect(parsed.rules[0]).toEqual(NORMAL_RULE);
85+
expect(parsed.vectorState).toEqual(PushRuleVectorState.ON);
86+
expect(parsed.externalRules).toEqual([]);
87+
});
88+
89+
it("should parse loud keyword notifications", function() {
90+
var rules = { 'global': { 'content': [
91+
LOUD_RULE,
92+
USERNAME_RULE,
93+
]}};
94+
95+
var parsed = ContentRules.parseContentRules(rules);
96+
expect(parsed.rules.length).toEqual(1);
97+
expect(parsed.rules[0]).toEqual(LOUD_RULE);
98+
expect(parsed.vectorState).toEqual(PushRuleVectorState.LOUD);
99+
expect(parsed.externalRules).toEqual([]);
100+
});
101+
102+
it("should parse mixed keyword notifications", function() {
103+
var rules = { 'global': { 'content': [
104+
LOUD_RULE,
105+
NORMAL_RULE,
106+
USERNAME_RULE,
107+
]}};
108+
109+
var parsed = ContentRules.parseContentRules(rules);
110+
expect(parsed.rules.length).toEqual(1);
111+
expect(parsed.rules[0]).toEqual(LOUD_RULE);
112+
expect(parsed.vectorState).toEqual(PushRuleVectorState.LOUD);
113+
expect(parsed.externalRules.length).toEqual(1);
114+
expect(parsed.externalRules[0]).toEqual(NORMAL_RULE);
115+
});
116+
});
117+
});
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Copyright 2016 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
var notifications = require('../../../src/notifications');
18+
19+
var prvs = notifications.PushRuleVectorState;
20+
21+
var expect = require('expect');
22+
23+
describe("PushRuleVectorState", function() {
24+
describe("contentRuleVectorStateKind", function() {
25+
it("should understand normal notifications", function () {
26+
var rule = {
27+
actions: [
28+
"notify",
29+
],
30+
};
31+
32+
expect(prvs.contentRuleVectorStateKind(rule)).
33+
toEqual(prvs.ON);
34+
});
35+
36+
it("should handle loud notifications", function () {
37+
var rule = {
38+
actions: [
39+
"notify",
40+
{ set_tweak: "highlight", value: true },
41+
{ set_tweak: "sound", value: "default" },
42+
]
43+
};
44+
45+
expect(prvs.contentRuleVectorStateKind(rule)).
46+
toEqual(prvs.LOUD);
47+
});
48+
49+
it("should understand missing highlight.value", function () {
50+
var rule = {
51+
actions: [
52+
"notify",
53+
{ set_tweak: "highlight" },
54+
{ set_tweak: "sound", value: "default" },
55+
]
56+
};
57+
58+
expect(prvs.contentRuleVectorStateKind(rule)).
59+
toEqual(prvs.LOUD);
60+
});
61+
});
62+
});

0 commit comments

Comments
 (0)
This repository has been archived.