1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-28 04:08:47 +02:00
bitwarden-browser/libs/common/src/state-migrations/migrations/43-move-auto-confirm-finger-prints-to-state-provider.spec.ts
Addison Beck bf2d2cfbed
Migrate autoConfirmFingerPrints to StateProvider (#8337)
* Fix a typo in the `StateDefinition` description

* Introduce `OrganizationManagementPreferencesService`

* Declare `OrganizationManagementPreferencesService` in DI

* Update `autoConfirmFingerPrints` logic in emergency access files

* Update `autoConfirmFingerPrints` logic in `people` files

* Remove `autoConfirmFingerPrints` from `StateService` and `Account`

* Migrate existing client data for `autoConfirmFingerPrints`

* Update apps/web/src/app/admin-console/organizations/manage/user-confirm.component.ts

Co-authored-by: Matt Gibson <mgibson@bitwarden.com>

* Update apps/web/src/app/admin-console/organizations/manage/user-confirm.component.ts

Co-authored-by: Matt Gibson <mgibson@bitwarden.com>

* Use `set` instead of `update` for function names

---------

Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
2024-03-19 17:37:35 -04:00

103 lines
2.8 KiB
TypeScript

import { MockProxy } from "jest-mock-extended";
import { MigrationHelper } from "../migration-helper";
import { mockMigrationHelper, runMigrator } from "../migration-helper.spec";
import { AutoConfirmFingerPrintsMigrator } from "./43-move-auto-confirm-finger-prints-to-state-provider";
function rollbackJSON() {
return {
authenticatedAccounts: ["user-1", "user-2"],
"user_user-1_organizationManagementPreferences_autoConfirmFingerPrints": true,
"user_user-2_organizationManagementPreferences_autoConfirmFingerPrints": false,
"user-1": {
settings: {
extra: "data",
},
extra: "data",
},
"user-2": {
settings: {
extra: "data",
},
extra: "data",
},
};
}
describe("AutoConfirmFingerPrintsMigrator", () => {
const migrator = new AutoConfirmFingerPrintsMigrator(42, 43);
it("should migrate the autoConfirmFingerPrints property from the account settings object to a user StorageKey", async () => {
const output = await runMigrator(migrator, {
authenticatedAccounts: ["user-1", "user-2"] as const,
"user-1": {
settings: {
autoConfirmFingerPrints: true,
extra: "data",
},
extra: "data",
},
"user-2": {
settings: {
autoConfirmFingerPrints: false,
extra: "data",
},
extra: "data",
},
});
expect(output).toEqual({
authenticatedAccounts: ["user-1", "user-2"],
"user_user-1_organizationManagementPreferences_autoConfirmFingerPrints": true,
"user_user-2_organizationManagementPreferences_autoConfirmFingerPrints": false,
"user-1": {
settings: {
extra: "data",
},
extra: "data",
},
"user-2": {
settings: {
extra: "data",
},
extra: "data",
},
});
});
describe("rollback", () => {
let helper: MockProxy<MigrationHelper>;
let sut: AutoConfirmFingerPrintsMigrator;
const keyDefinitionLike = {
key: "autoConfirmFingerPrints",
stateDefinition: {
name: "organizationManagementPreferences",
},
};
beforeEach(() => {
helper = mockMigrationHelper(rollbackJSON(), 43);
sut = new AutoConfirmFingerPrintsMigrator(42, 43);
});
it("should null the autoConfirmFingerPrints user StorageKey for each account", async () => {
await sut.rollback(helper);
expect(helper.setToUser).toHaveBeenCalledWith("user-1", keyDefinitionLike, null);
});
it("should add the autoConfirmFingerPrints property back to the account settings object", async () => {
await sut.rollback(helper);
expect(helper.set).toHaveBeenCalledWith("user-1", {
settings: {
autoConfirmFingerPrints: true,
extra: "data",
},
extra: "data",
});
});
});
});