You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
39
spec/unit/filter-component.spec.js
Normal file
39
spec/unit/filter-component.spec.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import {FilterComponent} from "../../src/filter-component"
|
||||||
|
import {mkEvent} from '../test-utils'
|
||||||
|
|
||||||
|
describe("Filter Component", function() {
|
||||||
|
|
||||||
|
describe("types", function() {
|
||||||
|
it("should filter out events with other types", function() {
|
||||||
|
const filter = new FilterComponent({ types: [ 'm.room.message' ] })
|
||||||
|
|
||||||
|
const event = mkEvent({
|
||||||
|
type: 'm.room.member',
|
||||||
|
content: { },
|
||||||
|
room: 'roomId',
|
||||||
|
event: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
const checkResult = filter.check(event)
|
||||||
|
|
||||||
|
expect(checkResult).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should validate events with the same type", function() {
|
||||||
|
const filter = new FilterComponent({ types: [ 'm.room.message' ] })
|
||||||
|
|
||||||
|
const event = mkEvent({
|
||||||
|
type: 'm.room.message',
|
||||||
|
content: { },
|
||||||
|
room: 'roomId',
|
||||||
|
event: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
const checkResult = filter.check(event)
|
||||||
|
|
||||||
|
expect(checkResult).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
@@ -108,8 +108,9 @@ FilterComponent.prototype._checkFields =
|
|||||||
}
|
}
|
||||||
|
|
||||||
const allowed_values = self[name];
|
const allowed_values = self[name];
|
||||||
if (allowed_values) {
|
if (allowed_values && allowed_values.length > 0) {
|
||||||
if (!allowed_values.map(match_func)) {
|
const anyMatch = allowed_values.map(match_func).reduce((a, b) => a || b);
|
||||||
|
if (!anyMatch) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user