Skip to content

Commit

Permalink
Remove deprecated callbacks support
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy committed Oct 3, 2022
1 parent e36d41a commit f6f4a0a
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 692 deletions.
8 changes: 4 additions & 4 deletions spec/unit/crypto/backup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ describe("MegolmBackup", function() {
let numCalls = 0;
return new Promise<void>((resolve, reject) => {
client.http.authedRequest = function(
callback, method, path, queryParams, data, opts,
method, path, queryParams, data, opts,
) {
++numCalls;
expect(numCalls).toBeLessThanOrEqual(1);
Expand Down Expand Up @@ -382,7 +382,7 @@ describe("MegolmBackup", function() {
let numCalls = 0;
return new Promise<void>((resolve, reject) => {
client.http.authedRequest = function(
callback, method, path, queryParams, data, opts,
method, path, queryParams, data, opts,
) {
++numCalls;
expect(numCalls).toBeLessThanOrEqual(1);
Expand Down Expand Up @@ -439,7 +439,7 @@ describe("MegolmBackup", function() {
new Promise<void>((resolve, reject) => {
let backupInfo;
client.http.authedRequest = function(
callback, method, path, queryParams, data, opts,
method, path, queryParams, data, opts,
) {
++numCalls;
expect(numCalls).toBeLessThanOrEqual(2);
Expand Down Expand Up @@ -543,7 +543,7 @@ describe("MegolmBackup", function() {

await new Promise<void>((resolve, reject) => {
client.http.authedRequest = function(
callback, method, path, queryParams, data, opts,
method, path, queryParams, data, opts,
) {
++numCalls;
expect(numCalls).toBeLessThanOrEqual(2);
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/crypto/cross-signing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe("Cross Signing", function() {
};
alice.uploadKeySignatures = async () => ({ failures: {} });
alice.setAccountData = async () => ({});
alice.getAccountDataFromServer = async <T extends {[k: string]: any}>(): Promise<T> => ({} as T);
alice.getAccountDataFromServer = async <T extends {[k: string]: any}>(): Promise<T | null> => ({} as T);
const authUploadDeviceSigningKeys = async func => await func({});

// Try bootstrap, expecting `authUploadDeviceSigningKeys` to pass
Expand Down
9 changes: 3 additions & 6 deletions spec/unit/crypto/secrets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,13 @@ describe("Secrets", function() {
const secretStorage = alice.crypto.secretStorage;

jest.spyOn(alice, 'setAccountData').mockImplementation(
async function(eventType, contents, callback) {
async function(eventType, contents) {
alice.store.storeAccountDataEvents([
new MatrixEvent({
type: eventType,
content: contents,
}),
]);
if (callback) {
callback(undefined, undefined);
}
return {};
});

Expand Down Expand Up @@ -192,7 +189,7 @@ describe("Secrets", function() {
},
},
);
alice.setAccountData = async function(eventType, contents, callback) {
alice.setAccountData = async function(eventType, contents) {
alice.store.storeAccountDataEvents([
new MatrixEvent({
type: eventType,
Expand Down Expand Up @@ -332,7 +329,7 @@ describe("Secrets", function() {
);
bob.uploadDeviceSigningKeys = async () => ({});
bob.uploadKeySignatures = jest.fn().mockResolvedValue(undefined);
bob.setAccountData = async function(eventType, contents, callback) {
bob.setAccountData = async function(eventType, contents) {
const event = new MatrixEvent({
type: eventType,
content: contents,
Expand Down
36 changes: 14 additions & 22 deletions spec/unit/matrix-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe("MatrixClient", function() {
];
let acceptKeepalives: boolean;
let pendingLookup = null;
function httpReq(cb, method, path, qp, data, prefix) {
function httpReq(method, path, qp, data, prefix) {
if (path === KEEP_ALIVE_PATH && acceptKeepalives) {
return Promise.resolve({
unstable_features: {
Expand Down Expand Up @@ -1153,8 +1153,7 @@ describe("MatrixClient", function() {

// event type combined
const expectedEventType = M_BEACON_INFO.name;
const [callback, method, path, queryParams, requestContent] = client.http.authedRequest.mock.calls[0];
expect(callback).toBeFalsy();
const [method, path, queryParams, requestContent] = client.http.authedRequest.mock.calls[0];
expect(method).toBe('PUT');
expect(path).toEqual(
`/rooms/${encodeURIComponent(roomId)}/state/` +
Expand All @@ -1168,7 +1167,7 @@ describe("MatrixClient", function() {
await client.unstable_setLiveBeacon(roomId, content);

// event type combined
const [, , path, , requestContent] = client.http.authedRequest.mock.calls[0];
const [, path, , requestContent] = client.http.authedRequest.mock.calls[0];
expect(path).toEqual(
`/rooms/${encodeURIComponent(roomId)}/state/` +
`${encodeURIComponent(M_BEACON_INFO.name)}/${encodeURIComponent(userId)}`,
Expand Down Expand Up @@ -1229,7 +1228,7 @@ describe("MatrixClient", function() {
it("is called with plain text topic and callback and sends state event", async () => {
const sendStateEvent = createSendStateEventMock("pizza");
client.sendStateEvent = sendStateEvent;
await client.setRoomTopic(roomId, "pizza", () => {});
await client.setRoomTopic(roomId, "pizza");
expect(sendStateEvent).toHaveBeenCalledTimes(1);
});

Expand All @@ -1244,15 +1243,9 @@ describe("MatrixClient", function() {
describe("setPassword", () => {
const auth = { session: 'abcdef', type: 'foo' };
const newPassword = 'newpassword';
const callback = () => {};

const passwordTest = (expectedRequestContent: any, expectedCallback?: Function) => {
const [callback, method, path, queryParams, requestContent] = client.http.authedRequest.mock.calls[0];
if (expectedCallback) {
expect(callback).toBe(expectedCallback);
} else {
expect(callback).toBeFalsy();
}

const passwordTest = (expectedRequestContent: any) => {
const [method, path, queryParams, requestContent] = client.http.authedRequest.mock.calls[0];
expect(method).toBe('POST');
expect(path).toEqual('/account/password');
expect(queryParams).toBeFalsy();
Expand All @@ -1269,8 +1262,8 @@ describe("MatrixClient", function() {
});

it("no logout_devices specified + callback", async () => {
await client.setPassword(auth, newPassword, callback);
passwordTest({ auth, new_password: newPassword }, callback);
await client.setPassword(auth, newPassword);
passwordTest({ auth, new_password: newPassword });
});

it("overload logoutDevices=true", async () => {
Expand All @@ -1279,8 +1272,8 @@ describe("MatrixClient", function() {
});

it("overload logoutDevices=true + callback", async () => {
await client.setPassword(auth, newPassword, true, callback);
passwordTest({ auth, new_password: newPassword, logout_devices: true }, callback);
await client.setPassword(auth, newPassword, true);
passwordTest({ auth, new_password: newPassword, logout_devices: true });
});

it("overload logoutDevices=false", async () => {
Expand All @@ -1289,8 +1282,8 @@ describe("MatrixClient", function() {
});

it("overload logoutDevices=false + callback", async () => {
await client.setPassword(auth, newPassword, false, callback);
passwordTest({ auth, new_password: newPassword, logout_devices: false }, callback);
await client.setPassword(auth, newPassword, false);
passwordTest({ auth, new_password: newPassword, logout_devices: false });
});
});

Expand All @@ -1305,8 +1298,7 @@ describe("MatrixClient", function() {
const result = await client.getLocalAliases(roomId);

// Current version of the endpoint we support is v3
const [callback, method, path, queryParams, data, opts] = client.http.authedRequest.mock.calls[0];
expect(callback).toBeFalsy();
const [method, path, queryParams, data, opts] = client.http.authedRequest.mock.calls[0];
expect(data).toBeFalsy();
expect(method).toBe('GET');
expect(path).toEqual(`/rooms/${encodeURIComponent(roomId)}/aliases`);
Expand Down
2 changes: 0 additions & 2 deletions src/@types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { Callback } from "../client";
import { IContent, IEvent } from "../models/event";
import { Preset, Visibility } from "./partials";
import { IEventWithRoomId, SearchKey } from "./search";
Expand Down Expand Up @@ -125,7 +124,6 @@ export interface IUploadOpts {
type?: string;
rawResponse?: boolean;
onlyContentUri?: boolean;
callback?: Callback;
progressHandler?: (state: {loaded: number, total: number}) => void;
}

Expand Down
Loading

0 comments on commit f6f4a0a

Please sign in to comment.