mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
[PM-5571] Migrate enableDDG to state provider framework (#8384)
Migrate enableDuckDuckGo to state provider framework.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { runMigrator } from "../migration-helper.spec";
|
||||
|
||||
import { MoveDdgToStateProviderMigrator } from "./48-move-ddg-to-state-provider";
|
||||
|
||||
describe("MoveDdgToStateProviderMigrator", () => {
|
||||
const migrator = new MoveDdgToStateProviderMigrator(47, 48);
|
||||
|
||||
it("migrate", async () => {
|
||||
const output = await runMigrator(migrator, {
|
||||
global: {
|
||||
enableDuckDuckGoBrowserIntegration: true,
|
||||
otherStuff: "otherStuff1",
|
||||
},
|
||||
otherStuff: "otherStuff2",
|
||||
});
|
||||
|
||||
expect(output).toEqual({
|
||||
global_autofillSettings_enableDuckDuckGoBrowserIntegration: true,
|
||||
global: {
|
||||
otherStuff: "otherStuff1",
|
||||
},
|
||||
otherStuff: "otherStuff2",
|
||||
});
|
||||
});
|
||||
|
||||
it("rollback", async () => {
|
||||
const output = await runMigrator(
|
||||
migrator,
|
||||
{
|
||||
global_autofillSettings_enableDuckDuckGoBrowserIntegration: true,
|
||||
global: {
|
||||
otherStuff: "otherStuff1",
|
||||
},
|
||||
otherStuff: "otherStuff2",
|
||||
},
|
||||
"rollback",
|
||||
);
|
||||
|
||||
expect(output).toEqual({
|
||||
global: {
|
||||
enableDuckDuckGoBrowserIntegration: true,
|
||||
otherStuff: "otherStuff1",
|
||||
},
|
||||
otherStuff: "otherStuff2",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import { KeyDefinitionLike, MigrationHelper } from "../migration-helper";
|
||||
import { Migrator } from "../migrator";
|
||||
|
||||
type ExpectedGlobal = {
|
||||
enableDuckDuckGoBrowserIntegration?: boolean;
|
||||
};
|
||||
|
||||
export const DDG_KEY: KeyDefinitionLike = {
|
||||
key: "enableDuckDuckGoBrowserIntegration",
|
||||
stateDefinition: {
|
||||
name: "autofillSettings",
|
||||
},
|
||||
};
|
||||
|
||||
export class MoveDdgToStateProviderMigrator extends Migrator<47, 48> {
|
||||
async migrate(helper: MigrationHelper): Promise<void> {
|
||||
// global state
|
||||
const global = await helper.get<ExpectedGlobal>("global");
|
||||
if (global?.enableDuckDuckGoBrowserIntegration == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
await helper.setToGlobal(DDG_KEY, global.enableDuckDuckGoBrowserIntegration);
|
||||
delete global.enableDuckDuckGoBrowserIntegration;
|
||||
await helper.set("global", global);
|
||||
}
|
||||
|
||||
async rollback(helper: MigrationHelper): Promise<void> {
|
||||
const enableDdg = await helper.getFromGlobal<boolean>(DDG_KEY);
|
||||
|
||||
if (!enableDdg) {
|
||||
return;
|
||||
}
|
||||
|
||||
const global = (await helper.get<ExpectedGlobal>("global")) ?? {};
|
||||
global.enableDuckDuckGoBrowserIntegration = enableDdg;
|
||||
await helper.set("global", global);
|
||||
await helper.removeFromGlobal(DDG_KEY);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user