1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-06-08 15:21:53 +03:00
Travis Ralston bc78784688
Extract v1 extensible events polls types out of the events-sdk (#3062)
* Extract v1 extensible events polls out of events-sdk

* Appease tsdoc?

* Appease naming standards

* Bring the tests over too
2023-01-13 10:02:27 -07:00

88 lines
3.5 KiB
TypeScript

/*
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { NamespacedValue } from "matrix-events-sdk";
import { isEventTypeSame } from "../../../src/@types/extensible_events";
describe("isEventTypeSame", () => {
it("should match string and string", () => {
const a = "org.example.message-like";
const b = "org.example.different";
expect(isEventTypeSame(a, b)).toBe(false);
expect(isEventTypeSame(b, a)).toBe(false);
expect(isEventTypeSame(a, a)).toBe(true);
expect(isEventTypeSame(b, b)).toBe(true);
});
it("should match string and namespace", () => {
const a = "org.example.message-like";
const b = new NamespacedValue<string, string>("org.example.stable", "org.example.unstable");
expect(isEventTypeSame(a, b)).toBe(false);
expect(isEventTypeSame(b, a)).toBe(false);
expect(isEventTypeSame(a, a)).toBe(true);
expect(isEventTypeSame(b, b)).toBe(true);
expect(isEventTypeSame(b.name, b)).toBe(true);
expect(isEventTypeSame(b.altName, b)).toBe(true);
expect(isEventTypeSame(b, b.name)).toBe(true);
expect(isEventTypeSame(b, b.altName)).toBe(true);
});
it("should match namespace and namespace", () => {
const a = new NamespacedValue<string, string>("org.example.stable1", "org.example.unstable1");
const b = new NamespacedValue<string, string>("org.example.stable2", "org.example.unstable2");
expect(isEventTypeSame(a, b)).toBe(false);
expect(isEventTypeSame(b, a)).toBe(false);
expect(isEventTypeSame(a, a)).toBe(true);
expect(isEventTypeSame(a.name, a)).toBe(true);
expect(isEventTypeSame(a.altName, a)).toBe(true);
expect(isEventTypeSame(a, a.name)).toBe(true);
expect(isEventTypeSame(a, a.altName)).toBe(true);
expect(isEventTypeSame(b, b)).toBe(true);
expect(isEventTypeSame(b.name, b)).toBe(true);
expect(isEventTypeSame(b.altName, b)).toBe(true);
expect(isEventTypeSame(b, b.name)).toBe(true);
expect(isEventTypeSame(b, b.altName)).toBe(true);
});
it("should match namespaces of different pointers", () => {
const a = new NamespacedValue<string, string>("org.example.stable", "org.example.unstable");
const b = new NamespacedValue<string, string>("org.example.stable", "org.example.unstable");
expect(isEventTypeSame(a, b)).toBe(true);
expect(isEventTypeSame(b, a)).toBe(true);
expect(isEventTypeSame(a, a)).toBe(true);
expect(isEventTypeSame(a.name, a)).toBe(true);
expect(isEventTypeSame(a.altName, a)).toBe(true);
expect(isEventTypeSame(a, a.name)).toBe(true);
expect(isEventTypeSame(a, a.altName)).toBe(true);
expect(isEventTypeSame(b, b)).toBe(true);
expect(isEventTypeSame(b.name, b)).toBe(true);
expect(isEventTypeSame(b.altName, b)).toBe(true);
expect(isEventTypeSame(b, b.name)).toBe(true);
expect(isEventTypeSame(b, b.altName)).toBe(true);
});
});