mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 09:43:23 +00:00
* WIP: safer state migrations Co-authored-by: Justin Baur <justindbaur@users.noreply.github.com> * Add min version check and remove old migrations Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com> * Add rollback and version checking * Add state version move migration * Expand tests and improve typing for Migrations * Remove StateMigration Service * Rewrite version 5 and 6 migrations * Add all but initial migration to supported migrations * Handle stateVersion location in migrator update versions * Move to unique migrations directory * Disallow imports outside of state-migrations * Lint and test fixes * Do not run migrations if we cannot determine state * Fix desktop background StateService build * Document Migration builder class * Add debug logging to migrations * Comment on migrator overrides * Use specific property names * `npm run prettier` 🤖 * Insert new migration * Set stateVersion when creating new globals object * PR comments * Fix migrate imports * Move migration building into `migrate` function * Export current version from migration definitions * Move file version concerns to migrator * Update migrate spec to reflect new version requirements * Fix import paths * Prefer unique state data * Remove unnecessary async * Prefer to not use `any` --------- Co-authored-by: Justin Baur <justindbaur@users.noreply.github.com> Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com>
76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
import { MockProxy } from "jest-mock-extended";
|
|
|
|
import { MigrationHelper } from "../migration-helper";
|
|
import { mockMigrationHelper } from "../migration-helper.spec";
|
|
|
|
import { RemoveEverBeenUnlockedMigrator } from "./4-remove-ever-been-unlocked";
|
|
|
|
function migrateExampleJSON() {
|
|
return {
|
|
global: {
|
|
stateVersion: 3,
|
|
otherStuff: "otherStuff1",
|
|
},
|
|
authenticatedAccounts: [
|
|
"c493ed01-4e08-4e88-abc7-332f380ca760",
|
|
"23e61a5f-2ece-4f5e-b499-f0bc489482a9",
|
|
],
|
|
"c493ed01-4e08-4e88-abc7-332f380ca760": {
|
|
profile: {
|
|
otherStuff: "otherStuff2",
|
|
everBeenUnlocked: true,
|
|
},
|
|
otherStuff: "otherStuff3",
|
|
},
|
|
"23e61a5f-2ece-4f5e-b499-f0bc489482a9": {
|
|
profile: {
|
|
otherStuff: "otherStuff4",
|
|
everBeenUnlocked: false,
|
|
},
|
|
otherStuff: "otherStuff5",
|
|
},
|
|
otherStuff: "otherStuff6",
|
|
};
|
|
}
|
|
|
|
describe("RemoveEverBeenUnlockedMigrator", () => {
|
|
let helper: MockProxy<MigrationHelper>;
|
|
let sut: RemoveEverBeenUnlockedMigrator;
|
|
|
|
beforeEach(() => {
|
|
helper = mockMigrationHelper(migrateExampleJSON());
|
|
sut = new RemoveEverBeenUnlockedMigrator(3, 4);
|
|
});
|
|
|
|
describe("migrate", () => {
|
|
it("should remove everBeenUnlocked from profile", async () => {
|
|
await sut.migrate(helper);
|
|
expect(helper.set).toHaveBeenCalledTimes(2);
|
|
expect(helper.set).toHaveBeenCalledWith("c493ed01-4e08-4e88-abc7-332f380ca760", {
|
|
profile: {
|
|
otherStuff: "otherStuff2",
|
|
},
|
|
otherStuff: "otherStuff3",
|
|
});
|
|
expect(helper.set).toHaveBeenCalledWith("23e61a5f-2ece-4f5e-b499-f0bc489482a9", {
|
|
profile: {
|
|
otherStuff: "otherStuff4",
|
|
},
|
|
otherStuff: "otherStuff5",
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("updateVersion", () => {
|
|
it("should update version up", async () => {
|
|
await sut.updateVersion(helper, "up");
|
|
|
|
expect(helper.set).toHaveBeenCalledTimes(1);
|
|
expect(helper.set).toHaveBeenCalledWith("global", {
|
|
stateVersion: 4,
|
|
otherStuff: "otherStuff1",
|
|
});
|
|
});
|
|
});
|
|
});
|