mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 05:13:29 +00:00
[PM-14366] Deprecated active user state from billing state service (#12273)
* Updated billing state provider to not rely on ActiveUserStateProvider * Updated usages * Resolved browser build * Resolved web build * Resolved CLI build * resolved desktop build * Update apps/cli/src/tools/send/commands/create.command.ts Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com> * Move subscription visibility logic from component to service * Resolved unit test failures. Using existing userIds where present * Simplified activeUserId access * Resolved typescript strict errors * Resolved broken unit test * Resolved ts strict error --------- Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import { Router, RouterLink } from "@angular/router";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions";
|
||||
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
|
||||
import { BadgeModule, ButtonModule, MenuModule } from "@bitwarden/components";
|
||||
@@ -24,11 +25,18 @@ export class NewSendDropdownComponent implements OnInit {
|
||||
constructor(
|
||||
private router: Router,
|
||||
private billingAccountProfileStateService: BillingAccountProfileStateService,
|
||||
private accountService: AccountService,
|
||||
) {}
|
||||
|
||||
async ngOnInit() {
|
||||
const account = await firstValueFrom(this.accountService.activeAccount$);
|
||||
if (!account) {
|
||||
this.hasNoPremium = true;
|
||||
return;
|
||||
}
|
||||
|
||||
this.hasNoPremium = !(await firstValueFrom(
|
||||
this.billingAccountProfileStateService.hasPremiumFromAnySource$,
|
||||
this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,10 @@ import { mock, MockProxy } from "jest-mock-extended";
|
||||
import { of } from "rxjs";
|
||||
|
||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { ChipSelectComponent } from "@bitwarden/components";
|
||||
|
||||
import { SendListFiltersService } from "../services/send-list-filters.service";
|
||||
@@ -18,13 +20,22 @@ describe("SendListFiltersComponent", () => {
|
||||
let fixture: ComponentFixture<SendListFiltersComponent>;
|
||||
let sendListFiltersService: SendListFiltersService;
|
||||
let billingAccountProfileStateService: MockProxy<BillingAccountProfileStateService>;
|
||||
let accountService: MockProxy<AccountService>;
|
||||
const userId = "userId" as UserId;
|
||||
|
||||
beforeEach(async () => {
|
||||
sendListFiltersService = new SendListFiltersService(mock(), new FormBuilder());
|
||||
sendListFiltersService.resetFilterForm = jest.fn();
|
||||
billingAccountProfileStateService = mock<BillingAccountProfileStateService>();
|
||||
accountService = mock<AccountService>();
|
||||
|
||||
billingAccountProfileStateService.hasPremiumFromAnySource$ = of(true);
|
||||
accountService.activeAccount$ = of({
|
||||
id: userId,
|
||||
email: "test@email.com",
|
||||
emailVerified: true,
|
||||
name: "Test User",
|
||||
});
|
||||
billingAccountProfileStateService.hasPremiumFromAnySource$.mockReturnValue(of(true));
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [
|
||||
@@ -37,10 +48,8 @@ describe("SendListFiltersComponent", () => {
|
||||
providers: [
|
||||
{ provide: I18nService, useValue: { t: (key: string) => key } },
|
||||
{ provide: SendListFiltersService, useValue: sendListFiltersService },
|
||||
{
|
||||
provide: BillingAccountProfileStateService,
|
||||
useValue: billingAccountProfileStateService,
|
||||
},
|
||||
{ provide: BillingAccountProfileStateService, useValue: billingAccountProfileStateService },
|
||||
{ provide: AccountService, useValue: accountService },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
@@ -57,6 +66,7 @@ describe("SendListFiltersComponent", () => {
|
||||
let canAccessPremium: boolean | undefined;
|
||||
component["canAccessPremium$"].subscribe((value) => (canAccessPremium = value));
|
||||
expect(canAccessPremium).toBe(true);
|
||||
expect(billingAccountProfileStateService.hasPremiumFromAnySource$).toHaveBeenCalledWith(userId);
|
||||
});
|
||||
|
||||
it("should call resetFilterForm on ngOnDestroy", () => {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { Component, OnDestroy } from "@angular/core";
|
||||
import { ReactiveFormsModule } from "@angular/forms";
|
||||
import { Observable } from "rxjs";
|
||||
import { Observable, of, switchMap } from "rxjs";
|
||||
|
||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
||||
import { ChipSelectComponent } from "@bitwarden/components";
|
||||
|
||||
import { SendListFiltersService } from "../services/send-list-filters.service";
|
||||
@@ -23,8 +24,15 @@ export class SendListFiltersComponent implements OnDestroy {
|
||||
constructor(
|
||||
private sendListFiltersService: SendListFiltersService,
|
||||
billingAccountProfileStateService: BillingAccountProfileStateService,
|
||||
accountService: AccountService,
|
||||
) {
|
||||
this.canAccessPremium$ = billingAccountProfileStateService.hasPremiumFromAnySource$;
|
||||
this.canAccessPremium$ = accountService.activeAccount$.pipe(
|
||||
switchMap((account) =>
|
||||
account
|
||||
? billingAccountProfileStateService.hasPremiumFromAnySource$(account.id)
|
||||
: of(false),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
|
||||
Reference in New Issue
Block a user