1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-04 05:02:41 +03:00

Prettier fixes

This commit is contained in:
Eric Eastwood
2022-12-13 16:26:14 -06:00
parent fcf12b49e3
commit 70a033c2fd
2 changed files with 107 additions and 131 deletions

View File

@@ -220,20 +220,18 @@ describe("MatrixClient", function () {
return Promise.resolve(next.data); return Promise.resolve(next.data);
} }
const receivedRequestQueryString = new URLSearchParams( const receivedRequestQueryString = new URLSearchParams(convertQueryDictToStringRecord(queryParams)).toString();
convertQueryDictToStringRecord(queryParams),
).toString();
const receivedRequestDebugString = `${method} ${prefix}${path}${receivedRequestQueryString}`; const receivedRequestDebugString = `${method} ${prefix}${path}${receivedRequestQueryString}`;
const expectedQueryString = new URLSearchParams( const expectedQueryString = new URLSearchParams(
convertQueryDictToStringRecord(next.expectQueryParams), convertQueryDictToStringRecord(next.expectQueryParams),
).toString(); ).toString();
const expectedRequestDebugString = `${next.method} ${next.prefix ?? ''}${next.path}${expectedQueryString}`; const expectedRequestDebugString = `${next.method} ${next.prefix ?? ""}${next.path}${expectedQueryString}`;
// If you're seeing this then you forgot to handle at least 1 pending request. // If you're seeing this then you forgot to handle at least 1 pending request.
throw new Error( throw new Error(
`A pending request was not handled: ${receivedRequestDebugString} ` + `A pending request was not handled: ${receivedRequestDebugString} ` +
`(next request expected was ${expectedRequestDebugString})\n` + `(next request expected was ${expectedRequestDebugString})\n` +
`Check your tests to ensure your number of expectations lines up with your number of requests ` + `Check your tests to ensure your number of expectations lines up with your number of requests ` +
`made, and that those requests match your expectations.`, `made, and that those requests match your expectations.`,
); );
} }
@@ -317,126 +315,117 @@ describe("MatrixClient", function () {
client.stopClient(); client.stopClient();
}); });
describe('timestampToEvent', () => { describe("timestampToEvent", () => {
const roomId = '!room:server.org'; const roomId = "!room:server.org";
const eventId = "$eventId:example.org"; const eventId = "$eventId:example.org";
const unstableMSC3030Prefix = "/_matrix/client/unstable/org.matrix.msc3030"; const unstableMSC3030Prefix = "/_matrix/client/unstable/org.matrix.msc3030";
it('should call stable endpoint', async () => { it("should call stable endpoint", async () => {
httpLookups = [{ httpLookups = [
method: "GET", {
path: `/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`, method: "GET",
data: { event_id: eventId }, path: `/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`,
expectQueryParams: { data: { event_id: eventId },
ts: '0', expectQueryParams: {
dir: 'f', ts: "0",
dir: "f",
},
}, },
}]; ];
await client.timestampToEvent(roomId, 0, Direction.Forward); await client.timestampToEvent(roomId, 0, Direction.Forward);
expect(mocked(client.http.authedRequest).mock.calls.length).toStrictEqual(1); expect(mocked(client.http.authedRequest).mock.calls.length).toStrictEqual(1);
const [method, path, queryParams,, { prefix }] = mocked(client.http.authedRequest).mock.calls[0]; const [method, path, queryParams, , { prefix }] = mocked(client.http.authedRequest).mock.calls[0];
expect(method).toStrictEqual('GET'); expect(method).toStrictEqual("GET");
expect(prefix).toStrictEqual(ClientPrefix.V1); expect(prefix).toStrictEqual(ClientPrefix.V1);
expect(path).toStrictEqual( expect(path).toStrictEqual(`/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`);
`/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`,
);
expect(queryParams).toStrictEqual({ expect(queryParams).toStrictEqual({
ts: '0', ts: "0",
dir: 'f', dir: "f",
}); });
}); });
it('should fallback to unstable endpoint when no support for stable endpoint', async () => { it("should fallback to unstable endpoint when no support for stable endpoint", async () => {
httpLookups = [{ httpLookups = [
method: "GET", {
path: `/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`, method: "GET",
prefix: ClientPrefix.V1, path: `/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`,
error: { prefix: ClientPrefix.V1,
httpStatus: 404, error: {
errcode: "M_UNRECOGNIZED", httpStatus: 404,
errcode: "M_UNRECOGNIZED",
},
expectQueryParams: {
ts: "0",
dir: "f",
},
}, },
expectQueryParams: { {
ts: '0', method: "GET",
dir: 'f', path: `/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`,
prefix: unstableMSC3030Prefix,
data: { event_id: eventId },
expectQueryParams: {
ts: "0",
dir: "f",
},
}, },
}, { ];
method: "GET",
path: `/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`,
prefix: unstableMSC3030Prefix,
data: { event_id: eventId },
expectQueryParams: {
ts: '0',
dir: 'f',
},
}];
await client.timestampToEvent(roomId, 0, Direction.Forward); await client.timestampToEvent(roomId, 0, Direction.Forward);
expect(mocked(client.http.authedRequest).mock.calls.length).toStrictEqual(2); expect(mocked(client.http.authedRequest).mock.calls.length).toStrictEqual(2);
const [ const [stableMethod, stablePath, stableQueryParams, , { prefix: stablePrefix }] = mocked(
stableMethod, client.http.authedRequest,
stablePath, ).mock.calls[0];
stableQueryParams, expect(stableMethod).toStrictEqual("GET");
,
{ prefix: stablePrefix },
] = mocked(client.http.authedRequest).mock.calls[0];
expect(stableMethod).toStrictEqual('GET');
expect(stablePrefix).toStrictEqual(ClientPrefix.V1); expect(stablePrefix).toStrictEqual(ClientPrefix.V1);
expect(stablePath).toStrictEqual( expect(stablePath).toStrictEqual(`/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`);
`/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`,
);
expect(stableQueryParams).toStrictEqual({ expect(stableQueryParams).toStrictEqual({
ts: '0', ts: "0",
dir: 'f', dir: "f",
}); });
const [ const [unstableMethod, unstablePath, unstableQueryParams, , { prefix: unstablePrefix }] = mocked(
unstableMethod, client.http.authedRequest,
unstablePath, ).mock.calls[1];
unstableQueryParams, expect(unstableMethod).toStrictEqual("GET");
,
{ prefix: unstablePrefix },
] = mocked(client.http.authedRequest).mock.calls[1];
expect(unstableMethod).toStrictEqual('GET');
expect(unstablePrefix).toStrictEqual(unstableMSC3030Prefix); expect(unstablePrefix).toStrictEqual(unstableMSC3030Prefix);
expect(unstablePath).toStrictEqual( expect(unstablePath).toStrictEqual(`/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`);
`/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`,
);
expect(unstableQueryParams).toStrictEqual({ expect(unstableQueryParams).toStrictEqual({
ts: '0', ts: "0",
dir: 'f', dir: "f",
}); });
}); });
it('should not fallback to unstable endpoint when stable endpoint returns an error', async () => { it("should not fallback to unstable endpoint when stable endpoint returns an error", async () => {
httpLookups = [{ httpLookups = [
method: "GET", {
path: `/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`, method: "GET",
prefix: ClientPrefix.V1, path: `/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`,
error: { prefix: ClientPrefix.V1,
httpStatus: 500, error: {
errcode: "Fake response error", httpStatus: 500,
errcode: "Fake response error",
},
expectQueryParams: {
ts: "0",
dir: "f",
},
}, },
expectQueryParams: { ];
ts: '0',
dir: 'f',
},
}];
await expect(client.timestampToEvent(roomId, 0, Direction.Forward)).rejects.toBeDefined(); await expect(client.timestampToEvent(roomId, 0, Direction.Forward)).rejects.toBeDefined();
expect(mocked(client.http.authedRequest).mock.calls.length).toStrictEqual(1); expect(mocked(client.http.authedRequest).mock.calls.length).toStrictEqual(1);
const [method, path, queryParams,, { prefix }] = mocked(client.http.authedRequest).mock.calls[0]; const [method, path, queryParams, , { prefix }] = mocked(client.http.authedRequest).mock.calls[0];
expect(method).toStrictEqual('GET'); expect(method).toStrictEqual("GET");
expect(prefix).toStrictEqual(ClientPrefix.V1); expect(prefix).toStrictEqual(ClientPrefix.V1);
expect(path).toStrictEqual( expect(path).toStrictEqual(`/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`);
`/rooms/${encodeURIComponent(roomId)}/timestamp_to_event`,
);
expect(queryParams).toStrictEqual({ expect(queryParams).toStrictEqual({
ts: '0', ts: "0",
dir: 'f', dir: "f",
}); });
}); });
}); });

