mirror of
https://github.com/bitwarden/browser
synced 2025-12-21 18:53:29 +00:00
* Migrate EnvironmentService * Move Migration Test Helper * Claim StateDefinition * Add State Migration * Update StateServices * Update EnvironmentService Abstraction * Update DI * Update Browser Instantiation * Fix BrowserEnvironmentService * Update Desktop & CLI Instantiation * Update Usage * Create isStringRecord helper * Fix Old Tests * Use Existing AccountService * Don't Rely on Parameter Mutation * Fix Conflicts
158 lines
3.7 KiB
TypeScript
158 lines
3.7 KiB
TypeScript
import { runMigrator } from "../migration-helper.spec";
|
|
|
|
import { MoveEnvironmentStateToProviders } from "./12-move-environment-state-to-providers";
|
|
|
|
describe("MoveEnvironmentStateToProviders", () => {
|
|
const migrator = new MoveEnvironmentStateToProviders(11, 12);
|
|
|
|
it("can migrate all data", async () => {
|
|
const output = await runMigrator(migrator, {
|
|
authenticatedAccounts: ["user1", "user2"] as const,
|
|
global: {
|
|
region: "US",
|
|
environmentUrls: {
|
|
base: "example.com",
|
|
},
|
|
extra: "data",
|
|
},
|
|
user1: {
|
|
extra: "data",
|
|
settings: {
|
|
extra: "data",
|
|
region: "US",
|
|
environmentUrls: {
|
|
base: "example.com",
|
|
},
|
|
},
|
|
},
|
|
user2: {
|
|
extra: "data",
|
|
settings: {
|
|
region: "EU",
|
|
environmentUrls: {
|
|
base: "other.example.com",
|
|
},
|
|
extra: "data",
|
|
},
|
|
},
|
|
extra: "data",
|
|
});
|
|
|
|
expect(output).toEqual({
|
|
authenticatedAccounts: ["user1", "user2"],
|
|
global: {
|
|
extra: "data",
|
|
},
|
|
global_environment_region: "US",
|
|
global_environment_urls: {
|
|
base: "example.com",
|
|
},
|
|
user1: {
|
|
extra: "data",
|
|
settings: {
|
|
extra: "data",
|
|
},
|
|
},
|
|
user2: {
|
|
extra: "data",
|
|
settings: {
|
|
extra: "data",
|
|
},
|
|
},
|
|
extra: "data",
|
|
user_user1_environment_region: "US",
|
|
user_user2_environment_region: "EU",
|
|
user_user1_environment_urls: {
|
|
base: "example.com",
|
|
},
|
|
user_user2_environment_urls: {
|
|
base: "other.example.com",
|
|
},
|
|
});
|
|
});
|
|
|
|
it("handles missing parts", async () => {
|
|
const output = await runMigrator(migrator, {
|
|
authenticatedAccounts: ["user1", "user2"],
|
|
global: {
|
|
extra: "data",
|
|
},
|
|
user1: {
|
|
extra: "data",
|
|
settings: {
|
|
extra: "data",
|
|
},
|
|
},
|
|
user2: null,
|
|
});
|
|
|
|
expect(output).toEqual({
|
|
authenticatedAccounts: ["user1", "user2"],
|
|
global: {
|
|
extra: "data",
|
|
},
|
|
user1: {
|
|
extra: "data",
|
|
settings: {
|
|
extra: "data",
|
|
},
|
|
},
|
|
user2: null,
|
|
});
|
|
});
|
|
|
|
it("can migrate only global data", async () => {
|
|
const output = await runMigrator(migrator, {
|
|
authenticatedAccounts: [] as const,
|
|
global: {
|
|
region: "Self-Hosted",
|
|
},
|
|
});
|
|
|
|
expect(output).toEqual({
|
|
authenticatedAccounts: [],
|
|
global_environment_region: "Self-Hosted",
|
|
global: {},
|
|
});
|
|
});
|
|
|
|
it("can migrate only user state", async () => {
|
|
const output = await runMigrator(migrator, {
|
|
authenticatedAccounts: ["user1"] as const,
|
|
global: null,
|
|
user1: {
|
|
settings: {
|
|
region: "Self-Hosted",
|
|
environmentUrls: {
|
|
base: "some-base-url",
|
|
api: "some-api-url",
|
|
identity: "some-identity-url",
|
|
icons: "some-icons-url",
|
|
notifications: "some-notifications-url",
|
|
events: "some-events-url",
|
|
webVault: "some-webVault-url",
|
|
keyConnector: "some-keyConnector-url",
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(output).toEqual({
|
|
authenticatedAccounts: ["user1"] as const,
|
|
global: null,
|
|
user1: { settings: {} },
|
|
user_user1_environment_region: "Self-Hosted",
|
|
user_user1_environment_urls: {
|
|
base: "some-base-url",
|
|
api: "some-api-url",
|
|
identity: "some-identity-url",
|
|
icons: "some-icons-url",
|
|
notifications: "some-notifications-url",
|
|
events: "some-events-url",
|
|
webVault: "some-webVault-url",
|
|
keyConnector: "some-keyConnector-url",
|
|
},
|
|
});
|
|
});
|
|
});
|