mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 17:23:37 +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:
@@ -1,5 +1,7 @@
|
||||
import { mock, MockProxy } from "jest-mock-extended";
|
||||
|
||||
// eslint-disable-next-line import/no-restricted-paths -- Needed client type enum
|
||||
import { ClientType } from "../enums";
|
||||
// eslint-disable-next-line import/no-restricted-paths -- Needed to print log messages
|
||||
import { LogService } from "../platform/abstractions/log.service";
|
||||
// eslint-disable-next-line import/no-restricted-paths -- Needed to interface with storage locations
|
||||
@@ -23,52 +25,56 @@ describe("migrator default methods", () => {
|
||||
let helper: MigrationHelper;
|
||||
let sut: TestMigrator;
|
||||
|
||||
beforeEach(() => {
|
||||
storage = mock();
|
||||
logService = mock();
|
||||
helper = new MigrationHelper(0, storage, logService, "general");
|
||||
sut = new TestMigrator(0, 1);
|
||||
});
|
||||
const clientTypes = Object.values(ClientType);
|
||||
|
||||
describe("shouldMigrate", () => {
|
||||
describe("up", () => {
|
||||
it("should return true if the current version equals the from version", async () => {
|
||||
expect(await sut.shouldMigrate(helper, "up")).toBe(true);
|
||||
describe.each(clientTypes)("for client %s", (clientType) => {
|
||||
beforeEach(() => {
|
||||
storage = mock();
|
||||
logService = mock();
|
||||
helper = new MigrationHelper(0, storage, logService, "general", clientType);
|
||||
sut = new TestMigrator(0, 1);
|
||||
});
|
||||
|
||||
describe("shouldMigrate", () => {
|
||||
describe("up", () => {
|
||||
it("should return true if the current version equals the from version", async () => {
|
||||
expect(await sut.shouldMigrate(helper, "up")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false if the current version does not equal the from version", async () => {
|
||||
helper.currentVersion = 1;
|
||||
expect(await sut.shouldMigrate(helper, "up")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it("should return false if the current version does not equal the from version", async () => {
|
||||
helper.currentVersion = 1;
|
||||
expect(await sut.shouldMigrate(helper, "up")).toBe(false);
|
||||
describe("down", () => {
|
||||
it("should return true if the current version equals the to version", async () => {
|
||||
helper.currentVersion = 1;
|
||||
expect(await sut.shouldMigrate(helper, "down")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false if the current version does not equal the to version", async () => {
|
||||
expect(await sut.shouldMigrate(helper, "down")).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("down", () => {
|
||||
it("should return true if the current version equals the to version", async () => {
|
||||
helper.currentVersion = 1;
|
||||
expect(await sut.shouldMigrate(helper, "down")).toBe(true);
|
||||
describe("updateVersion", () => {
|
||||
describe("up", () => {
|
||||
it("should update the version", async () => {
|
||||
await sut.updateVersion(helper, "up");
|
||||
expect(storage.save).toBeCalledWith("stateVersion", 1);
|
||||
expect(helper.currentVersion).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
it("should return false if the current version does not equal the to version", async () => {
|
||||
expect(await sut.shouldMigrate(helper, "down")).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("updateVersion", () => {
|
||||
describe("up", () => {
|
||||
it("should update the version", async () => {
|
||||
await sut.updateVersion(helper, "up");
|
||||
expect(storage.save).toBeCalledWith("stateVersion", 1);
|
||||
expect(helper.currentVersion).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("down", () => {
|
||||
it("should update the version", async () => {
|
||||
helper.currentVersion = 1;
|
||||
await sut.updateVersion(helper, "down");
|
||||
expect(storage.save).toBeCalledWith("stateVersion", 0);
|
||||
expect(helper.currentVersion).toBe(0);
|
||||
describe("down", () => {
|
||||
it("should update the version", async () => {
|
||||
helper.currentVersion = 1;
|
||||
await sut.updateVersion(helper, "down");
|
||||
expect(storage.save).toBeCalledWith("stateVersion", 0);
|
||||
expect(helper.currentVersion).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user