View File

@@ -480,9 +480,9 @@ export interface ICapability {
enabled: boolean; enabled: boolean;
} }
export interface IChangePasswordCapability extends ICapability { } export interface IChangePasswordCapability extends ICapability {}
export interface IThreadsCapability extends ICapability { } export interface IThreadsCapability extends ICapability {}
interface ICapabilities { interface ICapabilities {
[key: string]: any; [key: string]: any;
@@ -1244,12 +1244,12 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
if (this.deviceId) { if (this.deviceId) {
logger.warn( logger.warn(
"not importing device because device ID is provided to " + "not importing device because device ID is provided to " +
"constructor independently of exported data", "constructor independently of exported data",
); );
} else if (this.credentials.userId) { } else if (this.credentials.userId) {
logger.warn( logger.warn(
"not importing device because user ID is provided to " + "not importing device because user ID is provided to " +
"constructor independently of exported data", "constructor independently of exported data",
); );
} else if (!opts.deviceToImport.deviceId) { } else if (!opts.deviceToImport.deviceId) {
logger.warn("not importing device because no device ID in exported data"); logger.warn("not importing device because no device ID in exported data");
@@ -1973,7 +1973,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
if (!isCryptoAvailable()) { if (!isCryptoAvailable()) {
throw new Error( throw new Error(
`End-to-end encryption not supported in this js-sdk build: did ` + `End-to-end encryption not supported in this js-sdk build: did ` +
`you remember to load the olm library?`, `you remember to load the olm library?`,
); );
} }
@@ -1998,13 +1998,13 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
if (userId === null) { if (userId === null) {
throw new Error( throw new Error(
`Cannot enable encryption on MatrixClient with unknown userId: ` + `Cannot enable encryption on MatrixClient with unknown userId: ` +
`ensure userId is passed in createClient().`, `ensure userId is passed in createClient().`,
); );
} }
if (this.deviceId === null) { if (this.deviceId === null) {
throw new Error( throw new Error(
`Cannot enable encryption on MatrixClient with unknown deviceId: ` + `Cannot enable encryption on MatrixClient with unknown deviceId: ` +
`ensure deviceId is passed in createClient().`, `ensure deviceId is passed in createClient().`,
); );
} }
@@ -5350,7 +5350,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
if (!this.timelineSupport) { if (!this.timelineSupport) {
throw new Error( throw new Error(
"timeline support is disabled. Set the 'timelineSupport'" + "timeline support is disabled. Set the 'timelineSupport'" +
" parameter to true when creating MatrixClient to enable it.", " parameter to true when creating MatrixClient to enable it.",
); );
} }
@@ -5590,7 +5590,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
if (!this.timelineSupport) { if (!this.timelineSupport) {
throw new Error( throw new Error(
"timeline support is disabled. Set the 'timelineSupport'" + "timeline support is disabled. Set the 'timelineSupport'" +
" parameter to true when creating MatrixClient to enable it.", " parameter to true when creating MatrixClient to enable it.",
); );
} }
@@ -9269,38 +9269,25 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
}; };
try { try {
return await this.http.authedRequest( return await this.http.authedRequest(Method.Get, path, queryParams, undefined, {
Method.Get, prefix: ClientPrefix.V1,
path, });
queryParams,
undefined,
{
prefix: ClientPrefix.V1,
},
);
} catch (err) { } catch (err) {
// Fallback to the prefixed unstable endpoint. Since the stable endpoint is // Fallback to the prefixed unstable endpoint. Since the stable endpoint is
// new, we should also try the unstable endpoint before giving up. We can // new, we should also try the unstable endpoint before giving up. We can
// remove this fallback request in a year (remove after 2023-11-28). // remove this fallback request in a year (remove after 2023-11-28).
if ( if (
(<MatrixError>err).errcode === "M_UNRECOGNIZED" && ( (<MatrixError>err).errcode === "M_UNRECOGNIZED" &&
// XXX: The 400 status code check should be removed in the future // XXX: The 400 status code check should be removed in the future
// when Synapse is compliant with MSC3743. // when Synapse is compliant with MSC3743.
(<MatrixError>err).httpStatus === 400 || ((<MatrixError>err).httpStatus === 400 ||
// This the correct standard status code for an unsupported // This the correct standard status code for an unsupported
// endpoint according to MSC3743. // endpoint according to MSC3743.
(<MatrixError>err).httpStatus === 404 (<MatrixError>err).httpStatus === 404)
)
) { ) {
return await this.http.authedRequest( return await this.http.authedRequest(Method.Get, path, queryParams, undefined, {
Method.Get, prefix: "/_matrix/client/unstable/org.matrix.msc3030",
path, });
queryParams,
undefined,
{
prefix: "/_matrix/client/unstable/org.matrix.msc3030",
},
);
} }
throw err; throw err;
@@ -9338,12 +9325,12 @@ export function fixNotificationCountOnDecryption(cli: MatrixClient, event: Matri
hasReadEvent = thread hasReadEvent = thread
? thread.hasUserReadEvent(cli.getUserId()!, event.getId()!) ? thread.hasUserReadEvent(cli.getUserId()!, event.getId()!)
: // If the thread object does not exist in the room yet, we don't : // If the thread object does not exist in the room yet, we don't
// want to calculate notification for this event yet. We have not // want to calculate notification for this event yet. We have not
// restored the read receipts yet and can't accurately calculate // restored the read receipts yet and can't accurately calculate
// highlight notifications at this stage. // highlight notifications at this stage.
// //
// This issue can likely go away when MSC3874 is implemented // This issue can likely go away when MSC3874 is implemented
true; true;
} else { } else {
hasReadEvent = room.hasUserReadEvent(cli.getUserId()!, event.getId()!); hasReadEvent = room.hasUserReadEvent(cli.getUserId()!, event.getId()!);
} }