mirror of
https://github.com/bitwarden/browser
synced 2026-01-06 02:23:44 +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
166 lines
5.8 KiB
TypeScript
166 lines
5.8 KiB
TypeScript
import { firstValueFrom } from "rxjs";
|
|
|
|
import {
|
|
FakeAccountService,
|
|
FakeActiveUserStateProvider,
|
|
mockAccountServiceWith,
|
|
FakeActiveUserState,
|
|
trackEmissions,
|
|
} from "../../../../spec";
|
|
import { UserId } from "../../../types/guid";
|
|
import { BillingAccountProfile } from "../../abstractions/account/billing-account-profile-state.service";
|
|
|
|
import {
|
|
BILLING_ACCOUNT_PROFILE_KEY_DEFINITION,
|
|
DefaultBillingAccountProfileStateService,
|
|
} from "./billing-account-profile-state.service";
|
|
|
|
describe("BillingAccountProfileStateService", () => {
|
|
let activeUserStateProvider: FakeActiveUserStateProvider;
|
|
let sut: DefaultBillingAccountProfileStateService;
|
|
let billingAccountProfileState: FakeActiveUserState<BillingAccountProfile>;
|
|
let accountService: FakeAccountService;
|
|
|
|
const userId = "fakeUserId" as UserId;
|
|
|
|
beforeEach(() => {
|
|
accountService = mockAccountServiceWith(userId);
|
|
activeUserStateProvider = new FakeActiveUserStateProvider(accountService);
|
|
|
|
sut = new DefaultBillingAccountProfileStateService(activeUserStateProvider);
|
|
|
|
billingAccountProfileState = activeUserStateProvider.getFake(
|
|
BILLING_ACCOUNT_PROFILE_KEY_DEFINITION,
|
|
);
|
|
});
|
|
|
|
afterEach(() => {
|
|
return jest.resetAllMocks();
|
|
});
|
|
|
|
describe("accountHasPremiumFromAnyOrganization$", () => {
|
|
it("should emit changes in hasPremiumFromAnyOrganization", async () => {
|
|
billingAccountProfileState.nextState({
|
|
hasPremiumPersonally: false,
|
|
hasPremiumFromAnyOrganization: true,
|
|
});
|
|
|
|
expect(await firstValueFrom(sut.hasPremiumFromAnyOrganization$)).toBe(true);
|
|
});
|
|
|
|
it("should emit once when calling setHasPremium once", async () => {
|
|
const emissions = trackEmissions(sut.hasPremiumFromAnyOrganization$);
|
|
const startingEmissionCount = emissions.length;
|
|
|
|
await sut.setHasPremium(true, true);
|
|
|
|
const endingEmissionCount = emissions.length;
|
|
expect(endingEmissionCount - startingEmissionCount).toBe(1);
|
|
});
|
|
});
|
|
|
|
describe("hasPremiumPersonally$", () => {
|
|
it("should emit changes in hasPremiumPersonally", async () => {
|
|
billingAccountProfileState.nextState({
|
|
hasPremiumPersonally: true,
|
|
hasPremiumFromAnyOrganization: false,
|
|
});
|
|
|
|
expect(await firstValueFrom(sut.hasPremiumPersonally$)).toBe(true);
|
|
});
|
|
|
|
it("should emit once when calling setHasPremium once", async () => {
|
|
const emissions = trackEmissions(sut.hasPremiumPersonally$);
|
|
const startingEmissionCount = emissions.length;
|
|
|
|
await sut.setHasPremium(true, true);
|
|
|
|
const endingEmissionCount = emissions.length;
|
|
expect(endingEmissionCount - startingEmissionCount).toBe(1);
|
|
});
|
|
});
|
|
|
|
describe("canAccessPremium$", () => {
|
|
it("should emit changes in hasPremiumPersonally", async () => {
|
|
billingAccountProfileState.nextState({
|
|
hasPremiumPersonally: true,
|
|
hasPremiumFromAnyOrganization: false,
|
|
});
|
|
|
|
expect(await firstValueFrom(sut.hasPremiumFromAnySource$)).toBe(true);
|
|
});
|
|
|
|
it("should emit changes in hasPremiumFromAnyOrganization", async () => {
|
|
billingAccountProfileState.nextState({
|
|
hasPremiumPersonally: false,
|
|
hasPremiumFromAnyOrganization: true,
|
|
});
|
|
|
|
expect(await firstValueFrom(sut.hasPremiumFromAnySource$)).toBe(true);
|
|
});
|
|
|
|
it("should emit changes in both hasPremiumPersonally and hasPremiumFromAnyOrganization", async () => {
|
|
billingAccountProfileState.nextState({
|
|
hasPremiumPersonally: true,
|
|
hasPremiumFromAnyOrganization: true,
|
|
});
|
|
|
|
expect(await firstValueFrom(sut.hasPremiumFromAnySource$)).toBe(true);
|
|
});
|
|
|
|
it("should emit once when calling setHasPremium once", async () => {
|
|
const emissions = trackEmissions(sut.hasPremiumFromAnySource$);
|
|
const startingEmissionCount = emissions.length;
|
|
|
|
await sut.setHasPremium(true, true);
|
|
|
|
const endingEmissionCount = emissions.length;
|
|
expect(endingEmissionCount - startingEmissionCount).toBe(1);
|
|
});
|
|
});
|
|
|
|
describe("setHasPremium", () => {
|
|
it("should have `hasPremiumPersonally$` emit `true` when passing `true` as an argument for hasPremiumPersonally", async () => {
|
|
await sut.setHasPremium(true, false);
|
|
|
|
expect(await firstValueFrom(sut.hasPremiumPersonally$)).toBe(true);
|
|
});
|
|
|
|
it("should have `hasPremiumFromAnyOrganization$` emit `true` when passing `true` as an argument for hasPremiumFromAnyOrganization", async () => {
|
|
await sut.setHasPremium(false, true);
|
|
|
|
expect(await firstValueFrom(sut.hasPremiumFromAnyOrganization$)).toBe(true);
|
|
});
|
|
|
|
it("should have `hasPremiumPersonally$` emit `false` when passing `false` as an argument for hasPremiumPersonally", async () => {
|
|
await sut.setHasPremium(false, false);
|
|
|
|
expect(await firstValueFrom(sut.hasPremiumPersonally$)).toBe(false);
|
|
});
|
|
|
|
it("should have `hasPremiumFromAnyOrganization$` emit `false` when passing `false` as an argument for hasPremiumFromAnyOrganization", async () => {
|
|
await sut.setHasPremium(false, false);
|
|
|
|
expect(await firstValueFrom(sut.hasPremiumFromAnyOrganization$)).toBe(false);
|
|
});
|
|
|
|
it("should have `canAccessPremium$` emit `true` when passing `true` as an argument for hasPremiumPersonally", async () => {
|
|
await sut.setHasPremium(true, false);
|
|
|
|
expect(await firstValueFrom(sut.hasPremiumFromAnySource$)).toBe(true);
|
|
});
|
|
|
|
it("should have `canAccessPremium$` emit `true` when passing `true` as an argument for hasPremiumFromAnyOrganization", async () => {
|
|
await sut.setHasPremium(false, true);
|
|
|
|
expect(await firstValueFrom(sut.hasPremiumFromAnySource$)).toBe(true);
|
|
});
|
|
|
|
it("should have `canAccessPremium$` emit `false` when passing `false` for all arguments", async () => {
|
|
await sut.setHasPremium(false, false);
|
|
|
|
expect(await firstValueFrom(sut.hasPremiumFromAnySource$)).toBe(false);
|
|
});
|
|
});
|
|
});
|