Skip to content

Commit

Permalink
adds unit tests that checks against event content modification inside…
Browse files Browse the repository at this point in the history
… setPowerLevel()
  • Loading branch information
GoodGuyMarco committed Nov 29, 2022
1 parent 4db5370 commit da0f4be
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions spec/integ/matrix-client-methods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1337,27 +1337,38 @@ describe("MatrixClient", function() {
});
});

describe("registerWithIdentityServer", () => {
it("should pass data to POST request", async () => {
const token = {
access_token: "access_token",
token_type: "Bearer",
matrix_server_name: "server_name",
expires_in: 12345,
};
describe("setPowerLevel", () => {
it.each([
{
userId: "alice@localhost",
expectation: {
"alice@localhost": 100,
},
},
{
userId: ["alice@localhost", "bob@localhost"],
expectation: {
"alice@localhost": 100,
"bob@localhost": 100,
},
},
])("should modify power levels of $userId correctly", async ({ userId, expectation }) => {
const event = {
getType: () => "m.room.power_levels",
getContent: () => ({
users: {
"alice@localhost": 50,
},
}),
} as MatrixEvent;

httpBackend!.when("POST", "/account/register").check(req => {
expect(req.data).toStrictEqual(token);
}).respond(200, {
access_token: "at",
token: "tt",
});
httpBackend!.when("PUT", "/state/m.room.power_levels").check(req => {
expect(req.data.users).toStrictEqual(expectation);
}).respond(200, {});

const prom = client!.registerWithIdentityServer(token);
const prom = client!.setPowerLevel("!room_id:server", userId, 100, event);
await httpBackend!.flushAllExpected();
const resp = await prom;
expect(resp.access_token).toBe("at");
expect(resp.token).toBe("tt");
await prom;
});
});
});
Expand Down

0 comments on commit da0f4be

Please sign in to comment.