mirror of
https://github.com/bitwarden/browser
synced 2025-12-27 21:53:25 +00:00
* setup StateProvider in LoginService * replace implementations * replace implementation * remove stateService * change storage location for web to 'disk-local' * implement migrate() method of Migrator * add RememberedEmailMigrator to migrate.ts * add rollback * add tests * replace implementation * replace implementation * add StateProvider to Desktop services * rename LoginService to RememberEmailService * update state definition * rename file * rename to storedEmail * rename service to EmailService to avoid confusion * add jsdocs * refactor login.component.ts * fix typos * fix test * rename to LoginEmailService * update factory * more renaming * remove duplicate logic and rename method * convert storedEmail to observable * refactor to remove setStoredEmail() method * move service to libs/auth/common * address floating promises * remove comment * remove unnecessary deps in service registration
82 lines
2.3 KiB
TypeScript
82 lines
2.3 KiB
TypeScript
import { MockProxy } from "jest-mock-extended";
|
|
|
|
import { MigrationHelper } from "../migration-helper";
|
|
import { mockMigrationHelper, runMigrator } from "../migration-helper.spec";
|
|
|
|
import { RememberedEmailMigrator } from "./51-move-remembered-email-to-state-providers";
|
|
|
|
function rollbackJSON() {
|
|
return {
|
|
global: {
|
|
extra: "data",
|
|
},
|
|
global_loginEmail_storedEmail: "user@example.com",
|
|
};
|
|
}
|
|
|
|
describe("RememberedEmailMigrator", () => {
|
|
const migrator = new RememberedEmailMigrator(50, 51);
|
|
|
|
describe("migrate", () => {
|
|
it("should migrate the rememberedEmail property from the legacy global object to a global StorageKey as 'global_loginEmail_storedEmail'", async () => {
|
|
const output = await runMigrator(migrator, {
|
|
global: {
|
|
rememberedEmail: "user@example.com",
|
|
extra: "data", // Represents a global property that should persist after migration
|
|
},
|
|
});
|
|
|
|
expect(output).toEqual({
|
|
global: {
|
|
extra: "data",
|
|
},
|
|
global_loginEmail_storedEmail: "user@example.com",
|
|
});
|
|
});
|
|
|
|
it("should remove the rememberedEmail property from the legacy global object", async () => {
|
|
const output = await runMigrator(migrator, {
|
|
global: {
|
|
rememberedEmail: "user@example.com",
|
|
},
|
|
});
|
|
|
|
expect(output.global).not.toHaveProperty("rememberedEmail");
|
|
});
|
|
});
|
|
|
|
describe("rollback", () => {
|
|
let helper: MockProxy<MigrationHelper>;
|
|
let sut: RememberedEmailMigrator;
|
|
|
|
const keyDefinitionLike = {
|
|
key: "storedEmail",
|
|
stateDefinition: {
|
|
name: "loginEmail",
|
|
},
|
|
};
|
|
|
|
beforeEach(() => {
|
|
helper = mockMigrationHelper(rollbackJSON(), 51);
|
|
sut = new RememberedEmailMigrator(50, 51);
|
|
});
|
|
|
|
it("should null out the storedEmail global StorageKey", async () => {
|
|
await sut.rollback(helper);
|
|
|
|
expect(helper.setToGlobal).toHaveBeenCalledTimes(1);
|
|
expect(helper.setToGlobal).toHaveBeenCalledWith(keyDefinitionLike, null);
|
|
});
|
|
|
|
it("should add the rememberedEmail property back to legacy global object", async () => {
|
|
await sut.rollback(helper);
|
|
|
|
expect(helper.set).toHaveBeenCalledTimes(1);
|
|
expect(helper.set).toHaveBeenCalledWith("global", {
|
|
rememberedEmail: "user@example.com",
|
|
extra: "data",
|
|
});
|
|
});
|
|
});
|
|
});
|