mirror of
https://github.com/bitwarden/browser
synced 2026-02-26 01:23:24 +00:00
* refactor: introduce @bitwarden/serialization * refactor: introduce @bitwarden/guid * refactor: introduce @bitwaren/client-type * refactor: introduce @bitwarden/core-test-utils * refactor: introduce @bitwarden/state and @bitwarden/state-test-utils Creates initial project structure for centralized application state management. Part of modularization effort to extract state code from common. * Added state provider documentation to README. * Changed callouts to Github format. * Fixed linting on file name. * Forced git to accept rename --------- Co-authored-by: Todd Martin <tmartin@bitwarden.com>
106 lines
3.0 KiB
TypeScript
106 lines
3.0 KiB
TypeScript
import { mock } from "jest-mock-extended";
|
|
|
|
import { MigrationHelper } from "@bitwarden/state";
|
|
|
|
import { FakeStorageService } from "../../../spec/fake-storage.service";
|
|
import { ClientType } from "../../enums";
|
|
|
|
import { MigrationBuilderService } from "./migration-builder.service";
|
|
|
|
describe("MigrationBuilderService", () => {
|
|
// All migrations from 10+ should be capable of having a null account object or null global object
|
|
const startingStateVersion = 10;
|
|
|
|
const noAccounts = {
|
|
stateVersion: startingStateVersion,
|
|
authenticatedAccounts: <string[]>[],
|
|
};
|
|
|
|
const nullAndUndefinedAccounts = {
|
|
stateVersion: startingStateVersion,
|
|
authenticatedAccounts: ["account1", "account2"],
|
|
account1: <object>null,
|
|
account2: <object>undefined,
|
|
};
|
|
|
|
const emptyAccountObject = {
|
|
stateVersion: startingStateVersion,
|
|
authenticatedAccounts: ["account1"],
|
|
account1: {},
|
|
};
|
|
|
|
const nullCommonAccountProperties = {
|
|
stateVersion: startingStateVersion,
|
|
authenticatedAccounts: ["account1"],
|
|
account1: {
|
|
data: <object>null,
|
|
keys: <object>null,
|
|
profile: <object>null,
|
|
settings: <object>null,
|
|
tokens: <object>null,
|
|
},
|
|
};
|
|
|
|
const emptyCommonAccountProperties = {
|
|
stateVersion: startingStateVersion,
|
|
authenticatedAccounts: ["account1"],
|
|
account1: {
|
|
data: {},
|
|
keys: {},
|
|
profile: {},
|
|
settings: {},
|
|
tokens: {},
|
|
},
|
|
};
|
|
|
|
const nullGlobal = {
|
|
stateVersion: startingStateVersion,
|
|
global: <object>null,
|
|
};
|
|
|
|
const undefinedGlobal = {
|
|
stateVersion: startingStateVersion,
|
|
global: <object>undefined,
|
|
};
|
|
|
|
const emptyGlobalObject = {
|
|
stateVersion: startingStateVersion,
|
|
global: {},
|
|
};
|
|
|
|
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 clientTypes = Object.values(ClientType);
|
|
|
|
// 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);
|
|
},
|
|
);
|
|
});
|