Skip to content

Commit ad566a5

Browse files
committed
Add and update tests
1 parent 18739aa commit ad566a5

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

test/ClientWidgetApi-test.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
} from "../src";
4949
import { IGetMediaConfigActionFromWidgetActionRequest } from "../src/interfaces/GetMediaConfigAction";
5050
import { IReadRoomAccountDataFromWidgetActionRequest } from "../src/interfaces/ReadRoomAccountDataAction";
51+
import { IToDeviceMessage } from "../src/interfaces/IToDeviceMessage";
5152

5253
jest.mock("../src/transport/PostmessageTransport");
5354

@@ -886,11 +887,11 @@ describe("ClientWidgetApi", () => {
886887
describe("receiving events", () => {
887888
const roomId = "!room:example.org";
888889
const otherRoomId = "!other-room:example.org";
889-
const event = createRoomEvent({ room_id: roomId, type: "m.room.message", content: "hello" });
890+
const event = createRoomEvent({ room_id: roomId, type: "m.room.message", content: { hello: "there" } });
890891
const eventFromOtherRoom = createRoomEvent({
891892
room_id: otherRoomId,
892893
type: "m.room.message",
893-
content: "test",
894+
content: { test: "test" },
894895
});
895896

896897
it("forwards events to the widget from one room only", async () => {
@@ -1095,6 +1096,22 @@ describe("ClientWidgetApi", () => {
10951096
});
10961097
});
10971098

1099+
describe.only("receiving to device messages", () => {
1100+
it.each([true, false])("forwards device messages to the widget", async (encrypted) => {
1101+
const event: IToDeviceMessage = {
1102+
content: { foo: "bar" },
1103+
type: "org.example.mytype",
1104+
sender: "@alice:example.org",
1105+
};
1106+
// Give the widget capabilities to receive from just one room
1107+
await loadIframe(["org.matrix.msc3819.receive.to_device:org.example.mytype"]);
1108+
1109+
// Event from the matching room should be forwarded
1110+
await clientWidgetApi.feedToDevice(event, encrypted);
1111+
expect(transport.send).toHaveBeenCalledWith(WidgetApiToWidgetAction.SendToDevice, { ...event, encrypted });
1112+
});
1113+
});
1114+
10981115
describe("update_delayed_event action", () => {
10991116
it("fails to cancel delayed events", async () => {
11001117
const event: IUpdateDelayedEventFromWidgetActionRequest = {
@@ -1727,7 +1744,7 @@ describe("ClientWidgetApi", () => {
17271744
it("reads events from a specific room", async () => {
17281745
const roomId = "!room:example.org";
17291746
jest.spyOn(clientWidgetApi, "getWidgetVersions").mockResolvedValue([]);
1730-
const event = createRoomEvent({ room_id: roomId, type: "net.example.test", content: "test" });
1747+
const event = createRoomEvent({ room_id: roomId, type: "net.example.test", content: { test: "test" } });
17311748
driver.readRoomTimeline.mockImplementation(async (rId) => {
17321749
if (rId === roomId) return [event];
17331750
return [];
@@ -1772,8 +1789,12 @@ describe("ClientWidgetApi", () => {
17721789
const roomId = "!room:example.org";
17731790
const otherRoomId = "!other-room:example.org";
17741791
jest.spyOn(clientWidgetApi, "getWidgetVersions").mockResolvedValue([]);
1775-
const event = createRoomEvent({ room_id: roomId, type: "net.example.test", content: "test" });
1776-
const otherRoomEvent = createRoomEvent({ room_id: otherRoomId, type: "net.example.test", content: "hi" });
1792+
const event = createRoomEvent({ room_id: roomId, type: "net.example.test", content: { test: "test" } });
1793+
const otherRoomEvent = createRoomEvent({
1794+
room_id: otherRoomId,
1795+
type: "net.example.test",
1796+
content: { hi: "there" },
1797+
});
17771798
driver.getKnownRooms.mockReturnValue([roomId, otherRoomId]);
17781799
driver.readRoomTimeline.mockImplementation(async (rId) => {
17791800
if (rId === roomId) return [event];

0 commit comments

Comments
 (0)