Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFerr committed Jul 17, 2024
1 parent 5026968 commit f57b2be
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions spec/unit/embedded.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,15 @@ class MockWidgetApi extends EventEmitter {
public requestCapabilityToSendToDevice = jest.fn();
public requestCapabilityToReceiveToDevice = jest.fn();
public sendRoomEvent = jest.fn(
(
eventType: string,
content: unknown,
roomId?: string,
futureTimeout?: number,
futureGroupId?: string
) =>
(eventType: string, content: unknown, roomId?: string, futureTimeout?: number, futureGroupId?: string) =>
futureTimeout === undefined && futureGroupId === undefined
? { event_id: `$${Math.random()}` }
: {
future_group_id: futureGroupId ?? `fg-${Math.random()}`,
send_token: `st-${Math.random()}`,
cancel_token: `ct-${Math.random()}`,
refresh_token: `rt-${Math.random()}`,
}
},
);
public sendStateEvent = jest.fn(
(
Expand All @@ -92,7 +86,7 @@ class MockWidgetApi extends EventEmitter {
send_token: `st-${Math.random()}`,
cancel_token: `ct-${Math.random()}`,
refresh_token: `rt-${Math.random()}`,
}
},
);
public sendToDevice = jest.fn();
public requestOpenIDConnectToken = jest.fn(() => {
Expand Down Expand Up @@ -196,7 +190,7 @@ describe("RoomWidgetClient", () => {
describe("futures", () => {
describe("when supported", () => {
const doesServerSupportUnstableFeatureMock = jest.fn((feature) =>
Promise.resolve(feature === "org.matrix.msc4140")
Promise.resolve(feature === "org.matrix.msc4140"),
);

beforeAll(() => {
Expand Down Expand Up @@ -300,7 +294,7 @@ describe("RoomWidgetClient", () => {
};

for (const missingField of Object.keys(response)) {
const badResponse: Record<string, string> = {...response};
const badResponse: Record<string, string> = { ...response };
delete badResponse[missingField];
const fullBadResponse = { ...badResponse, room_id: "!1:example.org" };

Expand All @@ -314,7 +308,7 @@ describe("RoomWidgetClient", () => {
null,
"org.matrix.rageshake_request",
{ request_id: 123 },
)
),
).rejects.toThrow(`'${missingField}' absent from response`);

Check failure on line 312 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

RoomWidgetClient › futures › when supported › when improperly implemented › fails to send message futures without a future_group_id

expect(received).rejects.toThrow(expected) Expected substring: "'future_group_id' absent from response" Received message: "'future_id' absent from response to a future request" 330 | private validateSendFutureResponse(response: ISendEventFromWidgetResponseData): SendFutureResponse { 331 | if (!response.future_id) { > 332 | throw new Error("'future_id' absent from response to a future request"); | ^ 333 | } 334 | return { future_id: response.future_id }; 335 | } at RoomWidgetClient.validateSendFutureResponse (src/embedded.ts:332:19) at validateSendFutureResponse (src/embedded.ts:272:25) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at Object.toThrow (node_modules/expect/build/index.js:218:22) at Object.toThrow (spec/unit/embedded.spec.ts:312:35) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)

Check failure on line 312 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

RoomWidgetClient › futures › when supported › when improperly implemented › fails to send message futures without a send_token

expect(received).rejects.toThrow(expected) Expected substring: "'send_token' absent from response" Received message: "'future_id' absent from response to a future request" 330 | private validateSendFutureResponse(response: ISendEventFromWidgetResponseData): SendFutureResponse { 331 | if (!response.future_id) { > 332 | throw new Error("'future_id' absent from response to a future request"); | ^ 333 | } 334 | return { future_id: response.future_id }; 335 | } at RoomWidgetClient.validateSendFutureResponse (src/embedded.ts:332:19) at validateSendFutureResponse (src/embedded.ts:272:25) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at Object.toThrow (node_modules/expect/build/index.js:218:22) at Object.toThrow (spec/unit/embedded.spec.ts:312:35) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)

Check failure on line 312 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

RoomWidgetClient › futures › when supported › when improperly implemented › fails to send message futures without a cancel_token

expect(received).rejects.toThrow(expected) Expected substring: "'cancel_token' absent from response" Received message: "'future_id' absent from response to a future request" 330 | private validateSendFutureResponse(response: ISendEventFromWidgetResponseData): SendFutureResponse { 331 | if (!response.future_id) { > 332 | throw new Error("'future_id' absent from response to a future request"); | ^ 333 | } 334 | return { future_id: response.future_id }; 335 | } at RoomWidgetClient.validateSendFutureResponse (src/embedded.ts:332:19) at validateSendFutureResponse (src/embedded.ts:272:25) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at Object.toThrow (node_modules/expect/build/index.js:218:22) at Object.toThrow (spec/unit/embedded.spec.ts:312:35) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)

Check failure on line 312 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

RoomWidgetClient › futures › when supported › when improperly implemented › fails to send message futures without a future_group_id

expect(received).rejects.toThrow(expected) Expected substring: "'future_group_id' absent from response" Received message: "'future_id' absent from response to a future request" 330 | private validateSendFutureResponse(response: ISendEventFromWidgetResponseData): SendFutureResponse { 331 | if (!response.future_id) { > 332 | throw new Error("'future_id' absent from response to a future request"); | ^ 333 | } 334 | return { future_id: response.future_id }; 335 | } at RoomWidgetClient.validateSendFutureResponse (src/embedded.ts:332:19) at validateSendFutureResponse (src/embedded.ts:272:25) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at Object.toThrow (node_modules/expect/build/index.js:218:22) at Object.toThrow (spec/unit/embedded.spec.ts:312:35) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)

Check failure on line 312 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

RoomWidgetClient › futures › when supported › when improperly implemented › fails to send message futures without a send_token

expect(received).rejects.toThrow(expected) Expected substring: "'send_token' absent from response" Received message: "'future_id' absent from response to a future request" 330 | private validateSendFutureResponse(response: ISendEventFromWidgetResponseData): SendFutureResponse { 331 | if (!response.future_id) { > 332 | throw new Error("'future_id' absent from response to a future request"); | ^ 333 | } 334 | return { future_id: response.future_id }; 335 | } at RoomWidgetClient.validateSendFutureResponse (src/embedded.ts:332:19) at validateSendFutureResponse (src/embedded.ts:272:25) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at Object.toThrow (node_modules/expect/build/index.js:218:22) at Object.toThrow (spec/unit/embedded.spec.ts:312:35) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)

Check failure on line 312 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

RoomWidgetClient › futures › when supported › when improperly implemented › fails to send message futures without a cancel_token

expect(received).rejects.toThrow(expected) Expected substring: "'cancel_token' absent from response" Received message: "'future_id' absent from response to a future request" 330 | private validateSendFutureResponse(response: ISendEventFromWidgetResponseData): SendFutureResponse { 331 | if (!response.future_id) { > 332 | throw new Error("'future_id' absent from response to a future request"); | ^ 333 | } 334 | return { future_id: response.future_id }; 335 | } at RoomWidgetClient.validateSendFutureResponse (src/embedded.ts:332:19) at validateSendFutureResponse (src/embedded.ts:272:25) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at Object.toThrow (node_modules/expect/build/index.js:218:22) at Object.toThrow (spec/unit/embedded.spec.ts:312:35) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)
});

Expand All @@ -323,12 +317,12 @@ describe("RoomWidgetClient", () => {
await makeClient({ sendState: [{ eventType: "org.example.foo", stateKey: "bar" }] });
await expect(
client._unstable_sendStateFuture(
"!1:example.org",
{ future_timeout: 2000, },
"org.example.foo",
{ hello: "world" },
"bar",
)
"!1:example.org",
{ future_timeout: 2000 },
"org.example.foo",
{ hello: "world" },
"bar",
),
).rejects.toThrow(`'${missingField}' absent from response`);

Check failure on line 326 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

RoomWidgetClient › futures › when supported › when improperly implemented › fails to send state futures without a future_group_id

expect(received).rejects.toThrow(expected) Expected substring: "'future_group_id' absent from response" Received message: "'future_id' absent from response to a future request" 330 | private validateSendFutureResponse(response: ISendEventFromWidgetResponseData): SendFutureResponse { 331 | if (!response.future_id) { > 332 | throw new Error("'future_id' absent from response to a future request"); | ^ 333 | } 334 | return { future_id: response.future_id }; 335 | } at RoomWidgetClient.validateSendFutureResponse (src/embedded.ts:332:19) at validateSendFutureResponse (src/embedded.ts:320:21) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at Object.toThrow (node_modules/expect/build/index.js:218:22) at Object.toThrow (spec/unit/embedded.spec.ts:326:35) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)

Check failure on line 326 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

RoomWidgetClient › futures › when supported › when improperly implemented › fails to send state futures without a send_token

expect(received).rejects.toThrow(expected) Expected substring: "'send_token' absent from response" Received message: "'future_id' absent from response to a future request" 330 | private validateSendFutureResponse(response: ISendEventFromWidgetResponseData): SendFutureResponse { 331 | if (!response.future_id) { > 332 | throw new Error("'future_id' absent from response to a future request"); | ^ 333 | } 334 | return { future_id: response.future_id }; 335 | } at RoomWidgetClient.validateSendFutureResponse (src/embedded.ts:332:19) at validateSendFutureResponse (src/embedded.ts:320:21) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at Object.toThrow (node_modules/expect/build/index.js:218:22) at Object.toThrow (spec/unit/embedded.spec.ts:326:35) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)

Check failure on line 326 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

RoomWidgetClient › futures › when supported › when improperly implemented › fails to send state futures without a cancel_token

expect(received).rejects.toThrow(expected) Expected substring: "'cancel_token' absent from response" Received message: "'future_id' absent from response to a future request" 330 | private validateSendFutureResponse(response: ISendEventFromWidgetResponseData): SendFutureResponse { 331 | if (!response.future_id) { > 332 | throw new Error("'future_id' absent from response to a future request"); | ^ 333 | } 334 | return { future_id: response.future_id }; 335 | } at RoomWidgetClient.validateSendFutureResponse (src/embedded.ts:332:19) at validateSendFutureResponse (src/embedded.ts:320:21) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at Object.toThrow (node_modules/expect/build/index.js:218:22) at Object.toThrow (spec/unit/embedded.spec.ts:326:35) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)

Check failure on line 326 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

RoomWidgetClient › futures › when supported › when improperly implemented › fails to send state futures without a future_group_id

expect(received).rejects.toThrow(expected) Expected substring: "'future_group_id' absent from response" Received message: "'future_id' absent from response to a future request" 330 | private validateSendFutureResponse(response: ISendEventFromWidgetResponseData): SendFutureResponse { 331 | if (!response.future_id) { > 332 | throw new Error("'future_id' absent from response to a future request"); | ^ 333 | } 334 | return { future_id: response.future_id }; 335 | } at RoomWidgetClient.validateSendFutureResponse (src/embedded.ts:332:19) at validateSendFutureResponse (src/embedded.ts:320:21) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at Object.toThrow (node_modules/expect/build/index.js:218:22) at Object.toThrow (spec/unit/embedded.spec.ts:326:35) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)

