Skip to content

Commit 1ce332f

Browse files
committed
Increase test coverage
1 parent d9563dc commit 1ce332f

File tree

2 files changed

+50
-37
lines changed

2 files changed

+50
-37
lines changed

spec/unit/matrix-client.spec.ts

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ type HttpLookup = {
9797
method: string;
9898
path: string;
9999
prefix?: string;
100-
data?: Record<string, any>;
100+
data?: Record<string, any> | Record<string, any>[];
101101
error?: object;
102102
expectBody?: Record<string, any>;
103103
expectQueryParams?: QueryDict;
@@ -349,7 +349,6 @@ describe("MatrixClient", function () {
349349
// set unstableFeatures to a defined state before each test
350350
unstableFeatures = {
351351
"org.matrix.msc3440.stable": true,
352-
"org.matrix.msc4140": true,
353352
};
354353

355354
makeClient();
@@ -724,50 +723,36 @@ describe("MatrixClient", function () {
724723
cancel_token: "ca",
725724
};
726725

727-
it("overload without threadId works", async () => {
728-
httpLookups = [];
726+
beforeEach(() => {
727+
unstableFeatures["org.matrix.msc4140"] = true;
728+
});
729729

730-
const timeoutFutureTxnId = client.makeTxnId();
731-
httpLookups.push({
732-
method: "PUT",
733-
prefix: unstableMSC4140Prefix,
734-
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${timeoutFutureTxnId}`,
735-
expectQueryParams: timeoutFutureOpts,
736-
data: timeoutFutureResponse,
737-
expectBody: content,
738-
});
730+
it("throws when unsupported by server", async () => {
731+
unstableFeatures["org.matrix.msc4140"] = false;
732+
const errorMessage = "Server does not support the Futures API";
739733

740-
const { future_group_id: futureGroupId } = await client._unstable_sendFuture(
734+
await expect(client._unstable_sendFuture(
741735
roomId,
742736
timeoutFutureOpts,
743737
null,
744738
EventType.RoomMessage,
745739
{ ...content },
746-
timeoutFutureTxnId,
747-
);
748-
749-
const actionFutureTxnId = client.makeTxnId();
750-
const actionFutureOpts = { future_group_id: futureGroupId };
751-
httpLookups.push({
752-
method: "PUT",
753-
prefix: unstableMSC4140Prefix,
754-
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${actionFutureTxnId}`,
755-
expectQueryParams: actionFutureOpts,
756-
data: actionFutureResponse,
757-
expectBody: content,
758-
});
740+
client.makeTxnId(),
741+
)).rejects.toThrow(errorMessage);
759742

760-
await client._unstable_sendFuture(
743+
await expect(client._unstable_sendStateFuture(
761744
roomId,
762-
actionFutureOpts,
763-
null,
764-
EventType.RoomMessage,
765-
{ ...content },
766-
actionFutureTxnId,
767-
);
745+
timeoutFutureOpts,
746+
EventType.RoomTopic,
747+
{ topic: "topic" },
748+
)).rejects.toThrow(errorMessage);
749+
750+
await expect(client._unstable_getFutures()).rejects.toThrow(errorMessage);
751+
752+
await expect(client._unstable_updateFutureWithToken("token")).rejects.toThrow(errorMessage);
768753
});
769754

770-
it("overload with null threadId works", async () => {
755+
it("works with null threadId", async () => {
771756
httpLookups = [];
772757

773758
const timeoutFutureTxnId = client.makeTxnId();
@@ -810,7 +795,7 @@ describe("MatrixClient", function () {
810795
);
811796
});
812797

813-
it("overload with threadId works", async () => {
798+
it("works with non-null threadId", async () => {
814799
httpLookups = [];
815800
const threadId = "$threadId:server";
816801
const expectBody = {
@@ -1026,6 +1011,33 @@ describe("MatrixClient", function () {
10261011

10271012
await client._unstable_sendStateFuture(roomId, actionFutureOpts, EventType.RoomTopic, { ...content });
10281013
});
1014+
1015+
it("can look up futures", async () => {
1016+
httpLookups = [
1017+
{
1018+
method: "GET",
1019+
prefix: unstableMSC4140Prefix,
1020+
path: "/future",
1021+
data: [],
1022+
}
1023+
];
1024+
1025+
await client._unstable_getFutures();
1026+
});
1027+
1028+
it("can update futures with their tokens", async () => {
1029+
const futureToken = "token";
1030+
httpLookups = [
1031+
{
1032+
method: "POST",
1033+
prefix: unstableMSC4140Prefix,
1034+
path: `/future/${futureToken}`,
1035+
data: {},
1036+
}
1037+
];
1038+
1039+
await client._unstable_updateFutureWithToken(futureToken);
1040+
});
10291041
});
10301042

10311043
it("should create (unstable) file trees", async () => {
@@ -1287,7 +1299,7 @@ describe("MatrixClient", function () {
12871299
const filter = new Filter(client.credentials.userId);
12881300

12891301
const filterId = await client.getOrCreateFilter(filterName, filter);
1290-
expect(filterId).toEqual(FILTER_RESPONSE.data?.filter_id);
1302+
expect(filterId).toEqual(!Array.isArray(FILTER_RESPONSE.data) && FILTER_RESPONSE.data?.filter_id);
12911303
});
12921304
});
12931305

spec/unit/matrixrtc/MatrixRTCSession.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe("MatrixRTCSession", () => {
4646
client = new MatrixClient({ baseUrl: "base_url" });
4747
client.getUserId = jest.fn().mockReturnValue("@alice:example.org");
4848
client.getDeviceId = jest.fn().mockReturnValue("AAAAAAA");
49+
client.doesServerSupportUnstableFeature = jest.fn().mockReturnValue({ "org.matrix.msc4140": true });
4950
});
5051

5152
afterEach(() => {

0 commit comments

Comments
 (0)