1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

[PM-7766] Add clientType to MigrationHelper (#8945)

* Add `clientType` to MigrationHelper

* PM-7766 - Fix migration builder tests to take new clientType into account.

Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>

* PM-7766 - Add client type to migration builder tests.

* PM-7766 - Fix migration-helper.spec tests.

* PM-7766 - Fix migrator.spec.ts

---------

Co-authored-by: Jared Snider <jsnider@bitwarden.com>
This commit is contained in:
Justin Baur
2024-04-29 07:28:58 -04:00
committed by GitHub
parent 42f1f965af
commit 3caa6cb635
17 changed files with 295 additions and 210 deletions

View File

@@ -1,6 +1,7 @@
import { mock } from "jest-mock-extended";
import { FakeStorageService } from "../../../spec/fake-storage.service";
import { ClientType } from "../../enums";
import { MigrationHelper } from "../../state-migrations/migration-helper";
import { MigrationBuilderService } from "./migration-builder.service";
@@ -66,25 +67,38 @@ describe("MigrationBuilderService", () => {
global: {},
};
it.each([
noAccounts,
nullAndUndefinedAccounts,
emptyAccountObject,
nullCommonAccountProperties,
emptyCommonAccountProperties,
nullGlobal,
undefinedGlobal,
emptyGlobalObject,
])("should not produce migrations that throw when given data: %s", async (startingState) => {
const sut = new MigrationBuilderService();
const startingStates = [
{ data: noAccounts, description: "No Accounts" },
{ data: nullAndUndefinedAccounts, description: "Null and Undefined Accounts" },
{ data: emptyAccountObject, description: "Empty Account Object" },
{ data: nullCommonAccountProperties, description: "Null Common Account Properties" },
{ data: emptyCommonAccountProperties, description: "Empty Common Account Properties" },
{ data: nullGlobal, description: "Null Global" },
{ data: undefinedGlobal, description: "Undefined Global" },
{ data: emptyGlobalObject, description: "Empty Global Object" },
];
const helper = new MigrationHelper(
startingStateVersion,
new FakeStorageService(startingState),
mock(),
"general",
);
const clientTypes = Object.values(ClientType);
await sut.build().migrate(helper);
});
// Generate all possible test cases
const testCases = startingStates.flatMap((startingState) =>
clientTypes.map((clientType) => ({ startingState, clientType })),
);
it.each(testCases)(
"should not produce migrations that throw when given $startingState.description for client $clientType",
async ({ startingState, clientType }) => {
const sut = new MigrationBuilderService();
const helper = new MigrationHelper(
startingStateVersion,
new FakeStorageService(startingState),
mock(),
"general",
clientType,
);
await sut.build().migrate(helper);
},
);
});

View File

@@ -1,6 +1,7 @@
import { mock } from "jest-mock-extended";
import { awaitAsync } from "../../../spec";
import { ClientType } from "../../enums";
import { CURRENT_VERSION } from "../../state-migrations";
import { MigrationBuilder } from "../../state-migrations/migration-builder";
import { LogService } from "../abstractions/log.service";
@@ -17,7 +18,7 @@ describe("MigrationRunner", () => {
migrationBuilderService.build.mockReturnValue(mockMigrationBuilder);
const sut = new MigrationRunner(storage, logService, migrationBuilderService);
const sut = new MigrationRunner(storage, logService, migrationBuilderService, ClientType.Web);
describe("migrate", () => {
it("should not run migrations if state is empty", async () => {

View File

@@ -1,3 +1,4 @@
import { ClientType } from "../../enums";
import { waitForMigrations } from "../../state-migrations";
import { CURRENT_VERSION, currentVersion } from "../../state-migrations/migrate";
import { MigrationHelper } from "../../state-migrations/migration-helper";
@@ -11,6 +12,7 @@ export class MigrationRunner {
protected diskStorage: AbstractStorageService,
protected logService: LogService,
protected migrationBuilderService: MigrationBuilderService,
private clientType: ClientType,
) {}
async run(): Promise<void> {
@@ -19,6 +21,7 @@ export class MigrationRunner {
this.diskStorage,
this.logService,
"general",
this.clientType,
);
if (migrationHelper.currentVersion < 0) {