Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

sliding sync: Add test to verify we send unsubscribe_rooms for every room switch #9784

Merged
merged 12 commits into from
Dec 22, 2022
Merged
45 changes: 45 additions & 0 deletions cypress/e2e/sliding-sync/sliding-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.

import _ from "lodash";
import { MatrixClient } from "matrix-js-sdk/src/matrix";
import { Interception } from "cypress/types/net-stubbing";

import { SynapseInstance } from "../../plugins/synapsedocker";
import { SettingLevel } from "../../../src/settings/SettingLevel";
Expand Down Expand Up @@ -407,4 +408,48 @@ describe("Sliding Sync", () => {
// ensure the reply-to does not disappear
cy.get(".mx_ReplyPreview").should("exist");
});

it("should send unsubscribe_rooms for every room switch", () => {
// create rooms and check room names are correct
cy.createRoom({ name: "Apple" })
.as("roomA")
.then(() => cy.contains(".mx_RoomSublist", "Apple"));
cy.createRoom({ name: "Pineapple" })
.as("roomP")
.then(() => cy.contains(".mx_RoomSublist", "Pineapple"));
cy.createRoom({ name: "Orange" })
.as("roomO")
.then(() => cy.contains(".mx_RoomSublist", "Orange"));

// Intercept all calls to /sync
cy.intercept({ method: "POST", url: "**/sync*" }).as("syncRequest");

const assertUnsubExists = (interception: Interception) => {
// There may be a request without a txn_id, ignore it, as there won't be any subscription changes
if (interception.request.body.txn_id === undefined) {
return;
}
assert.isArray(interception.request.body.unsubscribe_rooms, "unsubscribe_rooms is array");
assert.isObject(interception.request.body.room_subscriptions, "room_subscriptions is object");
};

// Select the Test Room
cy.contains(".mx_RoomTile", "Test Room").click();

// and wait for cypress to get the result as alias
cy.wait("@syncRequest").then((interception) => {
// This is the first switch, so no unsubscriptions yet.
assert.isObject(interception.request.body.room_subscriptions, "room_subscriptions is object");
});

// Switch to another room
cy.contains(".mx_RoomTile", "Pineapple").click();
cy.wait("@syncRequest").then((interception) => assertUnsubExists(interception));

// And switch to even another room
cy.contains(".mx_RoomTile", "Apple").click();
cy.wait("@syncRequest").then((interception) => assertUnsubExists(interception));

// TODO: Add tests for encrypted rooms
});
});