You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-06 12:02:40 +03:00
Apply prettier formatting
This commit is contained in:
@@ -2,7 +2,7 @@ import * as utils from "../test-utils/test-utils";
|
||||
import { IActionsObject, PushProcessor } from "../../src/pushprocessor";
|
||||
import { EventType, IContent, MatrixClient, MatrixEvent } from "../../src";
|
||||
|
||||
describe('NotificationService', function() {
|
||||
describe("NotificationService", function () {
|
||||
const testUserId = "@ali:matrix.org";
|
||||
const testDisplayName = "Alice M";
|
||||
const testRoomId = "!fl1bb13:localhost";
|
||||
@@ -13,15 +13,15 @@ describe('NotificationService', function() {
|
||||
|
||||
// These would be better if individual rules were configured in the tests themselves.
|
||||
const matrixClient = {
|
||||
getRoom: function() {
|
||||
getRoom: function () {
|
||||
return {
|
||||
currentState: {
|
||||
getMember: function() {
|
||||
getMember: function () {
|
||||
return {
|
||||
name: testDisplayName,
|
||||
};
|
||||
},
|
||||
getJoinedMemberCount: function() {
|
||||
getJoinedMemberCount: function () {
|
||||
return 0;
|
||||
},
|
||||
members: {},
|
||||
@@ -32,136 +32,136 @@ describe('NotificationService', function() {
|
||||
userId: testUserId,
|
||||
},
|
||||
pushRules: {
|
||||
"device": {},
|
||||
"global": {
|
||||
"content": [
|
||||
device: {},
|
||||
global: {
|
||||
content: [
|
||||
{
|
||||
"actions": [
|
||||
actions: [
|
||||
"notify",
|
||||
{
|
||||
"set_tweak": "sound",
|
||||
"value": "default",
|
||||
set_tweak: "sound",
|
||||
value: "default",
|
||||
},
|
||||
{
|
||||
"set_tweak": "highlight",
|
||||
set_tweak: "highlight",
|
||||
},
|
||||
],
|
||||
"enabled": true,
|
||||
"pattern": "ali",
|
||||
"rule_id": ".m.rule.contains_user_name",
|
||||
enabled: true,
|
||||
pattern: "ali",
|
||||
rule_id: ".m.rule.contains_user_name",
|
||||
},
|
||||
{
|
||||
"actions": [
|
||||
actions: [
|
||||
"notify",
|
||||
{
|
||||
"set_tweak": "sound",
|
||||
"value": "default",
|
||||
set_tweak: "sound",
|
||||
value: "default",
|
||||
},
|
||||
{
|
||||
"set_tweak": "highlight",
|
||||
set_tweak: "highlight",
|
||||
},
|
||||
],
|
||||
"enabled": true,
|
||||
"pattern": "coffee",
|
||||
"rule_id": "coffee",
|
||||
enabled: true,
|
||||
pattern: "coffee",
|
||||
rule_id: "coffee",
|
||||
},
|
||||
{
|
||||
"actions": [
|
||||
actions: [
|
||||
"notify",
|
||||
{
|
||||
"set_tweak": "sound",
|
||||
"value": "default",
|
||||
set_tweak: "sound",
|
||||
value: "default",
|
||||
},
|
||||
{
|
||||
"set_tweak": "highlight",
|
||||
set_tweak: "highlight",
|
||||
},
|
||||
],
|
||||
"enabled": true,
|
||||
"pattern": "foo*bar",
|
||||
"rule_id": "foobar",
|
||||
enabled: true,
|
||||
pattern: "foo*bar",
|
||||
rule_id: "foobar",
|
||||
},
|
||||
{
|
||||
"actions": [
|
||||
actions: [
|
||||
"notify",
|
||||
{
|
||||
"set_tweak": "sound",
|
||||
"value": "default",
|
||||
set_tweak: "sound",
|
||||
value: "default",
|
||||
},
|
||||
{
|
||||
"set_tweak": "highlight",
|
||||
set_tweak: "highlight",
|
||||
},
|
||||
],
|
||||
"enabled": true,
|
||||
"pattern": "p[io]ng",
|
||||
"rule_id": "pingpong",
|
||||
enabled: true,
|
||||
pattern: "p[io]ng",
|
||||
rule_id: "pingpong",
|
||||
},
|
||||
{
|
||||
"actions": [
|
||||
actions: [
|
||||
"notify",
|
||||
{
|
||||
"set_tweak": "sound",
|
||||
"value": "default",
|
||||
set_tweak: "sound",
|
||||
value: "default",
|
||||
},
|
||||
{
|
||||
"set_tweak": "highlight",
|
||||
set_tweak: "highlight",
|
||||
},
|
||||
],
|
||||
"enabled": true,
|
||||
"pattern": "I ate [0-9] pies",
|
||||
"rule_id": "pies",
|
||||
enabled: true,
|
||||
pattern: "I ate [0-9] pies",
|
||||
rule_id: "pies",
|
||||
},
|
||||
{
|
||||
"actions": [
|
||||
actions: [
|
||||
"notify",
|
||||
{
|
||||
"set_tweak": "sound",
|
||||
"value": "default",
|
||||
set_tweak: "sound",
|
||||
value: "default",
|
||||
},
|
||||
{
|
||||
"set_tweak": "highlight",
|
||||
set_tweak: "highlight",
|
||||
},
|
||||
],
|
||||
"enabled": true,
|
||||
"pattern": "b[!ai]ke",
|
||||
"rule_id": "bakebike",
|
||||
enabled: true,
|
||||
pattern: "b[!ai]ke",
|
||||
rule_id: "bakebike",
|
||||
},
|
||||
],
|
||||
"override": [
|
||||
override: [
|
||||
{
|
||||
"actions": [
|
||||
actions: [
|
||||
"notify",
|
||||
{
|
||||
"set_tweak": "sound",
|
||||
"value": "default",
|
||||
set_tweak: "sound",
|
||||
value: "default",
|
||||
},
|
||||
{
|
||||
"set_tweak": "highlight",
|
||||
set_tweak: "highlight",
|
||||
},
|
||||
],
|
||||
"conditions": [
|
||||
conditions: [
|
||||
{
|
||||
"kind": "contains_display_name",
|
||||
kind: "contains_display_name",
|
||||
},
|
||||
],
|
||||
"enabled": true,
|
||||
"rule_id": ".m.rule.contains_display_name",
|
||||
enabled: true,
|
||||
rule_id: ".m.rule.contains_display_name",
|
||||
},
|
||||
{
|
||||
"actions": [
|
||||
actions: [
|
||||
"notify",
|
||||
{
|
||||
"set_tweak": "sound",
|
||||
"value": "default",
|
||||
set_tweak: "sound",
|
||||
value: "default",
|
||||
},
|
||||
],
|
||||
"conditions": [
|
||||
conditions: [
|
||||
{
|
||||
"is": "2",
|
||||
"kind": "room_member_count",
|
||||
is: "2",
|
||||
kind: "room_member_count",
|
||||
},
|
||||
],
|
||||
"enabled": true,
|
||||
"rule_id": ".m.rule.room_one_to_one",
|
||||
enabled: true,
|
||||
rule_id: ".m.rule.room_one_to_one",
|
||||
},
|
||||
{
|
||||
rule_id: ".org.matrix.msc3914.rule.room.call",
|
||||
@@ -180,41 +180,39 @@ describe('NotificationService', function() {
|
||||
actions: ["notify", { set_tweak: "sound", value: "default" }],
|
||||
},
|
||||
],
|
||||
"room": [],
|
||||
"sender": [],
|
||||
"underride": [
|
||||
room: [],
|
||||
sender: [],
|
||||
underride: [
|
||||
{
|
||||
"actions": [
|
||||
"dont-notify",
|
||||
],
|
||||
"conditions": [
|
||||
actions: ["dont-notify"],
|
||||
conditions: [
|
||||
{
|
||||
"key": "content.msgtype",
|
||||
"kind": "event_match",
|
||||
"pattern": "m.notice",
|
||||
key: "content.msgtype",
|
||||
kind: "event_match",
|
||||
pattern: "m.notice",
|
||||
},
|
||||
],
|
||||
"enabled": true,
|
||||
"rule_id": ".m.rule.suppress_notices",
|
||||
enabled: true,
|
||||
rule_id: ".m.rule.suppress_notices",
|
||||
},
|
||||
{
|
||||
"actions": [
|
||||
actions: [
|
||||
"notify",
|
||||
{
|
||||
"set_tweak": "highlight",
|
||||
"value": false,
|
||||
set_tweak: "highlight",
|
||||
value: false,
|
||||
},
|
||||
],
|
||||
"conditions": [],
|
||||
"enabled": true,
|
||||
"rule_id": ".m.rule.fallback",
|
||||
conditions: [],
|
||||
enabled: true,
|
||||
rule_id: ".m.rule.fallback",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
} as unknown as MatrixClient;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
testEvent = utils.mkEvent({
|
||||
type: "m.room.message",
|
||||
room: testRoomId,
|
||||
@@ -231,25 +229,25 @@ describe('NotificationService', function() {
|
||||
|
||||
// User IDs
|
||||
|
||||
it('should bing on a user ID.', function() {
|
||||
it("should bing on a user ID.", function () {
|
||||
testEvent.event.content!.body = "Hello @ali:matrix.org, how are you?";
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on a partial user ID with an @.', function() {
|
||||
it("should bing on a partial user ID with an @.", function () {
|
||||
testEvent.event.content!.body = "Hello @ali, how are you?";
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on a partial user ID without @.', function() {
|
||||
it("should bing on a partial user ID without @.", function () {
|
||||
testEvent.event.content!.body = "Hello ali, how are you?";
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on a case-insensitive user ID.', function() {
|
||||
it("should bing on a case-insensitive user ID.", function () {
|
||||
testEvent.event.content!.body = "Hello @AlI:matrix.org, how are you?";
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
@@ -257,13 +255,13 @@ describe('NotificationService', function() {
|
||||
|
||||
// Display names
|
||||
|
||||
it('should bing on a display name.', function() {
|
||||
it("should bing on a display name.", function () {
|
||||
testEvent.event.content!.body = "Hello Alice M, how are you?";
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on a case-insensitive display name.', function() {
|
||||
it("should bing on a case-insensitive display name.", function () {
|
||||
testEvent.event.content!.body = "Hello ALICE M, how are you?";
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
@@ -271,25 +269,25 @@ describe('NotificationService', function() {
|
||||
|
||||
// Bing words
|
||||
|
||||
it('should bing on a bing word.', function() {
|
||||
it("should bing on a bing word.", function () {
|
||||
testEvent.event.content!.body = "I really like coffee";
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on case-insensitive bing words.', function() {
|
||||
it("should bing on case-insensitive bing words.", function () {
|
||||
testEvent.event.content!.body = "Coffee is great";
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on wildcard (.*) bing words.', function() {
|
||||
it("should bing on wildcard (.*) bing words.", function () {
|
||||
testEvent.event.content!.body = "It was foomahbar I think.";
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on character group ([abc]) bing words.', function() {
|
||||
it("should bing on character group ([abc]) bing words.", function () {
|
||||
testEvent.event.content!.body = "Ping!";
|
||||
let actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
@@ -298,13 +296,13 @@ describe('NotificationService', function() {
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on character range ([a-z]) bing words.', function() {
|
||||
it("should bing on character range ([a-z]) bing words.", function () {
|
||||
testEvent.event.content!.body = "I ate 6 pies";
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on character negation ([!a]) bing words.', function() {
|
||||
it("should bing on character negation ([!a]) bing words.", function () {
|
||||
testEvent.event.content!.body = "boke";
|
||||
let actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
@@ -313,7 +311,7 @@ describe('NotificationService', function() {
|
||||
expect(actions.tweaks.highlight).toEqual(false);
|
||||
});
|
||||
|
||||
it('should not bing on room server ACL changes', function() {
|
||||
it("should not bing on room server ACL changes", function () {
|
||||
testEvent = utils.mkEvent({
|
||||
type: EventType.RoomServerAcl,
|
||||
room: testRoomId,
|
||||
@@ -331,31 +329,41 @@ describe('NotificationService', function() {
|
||||
|
||||
// invalid
|
||||
|
||||
it('should gracefully handle bad input.', function() {
|
||||
testEvent.event.content!.body = { "foo": "bar" };
|
||||
it("should gracefully handle bad input.", function () {
|
||||
testEvent.event.content!.body = { foo: "bar" };
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(false);
|
||||
});
|
||||
|
||||
it("a rule with no conditions matches every event.", function() {
|
||||
expect(pushProcessor.ruleMatchesEvent({
|
||||
rule_id: "rule1",
|
||||
actions: [],
|
||||
conditions: [],
|
||||
default: false,
|
||||
enabled: true,
|
||||
}, testEvent)).toBe(true);
|
||||
expect(pushProcessor.ruleMatchesEvent({
|
||||
rule_id: "rule1",
|
||||
actions: [],
|
||||
default: false,
|
||||
enabled: true,
|
||||
}, testEvent)).toBe(true);
|
||||
it("a rule with no conditions matches every event.", function () {
|
||||
expect(
|
||||
pushProcessor.ruleMatchesEvent(
|
||||
{
|
||||
rule_id: "rule1",
|
||||
actions: [],
|
||||
conditions: [],
|
||||
default: false,
|
||||
enabled: true,
|
||||
},
|
||||
testEvent,
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
pushProcessor.ruleMatchesEvent(
|
||||
{
|
||||
rule_id: "rule1",
|
||||
actions: [],
|
||||
default: false,
|
||||
enabled: true,
|
||||
},
|
||||
testEvent,
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
describe("group call started push rule", () => {
|
||||
beforeEach(() => {
|
||||
matrixClient.pushRules!.global!.underride!.find(r => r.rule_id === ".m.rule.fallback")!.enabled = false;
|
||||
matrixClient.pushRules!.global!.underride!.find((r) => r.rule_id === ".m.rule.fallback")!.enabled = false;
|
||||
});
|
||||
|
||||
const getActionsForEvent = (prevContent: IContent, content: IContent): IActionsObject => {
|
||||
@@ -384,73 +392,104 @@ describe('NotificationService', function() {
|
||||
expect(actions?.tweaks?.highlight).toBeFalsy();
|
||||
};
|
||||
|
||||
it.each(
|
||||
["m.ring", "m.prompt"],
|
||||
)("should notify when new group call event appears with %s intent", (intent: string) => {
|
||||
assertDoesNotify(getActionsForEvent({}, {
|
||||
"m.intent": intent,
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
}));
|
||||
});
|
||||
it.each(["m.ring", "m.prompt"])(
|
||||
"should notify when new group call event appears with %s intent",
|
||||
(intent: string) => {
|
||||
assertDoesNotify(
|
||||
getActionsForEvent(
|
||||
{},
|
||||
{
|
||||
"m.intent": intent,
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("should notify when a call is un-terminated", () => {
|
||||
assertDoesNotify(getActionsForEvent({
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
"m.terminated": "All users left",
|
||||
}, {
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
}));
|
||||
assertDoesNotify(
|
||||
getActionsForEvent(
|
||||
{
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
"m.terminated": "All users left",
|
||||
},
|
||||
{
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it("should not notify when call is terminated", () => {
|
||||
assertDoesNotNotify(getActionsForEvent({
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
}, {
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
"m.terminated": "All users left",
|
||||
}));
|
||||
assertDoesNotNotify(
|
||||
getActionsForEvent(
|
||||
{
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
},
|
||||
{
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
"m.terminated": "All users left",
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it("should ignore with m.room intent", () => {
|
||||
assertDoesNotNotify(getActionsForEvent({}, {
|
||||
"m.intent": "m.room",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
}));
|
||||
assertDoesNotNotify(
|
||||
getActionsForEvent(
|
||||
{},
|
||||
{
|
||||
"m.intent": "m.room",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
describe("ignoring non-relevant state changes", () => {
|
||||
it("should ignore intent changes", () => {
|
||||
assertDoesNotNotify(getActionsForEvent({
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
}, {
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.video",
|
||||
"m.name": "Call",
|
||||
}));
|
||||
assertDoesNotNotify(
|
||||
getActionsForEvent(
|
||||
{
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
},
|
||||
{
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.video",
|
||||
"m.name": "Call",
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it("should ignore name changes", () => {
|
||||
assertDoesNotNotify(getActionsForEvent({
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
}, {
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "New call",
|
||||
}));
|
||||
assertDoesNotNotify(
|
||||
getActionsForEvent(
|
||||
{
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "Call",
|
||||
},
|
||||
{
|
||||
"m.intent": "m.ring",
|
||||
"m.type": "m.voice",
|
||||
"m.name": "New call",
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user