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

Rename convertQueryDictToMap

This commit is contained in:
Andy Balaam
2023-01-06 14:21:35 +00:00
parent b1566ee540
commit d7442147b9

View File

@ -68,9 +68,9 @@ jest.mock("../../src/webrtc/call", () => ({
supportsMatrixCall: jest.fn(() => false),
}));
// Utility function to ease the transition from our QueryDict type to a string record
// which we can use to stringify with URLSearchParams
function convertQueryDictToStringRecord(queryDict?: QueryDict): Map<string, string> {
// Utility function to ease the transition from our QueryDict type to a Map
// which we can use to build a URLSearchParams
function convertQueryDictToMap(queryDict?: QueryDict): Map<string, string> {
if (!queryDict) {
return new Map();
}
@ -100,15 +100,15 @@ type WrappedRoom = Room & {
describe("convertQueryDictToStringRecord", () => {
it("returns an empty map when dict is undefined", () => {
expect(convertQueryDictToStringRecord(undefined)).toEqual(new Map());
expect(convertQueryDictToMap(undefined)).toEqual(new Map());
});
it("converts an empty QueryDict to an empty map", () => {
expect(convertQueryDictToStringRecord({})).toEqual(new Map());
expect(convertQueryDictToMap({})).toEqual(new Map());
});
it("converts a QueryDict of strings to the equivalent map", () => {
expect(convertQueryDictToStringRecord({ a: "b", c: "d" })).toEqual(
expect(convertQueryDictToMap({ a: "b", c: "d" })).toEqual(
new Map([
["a", "b"],
["c", "d"],
@ -117,7 +117,7 @@ describe("convertQueryDictToStringRecord", () => {
});
it("converts the values of the supplied QueryDict to strings", () => {
expect(convertQueryDictToStringRecord({ arr: ["b", "c"], num: 45, boo: true, und: undefined })).toEqual(
expect(convertQueryDictToMap({ arr: ["b", "c"], num: 45, boo: true, und: undefined })).toEqual(
new Map([
["arr", "b,c"],
["num", "45"],
@ -128,7 +128,7 @@ describe("convertQueryDictToStringRecord", () => {
});
it("produces sane URLSearchParams conversions", () => {
expect(new URLSearchParams(Array.from(convertQueryDictToStringRecord({ a: "b", c: "d" }))).toString()).toEqual(
expect(new URLSearchParams(Array.from(convertQueryDictToMap({ a: "b", c: "d" }))).toString()).toEqual(
"a=b&c=d",
);
});
@ -255,11 +255,11 @@ describe("MatrixClient", function () {
}
const receivedRequestQueryString = new URLSearchParams(
Array.from(convertQueryDictToStringRecord(queryParams)),
Array.from(convertQueryDictToMap(queryParams)),
).toString();
const receivedRequestDebugString = `${method} ${prefix}${path}${receivedRequestQueryString}`;
const expectedQueryString = new URLSearchParams(
Array.from(convertQueryDictToStringRecord(next.expectQueryParams)),
Array.from(convertQueryDictToMap(next.expectQueryParams)),
).toString();
const expectedRequestDebugString = `${next.method} ${next.prefix ?? ""}${next.path}${expectedQueryString}`;
// If you're seeing this then you forgot to handle at least 1 pending request.