|
1 | 1 | import * as utils from "../test-utils/test-utils"; |
2 | | -import { PushProcessor } from "../../src/pushprocessor"; |
3 | | -import { EventType, MatrixClient, MatrixEvent } from "../../src"; |
| 2 | +import { IActionsObject, PushProcessor } from "../../src/pushprocessor"; |
| 3 | +import { EventType, IContent, MatrixClient, MatrixEvent } from "../../src"; |
4 | 4 |
|
5 | 5 | describe('NotificationService', function() { |
6 | 6 | const testUserId = "@ali:matrix.org"; |
@@ -336,4 +336,102 @@ describe('NotificationService', function() { |
336 | 336 | enabled: true, |
337 | 337 | }, testEvent)).toBe(true); |
338 | 338 | }); |
| 339 | + |
| 340 | + describe("performCustomEventHandling()", () => { |
| 341 | + const getActionsForEvent = (prevContent: IContent, content: IContent): IActionsObject => { |
| 342 | + testEvent = utils.mkEvent({ |
| 343 | + type: "org.matrix.msc3401.call", |
| 344 | + room: testRoomId, |
| 345 | + user: "@alice:foo", |
| 346 | + skey: "state_key", |
| 347 | + event: true, |
| 348 | + content: content, |
| 349 | + prev_content: prevContent, |
| 350 | + }); |
| 351 | + |
| 352 | + return pushProcessor.actionsForEvent(testEvent); |
| 353 | + }; |
| 354 | + |
| 355 | + const assertDoesNotify = (actions: IActionsObject): void => { |
| 356 | + expect(actions.notify).toBeTruthy(); |
| 357 | + expect(actions.tweaks.sound).toBeTruthy(); |
| 358 | + expect(actions.tweaks.highlight).toBeFalsy(); |
| 359 | + }; |
| 360 | + |
| 361 | + const assertDoesNotNotify = (actions: IActionsObject): void => { |
| 362 | + expect(actions.notify).toBeFalsy(); |
| 363 | + expect(actions.tweaks.sound).toBeFalsy(); |
| 364 | + expect(actions.tweaks.highlight).toBeFalsy(); |
| 365 | + }; |
| 366 | + |
| 367 | + it.each( |
| 368 | + ["m.ring", "m.prompt"], |
| 369 | + )("should notify when new group call event appears with %s intent", (intent: string) => { |
| 370 | + assertDoesNotify(getActionsForEvent({}, { |
| 371 | + "m.intent": intent, |
| 372 | + "m.type": "m.voice", |
| 373 | + "m.name": "Call", |
| 374 | + })); |
| 375 | + }); |
| 376 | + |
| 377 | + it("should notify when a call is un-terminated", () => { |
| 378 | + assertDoesNotify(getActionsForEvent({ |
| 379 | + "m.intent": "m.ring", |
| 380 | + "m.type": "m.voice", |
| 381 | + "m.name": "Call", |
| 382 | + "m.terminated": "All users left", |
| 383 | + }, { |
| 384 | + "m.intent": "m.ring", |
| 385 | + "m.type": "m.voice", |
| 386 | + "m.name": "Call", |
| 387 | + })); |
| 388 | + }); |
| 389 | + |
| 390 | + it("should not notify when call is terminated", () => { |
| 391 | + assertDoesNotNotify(getActionsForEvent({ |
| 392 | + "m.intent": "m.ring", |
| 393 | + "m.type": "m.voice", |
| 394 | + "m.name": "Call", |
| 395 | + }, { |
| 396 | + "m.intent": "m.ring", |
| 397 | + "m.type": "m.voice", |
| 398 | + "m.name": "Call", |
| 399 | + "m.terminated": "All users left", |
| 400 | + })); |
| 401 | + }); |
| 402 | + |
| 403 | + it("should ignore with m.room intent", () => { |
| 404 | + assertDoesNotNotify(getActionsForEvent({}, { |
| 405 | + "m.intent": "m.room", |
| 406 | + "m.type": "m.voice", |
| 407 | + "m.name": "Call", |
| 408 | + })); |
| 409 | + }); |
| 410 | + |
| 411 | + describe("ignoring non-relevant state changes", () => { |
| 412 | + it("should ignore intent changes", () => { |
| 413 | + assertDoesNotNotify(getActionsForEvent({ |
| 414 | + "m.intent": "m.ring", |
| 415 | + "m.type": "m.voice", |
| 416 | + "m.name": "Call", |
| 417 | + }, { |
| 418 | + "m.intent": "m.ring", |
| 419 | + "m.type": "m.video", |
| 420 | + "m.name": "Call", |
| 421 | + })); |
| 422 | + }); |
| 423 | + |
| 424 | + it("should ignore name changes", () => { |
| 425 | + assertDoesNotNotify(getActionsForEvent({ |
| 426 | + "m.intent": "m.ring", |
| 427 | + "m.type": "m.voice", |
| 428 | + "m.name": "Call", |
| 429 | + }, { |
| 430 | + "m.intent": "m.ring", |
| 431 | + "m.type": "m.voice", |
| 432 | + "m.name": "New call", |
| 433 | + })); |
| 434 | + }); |
| 435 | + }); |
| 436 | + }); |
339 | 437 | }); |
0 commit comments