mirror of
https://github.com/bitwarden/browser
synced 2025-12-06 00:13:28 +00:00
* Added billing account profile state service
* Update usages after removing state service functions
* Added migrator
* Updated bw.ts and main.background.ts
* Removed comment
* Updated state service dependencies to include billing service
* Added missing mv3 factory and updated MainContextMenuHandler
* updated autofill service and tests
* Updated the remaining extensions usages
* Updated desktop
* Removed subjects where they weren't needed
* Refactored billing service to have a single setter to avoid unecessary emissions
* Refactored has premium guard to return an observable
* Renamed services to match ADR
f633f2cdd8/docs/architecture/clients/presentation/angular.md (abstract--default-implementations)
* Updated property names to be a smidgen more descriptive and added jsdocs
* Updated setting of canAccessPremium to automatically update when the underlying observable emits
* Fixed build error after merge conflicts
* Another build error from conflict
* Removed autofill unit test changes from conflict
* Updated login strategy to not set premium field using state service
* Updated CLI to use billing state provider
* Shortened names a bit
* Fixed build
127 lines
3.2 KiB
TypeScript
127 lines
3.2 KiB
TypeScript
import { MockProxy, any } from "jest-mock-extended";
|
|
|
|
import { MigrationHelper } from "../migration-helper";
|
|
import { mockMigrationHelper } from "../migration-helper.spec";
|
|
|
|
import {
|
|
BILLING_ACCOUNT_PROFILE_KEY_DEFINITION,
|
|
MoveBillingAccountProfileMigrator,
|
|
} from "./39-move-billing-account-profile-to-state-providers";
|
|
|
|
const exampleJSON = () => ({
|
|
global: {
|
|
otherStuff: "otherStuff1",
|
|
},
|
|
authenticatedAccounts: ["user-1", "user-2", "user-3"],
|
|
"user-1": {
|
|
profile: {
|
|
hasPremiumPersonally: true,
|
|
hasPremiumFromOrganization: false,
|
|
otherStuff: "otherStuff2",
|
|
},
|
|
otherStuff: "otherStuff3",
|
|
},
|
|
"user-2": {
|
|
otherStuff: "otherStuff4",
|
|
},
|
|
});
|
|
|
|
const rollbackJSON = () => ({
|
|
"user_user-1_billing_accountProfile": {
|
|
hasPremiumPersonally: true,
|
|
hasPremiumFromOrganization: false,
|
|
},
|
|
global: {
|
|
otherStuff: "otherStuff1",
|
|
},
|
|
authenticatedAccounts: ["user-1", "user-2", "user-3"],
|
|
"user-1": {
|
|
profile: {
|
|
otherStuff: "otherStuff2",
|
|
},
|
|
otherStuff: "otherStuff3",
|
|
},
|
|
"user-2": {
|
|
otherStuff: "otherStuff4",
|
|
},
|
|
});
|
|
|
|
describe("MoveBillingAccountProfileToStateProviders migrator", () => {
|
|
let helper: MockProxy<MigrationHelper>;
|
|
let sut: MoveBillingAccountProfileMigrator;
|
|
|
|
describe("migrate", () => {
|
|
beforeEach(() => {
|
|
helper = mockMigrationHelper(exampleJSON(), 39);
|
|
sut = new MoveBillingAccountProfileMigrator(38, 39);
|
|
});
|
|
|
|
it("removes from all accounts", async () => {
|
|
await sut.migrate(helper);
|
|
expect(helper.set).toHaveBeenCalledTimes(1);
|
|
expect(helper.set).toHaveBeenCalledWith("user-1", {
|
|
profile: {
|
|
otherStuff: "otherStuff2",
|
|
},
|
|
otherStuff: "otherStuff3",
|
|
});
|
|
});
|
|
|
|
it("sets hasPremiumPersonally value for account that have it", async () => {
|
|
await sut.migrate(helper);
|
|
|
|
expect(helper.setToUser).toHaveBeenCalledWith(
|
|
"user-1",
|
|
BILLING_ACCOUNT_PROFILE_KEY_DEFINITION,
|
|
{ hasPremiumFromOrganization: false, hasPremiumPersonally: true },
|
|
);
|
|
});
|
|
|
|
it("should not call extra setToUser", async () => {
|
|
await sut.migrate(helper);
|
|
|
|
expect(helper.setToUser).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|
|
|
|
describe("rollback", () => {
|
|
beforeEach(() => {
|
|
helper = mockMigrationHelper(rollbackJSON(), 39);
|
|
sut = new MoveBillingAccountProfileMigrator(38, 39);
|
|
});
|
|
|
|
it("nulls out new values", async () => {
|
|
await sut.rollback(helper);
|
|
|
|
expect(helper.setToUser).toHaveBeenCalledWith(
|
|
"user-1",
|
|
BILLING_ACCOUNT_PROFILE_KEY_DEFINITION,
|
|
null,
|
|
);
|
|
});
|
|
|
|
it("adds explicit value back to accounts", async () => {
|
|
await sut.rollback(helper);
|
|
|
|
expect(helper.set).toHaveBeenCalledTimes(1);
|
|
expect(helper.set).toHaveBeenCalledWith("user-1", {
|
|
profile: {
|
|
hasPremiumPersonally: true,
|
|
hasPremiumFromOrganization: false,
|
|
otherStuff: "otherStuff2",
|
|
},
|
|
otherStuff: "otherStuff3",
|
|
});
|
|
});
|
|
|
|
it.each(["user-2", "user-3"])(
|
|
"does not restore values when accounts are not present",
|
|
async (userId) => {
|
|
await sut.rollback(helper);
|
|
|
|
expect(helper.set).not.toHaveBeenCalledWith(userId, any());
|
|
},
|
|
);
|
|
});
|
|
});
|