Check failure on line 326 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

RoomWidgetClient › futures › when supported › when improperly implemented › fails to send state futures without a send_token

expect(received).rejects.toThrow(expected) Expected substring: "'send_token' absent from response" Received message: "'future_id' absent from response to a future request" 330 | private validateSendFutureResponse(response: ISendEventFromWidgetResponseData): SendFutureResponse { 331 | if (!response.future_id) { > 332 | throw new Error("'future_id' absent from response to a future request"); | ^ 333 | } 334 | return { future_id: response.future_id }; 335 | } at RoomWidgetClient.validateSendFutureResponse (src/embedded.ts:332:19) at validateSendFutureResponse (src/embedded.ts:320:21) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at Object.toThrow (node_modules/expect/build/index.js:218:22) at Object.toThrow (spec/unit/embedded.spec.ts:326:35) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)

Check failure on line 326 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

RoomWidgetClient › futures › when supported › when improperly implemented › fails to send state futures without a cancel_token

expect(received).rejects.toThrow(expected) Expected substring: "'cancel_token' absent from response" Received message: "'future_id' absent from response to a future request" 330 | private validateSendFutureResponse(response: ISendEventFromWidgetResponseData): SendFutureResponse { 331 | if (!response.future_id) { > 332 | throw new Error("'future_id' absent from response to a future request"); | ^ 333 | } 334 | return { future_id: response.future_id }; 335 | } at RoomWidgetClient.validateSendFutureResponse (src/embedded.ts:332:19) at validateSendFutureResponse (src/embedded.ts:320:21) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at Object.toThrow (node_modules/expect/build/index.js:218:22) at Object.toThrow (spec/unit/embedded.spec.ts:326:35) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)
});
}
Expand All @@ -345,20 +339,20 @@ describe("RoomWidgetClient", () => {
null,
"org.matrix.rageshake_request",
{ request_id: 123 },
)
),
).rejects.toThrow("Server does not support the Futures API");
});

it("fails to send state futures", async () => {
await makeClient({ sendState: [{ eventType: "org.example.foo", stateKey: "bar" }] });
await expect(
client._unstable_sendStateFuture(
"!1:example.org",
{ future_timeout: 2000, },
"org.example.foo",
{ hello: "world" },
"bar",
)
"!1:example.org",
{ future_timeout: 2000 },
"org.example.foo",
{ hello: "world" },
"bar",
),
).rejects.toThrow("Server does not support the Futures API");
});
});
Expand Down

0 comments on commit f57b2be

Please sign in to comment.