1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-31 15:24:23 +03:00

Fix lints

This commit is contained in:
Eric Eastwood
2022-11-30 19:01:20 -06:00
parent 9a731cdf4f
commit ad8bb5d2cd

View File

@ -139,7 +139,7 @@ describe("MatrixClient", function() {
path: string, path: string,
queryParams?: QueryDict, queryParams?: QueryDict,
body?: Body, body?: Body,
requestOpts: IRequestOpts = {} requestOpts: IRequestOpts = {},
) { ) {
const { prefix } = requestOpts; const { prefix } = requestOpts;
if (path === KEEP_ALIVE_PATH && acceptKeepalives) { if (path === KEEP_ALIVE_PATH && acceptKeepalives) {
@ -205,9 +205,22 @@ describe("MatrixClient", function() {
} }
return Promise.resolve(next.data); return Promise.resolve(next.data);
} }
const receivedRequestQueryString = new URLSearchParams(
convertQueryDictToStringRecord(queryParams),
).toString();
const receivedRequest = decorateStringWithAnsiColor(
`${method} ${prefix}${path}${receivedRequestQueryString}`,
AnsiColorCode.Red,
);
const expectedQueryString = new URLSearchParams(
convertQueryDictToStringRecord(next.expectQueryParams),
).toString();
const expectedRequest = decorateStringWithAnsiColor(
`${next.method} ${next.prefix ?? ''}${next.path}${expectedQueryString}`,
AnsiColorCode.Green,
);
// 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.
const receivedRequest = decorateStringWithAnsiColor(`${method} ${prefix}${path}${new URLSearchParams(convertQueryDictToStringRecord(queryParams)).toString()}`, AnsiColorCode.Red);
const expectedRequest = decorateStringWithAnsiColor(`${next.method} ${next.prefix ?? ''}${next.path}${new URLSearchParams(convertQueryDictToStringRecord(next.expectQueryParams)).toString()}`, AnsiColorCode.Green);
throw new Error( throw new Error(
`A pending request was not handled: ${receivedRequest} ` + `A pending request was not handled: ${receivedRequest} ` +
`(next request expected was ${expectedRequest})\n` + `(next request expected was ${expectedRequest})\n` +
@ -286,7 +299,7 @@ describe("MatrixClient", function() {
data: { event_id: eventId }, data: { event_id: eventId },
expectQueryParams: { expectQueryParams: {
ts: '0', ts: '0',
dir: 'f' dir: 'f',
}, },
}]; }];
@ -297,11 +310,11 @@ describe("MatrixClient", function() {
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',
}); });
}); });
@ -312,11 +325,11 @@ describe("MatrixClient", function() {
prefix: ClientPrefix.V1, prefix: ClientPrefix.V1,
error: { error: {
httpStatus: 404, httpStatus: 404,
errcode: "M_UNRECOGNIZED" errcode: "M_UNRECOGNIZED",
}, },
expectQueryParams: { expectQueryParams: {
ts: '0', ts: '0',
dir: 'f' dir: 'f',
}, },
}, { }, {
method: "GET", method: "GET",
@ -325,33 +338,45 @@ describe("MatrixClient", function() {
data: { event_id: eventId }, data: { event_id: eventId },
expectQueryParams: { expectQueryParams: {
ts: '0', ts: '0',
dir: 'f' dir: 'f',
}, },
}]; }];
await client.timestampToEvent(roomId, 0, 'f'); await client.timestampToEvent(roomId, 0, 'f');
expect(client.http.authedRequest.mock.calls.length).toStrictEqual(2); expect(client.http.authedRequest.mock.calls.length).toStrictEqual(2);
const [stableMethod, stablePath, stableQueryParams,, { prefix: stablePrefix }] = client.http.authedRequest.mock.calls[0]; const [
stableMethod,
stablePath,
stableQueryParams,
,
{ prefix: stablePrefix },
] = client.http.authedRequest.mock.calls[0];
expect(stableMethod).toStrictEqual('GET'); 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 [unstableMethod, unstablePath, unstableQueryParams,, { prefix: unstablePrefix }] = client.http.authedRequest.mock.calls[1]; const [
unstableMethod,
unstablePath,
unstableQueryParams,
,
{ prefix: unstablePrefix },
] = client.http.authedRequest.mock.calls[1];
expect(unstableMethod).toStrictEqual('GET'); 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',
}); });
}); });
@ -362,11 +387,11 @@ describe("MatrixClient", function() {
prefix: ClientPrefix.V1, prefix: ClientPrefix.V1,
error: { error: {
httpStatus: 500, httpStatus: 500,
errcode: "Fake response error" errcode: "Fake response error",
}, },
expectQueryParams: { expectQueryParams: {
ts: '0', ts: '0',
dir: 'f' dir: 'f',
}, },
}]; }];
@ -377,11 +402,11 @@ describe("MatrixClient", function() {
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',
}); });
}); });
}); });