1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-05 18:13:26 +00:00

refactor feature flag state fetching and update tests

This commit is contained in:
Jonathan Prusik
2025-01-03 09:49:58 -05:00
parent b962373f71
commit 2b1a0046ee
5 changed files with 23 additions and 22 deletions

View File

@@ -11,10 +11,9 @@ import { DefaultDomainSettingsService, DomainSettingsService } from "./domain-se
describe("DefaultDomainSettingsService", () => {
let domainSettingsService: DomainSettingsService;
const configServiceMock = mock<ConfigService>();
let configService: MockProxy<ConfigService>;
const mockUserId = Utils.newGuid() as UserId;
const accountService: FakeAccountService = mockAccountServiceWith(mockUserId);
let mockConfigService: MockProxy<ConfigService>;
const fakeStateProvider: FakeStateProvider = new FakeStateProvider(accountService);
const mockEquivalentDomains = [
@@ -24,8 +23,9 @@ describe("DefaultDomainSettingsService", () => {
];
beforeEach(() => {
domainSettingsService = new DefaultDomainSettingsService(fakeStateProvider, mockConfigService);
jest.spyOn(configServiceMock, "getFeatureFlag$").mockReturnValue(of(false));
configService = mock<ConfigService>();
configService.getFeatureFlag$.mockImplementation(() => of(false));
domainSettingsService = new DefaultDomainSettingsService(fakeStateProvider, configService);
jest.spyOn(domainSettingsService, "getUrlEquivalentDomains");
domainSettingsService.equivalentDomains$ = of(mockEquivalentDomains);

View File

@@ -99,7 +99,12 @@ export class DefaultDomainSettingsService implements DomainSettingsService {
this.blockedInteractionsUris$ = this.configService
.getFeatureFlag$(FeatureFlag.BlockBrowserInjectionsByDomain)
.pipe(switchMap((enabled) => (enabled ? this.blockedInteractionsUrisState.state$ : of({}))));
.pipe(
switchMap((featureIsEnabled) =>
featureIsEnabled ? this.blockedInteractionsUrisState.state$ : of({} as NeverDomains),
),
map((disabledUris) => (Object.keys(disabledUris).length ? disabledUris : null)),
);
this.equivalentDomainsState = this.stateProvider.getActive(EQUIVALENT_DOMAINS);
this.equivalentDomains$ = this.equivalentDomainsState.state$.pipe(map((x) => x ?? null));