Merge commit from fork
and migrate existing account-level settings once-only for existing sessions.
This commit is contained in:
parent
5dda51f95c
commit
c7bbc1c045
5 changed files with 139 additions and 13 deletions
|
@ -14,11 +14,14 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { ClientEvent, MatrixClient, Room, SyncState } from "matrix-js-sdk";
|
||||
import { localstorage } from "modernizr";
|
||||
|
||||
import BasePlatform from "../../src/BasePlatform";
|
||||
import SdkConfig from "../../src/SdkConfig";
|
||||
import { SettingLevel } from "../../src/settings/SettingLevel";
|
||||
import SettingsStore from "../../src/settings/SettingsStore";
|
||||
import { mockPlatformPeg } from "../test-utils";
|
||||
import { mkStubRoom, mockPlatformPeg, stubClient } from "../test-utils";
|
||||
|
||||
const TEST_DATA = [
|
||||
{
|
||||
|
@ -84,4 +87,65 @@ describe("SettingsStore", () => {
|
|||
expect(SettingsStore.getValueAt(SettingLevel.DEVICE, SETTING_NAME_WITH_CONFIG_OVERRIDE)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("runMigrations", () => {
|
||||
let client: MatrixClient;
|
||||
let room: Room;
|
||||
let localStorageSetItemSpy: jest.SpyInstance;
|
||||
let localStorageSetPromise: Promise<void>;
|
||||
|
||||
beforeEach(() => {
|
||||
client = stubClient();
|
||||
room = mkStubRoom("!room:example.org", "Room", client);
|
||||
room.getAccountData = jest.fn().mockReturnValue({
|
||||
getContent: jest.fn().mockReturnValue({
|
||||
urlPreviewsEnabled_e2ee: true,
|
||||
}),
|
||||
});
|
||||
client.getRooms = jest.fn().mockReturnValue([room]);
|
||||
client.getRoom = jest.fn().mockReturnValue(room);
|
||||
|
||||
localStorageSetPromise = new Promise((resolve) => {
|
||||
localStorageSetItemSpy = jest
|
||||
.spyOn(localStorage.__proto__, "setItem")
|
||||
.mockImplementation(() => resolve());
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("migrates URL previews setting for e2ee rooms", async () => {
|
||||
SettingsStore.runMigrations(false);
|
||||
client.emit(ClientEvent.Sync, SyncState.Prepared, null);
|
||||
|
||||
expect(room.getAccountData).toHaveBeenCalled();
|
||||
|
||||
await localStorageSetPromise;
|
||||
|
||||
expect(localStorageSetItemSpy!).toHaveBeenCalledWith(
|
||||
`mx_setting_urlPreviewsEnabled_e2ee_${room.roomId}`,
|
||||
JSON.stringify({ value: true }),
|
||||
);
|
||||
});
|
||||
|
||||
it("does not migrate e2ee URL previews on a fresh login", async () => {
|
||||
SettingsStore.runMigrations(true);
|
||||
client.emit(ClientEvent.Sync, SyncState.Prepared, null);
|
||||
|
||||
expect(room.getAccountData).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not migrate if the device is flagged as migrated", async () => {
|
||||
jest.spyOn(localStorage.__proto__, "getItem").mockImplementation((key: unknown): string | undefined => {
|
||||
if (key === "url_previews_e2ee_migration_done") return JSON.stringify({ value: true });
|
||||
return undefined;
|
||||
});
|
||||
SettingsStore.runMigrations(false);
|
||||
client.emit(ClientEvent.Sync, SyncState.Prepared, null);
|
||||
|
||||
expect(room.getAccountData).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue