|
| 1 | +/* |
| 2 | +Copyright 2022 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +/// <reference types="cypress" /> |
| 18 | + |
| 19 | +import { SynapseInstance } from "../../plugins/synapsedocker"; |
| 20 | + |
| 21 | +function seedLabs(synapse: SynapseInstance, labsVal: boolean | null): void { |
| 22 | + cy.initTestUser(synapse, "Sally", () => { |
| 23 | + // seed labs flag |
| 24 | + cy.window({ log: false }).then(win => { |
| 25 | + if (typeof labsVal === "boolean") { |
| 26 | + // stringify boolean |
| 27 | + win.localStorage.setItem("mx_labs_feature_feature_hidden_read_receipts", `${labsVal}`); |
| 28 | + } |
| 29 | + }); |
| 30 | + }); |
| 31 | +} |
| 32 | + |
| 33 | +function testForVal(settingVal: boolean | null): void { |
| 34 | + const testRoomName = "READ RECEIPTS"; |
| 35 | + cy.createRoom({ name: testRoomName }).as("roomId"); |
| 36 | + cy.all([cy.get<string>("@roomId")]).then(() => { |
| 37 | + cy.viewRoomByName(testRoomName).then(() => { |
| 38 | + // if we can see the room, then sync is working for us. It's time to see if the |
| 39 | + // migration even ran. |
| 40 | + |
| 41 | + cy.getSettingValue("sendReadReceipts", null, true).should("satisfy", (val) => { |
| 42 | + if (typeof settingVal === "boolean") { |
| 43 | + return val === settingVal; |
| 44 | + } else { |
| 45 | + return !val; // falsy - we don't actually care if it's undefined, null, or a literal false |
| 46 | + } |
| 47 | + }); |
| 48 | + }); |
| 49 | + }); |
| 50 | +} |
| 51 | + |
| 52 | +describe("Hidden Read Receipts Setting Migration", () => { |
| 53 | + // We run this as a full-blown end-to-end test to ensure it works in an integration |
| 54 | + // sense. If we unit tested it, we'd be testing that the code works but not that the |
| 55 | + // migration actually runs. |
| 56 | + // |
| 57 | + // Here, we get to test that not only the code works but also that it gets run. Most |
| 58 | + // of our interactions are with the JS console as we're honestly just checking that |
| 59 | + // things got set correctly. |
| 60 | + // |
| 61 | + // For a security-sensitive feature like hidden read receipts, it's absolutely vital |
| 62 | + // that we migrate the setting appropriately. |
| 63 | + |
| 64 | + let synapse: SynapseInstance; |
| 65 | + |
| 66 | + beforeEach(() => { |
| 67 | + cy.startSynapse("default").then(data => { |
| 68 | + synapse = data; |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + afterEach(() => { |
| 73 | + cy.stopSynapse(synapse); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should not migrate the lack of a labs flag', () => { |
| 77 | + seedLabs(synapse, null); |
| 78 | + testForVal(null); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should migrate labsHiddenRR=false as sendRR=true', () => { |
| 82 | + seedLabs(synapse, false); |
| 83 | + testForVal(true); |
| 84 | + }); |
| 85 | + |
| 86 | + it('should migrate labsHiddenRR=true as sendRR=false', () => { |
| 87 | + seedLabs(synapse, true); |
| 88 | + testForVal(false); |
| 89 | + }); |
| 90 | +}); |
0 commit comments