|
| 1 | +/* |
| 2 | +Copyright 2022 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
1 | 17 | import * as utils from "../test-utils/test-utils"; |
2 | 18 | import { CRYPTO_ENABLED } from "../../src/client"; |
3 | 19 | import { MatrixEvent } from "../../src/models/event"; |
@@ -823,6 +839,171 @@ describe("MatrixClient", function() { |
823 | 839 | ]); |
824 | 840 | }); |
825 | 841 | }); |
| 842 | + |
| 843 | + describe("getThirdpartyUser", () => { |
| 844 | + it("should hit the expected API endpoint", async () => { |
| 845 | + const response = [{ |
| 846 | + userid: "@Bob", |
| 847 | + protocol: "irc", |
| 848 | + fields: {}, |
| 849 | + }]; |
| 850 | + |
| 851 | + const prom = client.getThirdpartyUser("irc", {}); |
| 852 | + httpBackend.when("GET", "/thirdparty/user/irc").respond(200, response); |
| 853 | + await httpBackend.flush(); |
| 854 | + expect(await prom).toStrictEqual(response); |
| 855 | + }); |
| 856 | + }); |
| 857 | + |
| 858 | + describe("getThirdpartyLocation", () => { |
| 859 | + it("should hit the expected API endpoint", async () => { |
| 860 | + const response = [{ |
| 861 | + alias: "#alias", |
| 862 | + protocol: "irc", |
| 863 | + fields: {}, |
| 864 | + }]; |
| 865 | + |
| 866 | + const prom = client.getThirdpartyLocation("irc", {}); |
| 867 | + httpBackend.when("GET", "/thirdparty/location/irc").respond(200, response); |
| 868 | + await httpBackend.flush(); |
| 869 | + expect(await prom).toStrictEqual(response); |
| 870 | + }); |
| 871 | + }); |
| 872 | + |
| 873 | + describe("getPushers", () => { |
| 874 | + it("should hit the expected API endpoint", async () => { |
| 875 | + const response = { |
| 876 | + pushers: [], |
| 877 | + }; |
| 878 | + |
| 879 | + const prom = client.getPushers(); |
| 880 | + httpBackend.when("GET", "/pushers").respond(200, response); |
| 881 | + await httpBackend.flush(); |
| 882 | + expect(await prom).toStrictEqual(response); |
| 883 | + }); |
| 884 | + }); |
| 885 | + |
| 886 | + describe("getKeyChanges", () => { |
| 887 | + it("should hit the expected API endpoint", async () => { |
| 888 | + const response = { |
| 889 | + changed: [], |
| 890 | + left: [], |
| 891 | + }; |
| 892 | + |
| 893 | + const prom = client.getKeyChanges("old", "new"); |
| 894 | + httpBackend.when("GET", "/keys/changes").check((req) => { |
| 895 | + expect(req.queryParams.from).toEqual("old"); |
| 896 | + expect(req.queryParams.to).toEqual("new"); |
| 897 | + }).respond(200, response); |
| 898 | + await httpBackend.flush(); |
| 899 | + expect(await prom).toStrictEqual(response); |
| 900 | + }); |
| 901 | + }); |
| 902 | + |
| 903 | + describe("getDevices", () => { |
| 904 | + it("should hit the expected API endpoint", async () => { |
| 905 | + const response = { |
| 906 | + devices: [], |
| 907 | + }; |
| 908 | + |
| 909 | + const prom = client.getDevices(); |
| 910 | + httpBackend.when("GET", "/devices").respond(200, response); |
| 911 | + await httpBackend.flush(); |
| 912 | + expect(await prom).toStrictEqual(response); |
| 913 | + }); |
| 914 | + }); |
| 915 | + |
| 916 | + describe("getDevice", () => { |
| 917 | + it("should hit the expected API endpoint", async () => { |
| 918 | + const response = { |
| 919 | + device_id: "DEADBEEF", |
| 920 | + display_name: "NotAPhone", |
| 921 | + last_seen_ip: "127.0.0.1", |
| 922 | + last_seen_ts: 1, |
| 923 | + }; |
| 924 | + |
| 925 | + const prom = client.getDevice("DEADBEEF"); |
| 926 | + httpBackend.when("GET", "/devices/DEADBEEF").respond(200, response); |
| 927 | + await httpBackend.flush(); |
| 928 | + expect(await prom).toStrictEqual(response); |
| 929 | + }); |
| 930 | + }); |
| 931 | + |
| 932 | + describe("getThreePids", () => { |
| 933 | + it("should hit the expected API endpoint", async () => { |
| 934 | + const response = { |
| 935 | + threepids: [], |
| 936 | + }; |
| 937 | + |
| 938 | + const prom = client.getThreePids(); |
| 939 | + httpBackend.when("GET", "/account/3pid").respond(200, response); |
| 940 | + await httpBackend.flush(); |
| 941 | + expect(await prom).toStrictEqual(response); |
| 942 | + }); |
| 943 | + }); |
| 944 | + |
| 945 | + describe("deleteAlias", () => { |
| 946 | + it("should hit the expected API endpoint", async () => { |
| 947 | + const response = {}; |
| 948 | + const prom = client.deleteAlias("#foo:bar"); |
| 949 | + httpBackend.when("DELETE", "/directory/room/" + encodeURIComponent("#foo:bar")).respond(200, response); |
| 950 | + await httpBackend.flush(); |
| 951 | + expect(await prom).toStrictEqual(response); |
| 952 | + }); |
| 953 | + }); |
| 954 | + |
| 955 | + describe("deleteRoomTag", () => { |
| 956 | + it("should hit the expected API endpoint", async () => { |
| 957 | + const response = {}; |
| 958 | + const prom = client.deleteRoomTag("!roomId:server", "u.tag"); |
| 959 | + const url = `/user/${encodeURIComponent(userId)}/rooms/${encodeURIComponent("!roomId:server")}/tags/u.tag`; |
| 960 | + httpBackend.when("DELETE", url).respond(200, response); |
| 961 | + await httpBackend.flush(); |
| 962 | + expect(await prom).toStrictEqual(response); |
| 963 | + }); |
| 964 | + }); |
| 965 | + |
| 966 | + describe("getRoomTags", () => { |
| 967 | + it("should hit the expected API endpoint", async () => { |
| 968 | + const response = { |
| 969 | + tags: { |
| 970 | + "u.tag": { |
| 971 | + order: 0.5, |
| 972 | + }, |
| 973 | + }, |
| 974 | + }; |
| 975 | + |
| 976 | + const prom = client.getRoomTags("!roomId:server"); |
| 977 | + const url = `/user/${encodeURIComponent(userId)}/rooms/${encodeURIComponent("!roomId:server")}/tags`; |
| 978 | + httpBackend.when("GET", url).respond(200, response); |
| 979 | + await httpBackend.flush(); |
| 980 | + expect(await prom).toStrictEqual(response); |
| 981 | + }); |
| 982 | + }); |
| 983 | + |
| 984 | + describe("requestRegisterEmailToken", () => { |
| 985 | + it("should hit the expected API endpoint", async () => { |
| 986 | + const response = { |
| 987 | + sid: "random_sid", |
| 988 | + submit_url: "https://foobar.matrix/_matrix/matrix", |
| 989 | + }; |
| 990 | + |
| 991 | + httpBackend.when("GET", "/_matrix/client/versions").respond(200, { |
| 992 | + versions: ["r0.5.0"], |
| 993 | + }); |
| 994 | + |
| 995 | + const prom = client.requestRegisterEmailToken("bob@email", "secret", 1); |
| 996 | + httpBackend.when("POST", "/register/email/requestToken").check(req => { |
| 997 | + expect(req.data).toStrictEqual({ |
| 998 | + email: "bob@email", |
| 999 | + client_secret: "secret", |
| 1000 | + send_attempt: 1, |
| 1001 | + }); |
| 1002 | + }).respond(200, response); |
| 1003 | + await httpBackend.flush(); |
| 1004 | + expect(await prom).toStrictEqual(response); |
| 1005 | + }); |
| 1006 | + }); |
826 | 1007 | }); |
827 | 1008 |
|
828 | 1009 | function withThreadId(event, newThreadId) { |
|
0 commit comments