1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 06:13:38 +00:00

Update marketing route for organizations when in cloud (#13123)

This commit is contained in:
Alex Morask
2025-02-06 08:54:23 -05:00
committed by GitHub
parent 5da7d934cc
commit 6a94b4d0ef
2 changed files with 39 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ import { ProviderService } from "@bitwarden/common/admin-console/abstractions/pr
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization"; import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { Provider } from "@bitwarden/common/admin-console/models/domain/provider"; import { Provider } from "@bitwarden/common/admin-console/models/domain/provider";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { Utils } from "@bitwarden/common/platform/misc/utils"; import { Utils } from "@bitwarden/common/platform/misc/utils";
import { SyncService } from "@bitwarden/common/platform/sync"; import { SyncService } from "@bitwarden/common/platform/sync";
import { FakeAccountService, mockAccountServiceWith } from "@bitwarden/common/spec"; import { FakeAccountService, mockAccountServiceWith } from "@bitwarden/common/spec";
@@ -24,6 +25,7 @@ describe("ProductSwitcherService", () => {
let organizationService: MockProxy<OrganizationService>; let organizationService: MockProxy<OrganizationService>;
let providerService: MockProxy<ProviderService>; let providerService: MockProxy<ProviderService>;
let accountService: FakeAccountService; let accountService: FakeAccountService;
let platformUtilsService: MockProxy<PlatformUtilsService>;
let activeRouteParams = convertToParamMap({ organizationId: "1234" }); let activeRouteParams = convertToParamMap({ organizationId: "1234" });
const getLastSync = jest.fn().mockResolvedValue(new Date("2024-05-14")); const getLastSync = jest.fn().mockResolvedValue(new Date("2024-05-14"));
const userId = Utils.newGuid() as UserId; const userId = Utils.newGuid() as UserId;
@@ -43,11 +45,13 @@ describe("ProductSwitcherService", () => {
organizationService = mock<OrganizationService>(); organizationService = mock<OrganizationService>();
providerService = mock<ProviderService>(); providerService = mock<ProviderService>();
accountService = mockAccountServiceWith(userId); accountService = mockAccountServiceWith(userId);
platformUtilsService = mock<PlatformUtilsService>();
router.url = "/"; router.url = "/";
router.events = of({}); router.events = of({});
organizationService.organizations$.mockReturnValue(of([{}] as Organization[])); organizationService.organizations$.mockReturnValue(of([{}] as Organization[]));
providerService.getAll.mockResolvedValue([] as Provider[]); providerService.getAll.mockResolvedValue([] as Provider[]);
platformUtilsService.isSelfHost.mockReturnValue(false);
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers: [ providers: [
@@ -55,6 +59,7 @@ describe("ProductSwitcherService", () => {
{ provide: OrganizationService, useValue: organizationService }, { provide: OrganizationService, useValue: organizationService },
{ provide: ProviderService, useValue: providerService }, { provide: ProviderService, useValue: providerService },
{ provide: AccountService, useValue: accountService }, { provide: AccountService, useValue: accountService },
{ provide: PlatformUtilsService, useValue: platformUtilsService },
{ {
provide: ActivatedRoute, provide: ActivatedRoute,
useValue: { useValue: {
@@ -138,11 +143,31 @@ describe("ProductSwitcherService", () => {
}); });
describe("Admin/Organizations", () => { describe("Admin/Organizations", () => {
it("includes Organizations in other when there are organizations", async () => { it("includes Organizations with the internal route in other when there are organizations on cloud", async () => {
initiateService(); initiateService();
const products = await firstValueFrom(service.products$); const products = await firstValueFrom(service.products$);
const organizations = products.other.find((p) => p.name === "Organizations");
expect(organizations).toBeDefined();
expect(organizations.marketingRoute.route).toBe("/create-organization");
expect(organizations.marketingRoute.external).toBe(false);
expect(products.other.find((p) => p.name === "Organizations")).toBeDefined();
expect(products.bento.find((p) => p.name === "Admin Console")).toBeUndefined();
});
it("includes Organizations with the external route in other when there are organizations on Self-Host", async () => {
platformUtilsService.isSelfHost.mockReturnValue(true);
initiateService();
const products = await firstValueFrom(service.products$);
const organizations = products.other.find((p) => p.name === "Organizations");
expect(organizations).toBeDefined();
expect(organizations.marketingRoute.route).toBe("https://bitwarden.com/products/business/");
expect(organizations.marketingRoute.external).toBe(true);
expect(products.other.find((p) => p.name === "Organizations")).toBeDefined(); expect(products.other.find((p) => p.name === "Organizations")).toBeDefined();
expect(products.bento.find((p) => p.name === "Admin Console")).toBeUndefined(); expect(products.bento.find((p) => p.name === "Admin Console")).toBeUndefined();
}); });

View File

@@ -21,6 +21,7 @@ import {
import { ProviderService } from "@bitwarden/common/admin-console/abstractions/provider.service"; import { ProviderService } from "@bitwarden/common/admin-console/abstractions/provider.service";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization"; import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { SyncService } from "@bitwarden/common/platform/sync"; import { SyncService } from "@bitwarden/common/platform/sync";
export type ProductSwitcherItem = { export type ProductSwitcherItem = {
@@ -101,6 +102,7 @@ export class ProductSwitcherService {
private i18n: I18nPipe, private i18n: I18nPipe,
private syncService: SyncService, private syncService: SyncService,
private accountService: AccountService, private accountService: AccountService,
private platformUtilsService: PlatformUtilsService,
) { ) {
this.pollUntilSynced(); this.pollUntilSynced();
} }
@@ -151,6 +153,16 @@ export class ProductSwitcherService {
// TODO: This should be migrated to an Observable provided by the provider service and moved to the combineLatest above. See AC-2092. // TODO: This should be migrated to an Observable provided by the provider service and moved to the combineLatest above. See AC-2092.
const providers = await this.providerService.getAll(); const providers = await this.providerService.getAll();
const orgsMarketingRoute = this.platformUtilsService.isSelfHost()
? {
route: "https://bitwarden.com/products/business/",
external: true,
}
: {
route: "/create-organization",
external: false,
};
const products = { const products = {
pm: { pm: {
name: "Password Manager", name: "Password Manager",
@@ -197,10 +209,7 @@ export class ProductSwitcherService {
orgs: { orgs: {
name: "Organizations", name: "Organizations",
icon: "bwi-business", icon: "bwi-business",
marketingRoute: { marketingRoute: orgsMarketingRoute,
route: "https://bitwarden.com/products/business/",
external: true,
},
otherProductOverrides: { otherProductOverrides: {
name: "Share your passwords", name: "Share your passwords",
supportingText: this.i18n.transform("protectYourFamilyOrBusiness"), supportingText: this.i18n.transform("protectYourFamilyOrBusiness"),