1 | "use strict";
|
2 | import 'source-map-support/register';
|
3 | const sdk = require("../..");
|
4 | const Filter = sdk.Filter;
|
5 | const utils = require("../test-utils");
|
6 |
|
7 | import expect from 'expect';
|
8 |
|
9 | describe("Filter", function() {
|
10 | const filterId = "f1lt3ring15g00d4ursoul";
|
11 | const userId = "@sir_arthur_david:humming.tiger";
|
12 | let filter;
|
13 |
|
14 | beforeEach(function() {
|
15 | utils.beforeEach(this);
|
16 | filter = new Filter(userId);
|
17 | });
|
18 |
|
19 | describe("fromJson", function() {
|
20 | it("create a new Filter from the provided values", function() {
|
21 | const definition = {
|
22 | event_fields: ["type", "content"],
|
23 | };
|
24 | const f = Filter.fromJson(userId, filterId, definition);
|
25 | expect(f.getDefinition()).toEqual(definition);
|
26 | expect(f.userId).toEqual(userId);
|
27 | expect(f.filterId).toEqual(filterId);
|
28 | });
|
29 | });
|
30 |
|
31 | describe("setTimelineLimit", function() {
|
32 | it("should set room.timeline.limit of the filter definition", function() {
|
33 | filter.setTimelineLimit(10);
|
34 | expect(filter.getDefinition()).toEqual({
|
35 | room: {
|
36 | timeline: {
|
37 | limit: 10,
|
38 | },
|
39 | },
|
40 | });
|
41 | });
|
42 | });
|
43 |
|
44 | describe("setDefinition/getDefinition", function() {
|
45 | it("should set and get the filter body", function() {
|
46 | const definition = {
|
47 | event_format: "client",
|
48 | };
|
49 | filter.setDefinition(definition);
|
50 | expect(filter.getDefinition()).toEqual(definition);
|
51 | });
|
52 | });
|
53 | });
|