mirror of
https://github.com/bitwarden/clients.git
synced 2025-12-10 00:08:42 -06:00
* [PM-27662] Add revision date to policy response * [PM-27662] Introduce vault item transfer service * [PM-27662] Add feature flag check * [PM-27662] Add tests * [PM-27662] Add basic implementation to Web vault * [PM-27662] Remove redundant for loop * [PM-27662] Remove unnecessary distinctUntilChanged * [PM-27662] Avoid subscribing to userMigrationInfo$ if feature flag disabled * [PM-27662] Make UserMigrationInfo type more strict * [PM-27662] Typo * [PM-27662] Fix missing i18n * [PM-27662] Fix tests * [PM-27662] Fix tests/types related to policy changes * [PM-27662] Use getById operator
100 lines
3.3 KiB
TypeScript
100 lines
3.3 KiB
TypeScript
import { mock } from "jest-mock-extended";
|
|
import { firstValueFrom, of } from "rxjs";
|
|
|
|
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
|
import { PolicyType } from "@bitwarden/common/admin-console/enums";
|
|
// FIXME: use index.ts imports once policy abstractions and models
|
|
// implement ADR-0002
|
|
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
|
import { UserId } from "@bitwarden/common/types/guid";
|
|
|
|
import { FakeStateProvider, mockAccountServiceWith } from "../../../../../common/spec";
|
|
|
|
import { GENERATOR_SETTINGS } from "./key-definitions";
|
|
|
|
import {
|
|
GeneratorNavigationEvaluator,
|
|
DefaultGeneratorNavigationService,
|
|
DefaultGeneratorNavigation,
|
|
} from ".";
|
|
|
|
const SomeUser = "some user" as UserId;
|
|
|
|
describe("DefaultGeneratorNavigationService", () => {
|
|
describe("options$", () => {
|
|
it("emits options", async () => {
|
|
const stateProvider = new FakeStateProvider(mockAccountServiceWith(SomeUser));
|
|
const settings = { type: "password" as const };
|
|
await stateProvider.setUserState(GENERATOR_SETTINGS, settings, SomeUser);
|
|
const navigation = new DefaultGeneratorNavigationService(stateProvider, null);
|
|
|
|
const result = await firstValueFrom(navigation.options$(SomeUser));
|
|
|
|
expect(result).toEqual(settings);
|
|
});
|
|
});
|
|
|
|
describe("defaults$", () => {
|
|
it("emits default options", async () => {
|
|
const navigation = new DefaultGeneratorNavigationService(null, null);
|
|
|
|
const result = await firstValueFrom(navigation.defaults$(SomeUser));
|
|
|
|
expect(result).toEqual(DefaultGeneratorNavigation);
|
|
});
|
|
});
|
|
|
|
describe("evaluator$", () => {
|
|
it("emits a GeneratorNavigationEvaluator", async () => {
|
|
const policyService = mock<PolicyService>({
|
|
policiesByType$() {
|
|
return of([]);
|
|
},
|
|
});
|
|
const navigation = new DefaultGeneratorNavigationService(null, policyService);
|
|
|
|
const result = await firstValueFrom(navigation.evaluator$(SomeUser));
|
|
|
|
expect(result).toBeInstanceOf(GeneratorNavigationEvaluator);
|
|
});
|
|
});
|
|
|
|
describe("enforcePolicy", () => {
|
|
it("applies policy", async () => {
|
|
const policyService = mock<PolicyService>({
|
|
policiesByType$(_type: PolicyType, _user: UserId) {
|
|
return of([
|
|
new Policy({
|
|
id: "" as any,
|
|
organizationId: "" as any,
|
|
enabled: true,
|
|
type: PolicyType.PasswordGenerator,
|
|
data: { overridePasswordType: "password" },
|
|
revisionDate: new Date().toISOString(),
|
|
}),
|
|
]);
|
|
},
|
|
});
|
|
const navigation = new DefaultGeneratorNavigationService(null, policyService);
|
|
const options = {};
|
|
|
|
const result = await navigation.enforcePolicy(SomeUser, options);
|
|
|
|
expect(result).toMatchObject({ type: "password" });
|
|
});
|
|
});
|
|
|
|
describe("saveOptions", () => {
|
|
it("updates options$", async () => {
|
|
const stateProvider = new FakeStateProvider(mockAccountServiceWith(SomeUser));
|
|
const navigation = new DefaultGeneratorNavigationService(stateProvider, null);
|
|
const settings = { type: "password" as const };
|
|
|
|
await navigation.saveOptions(SomeUser, settings);
|
|
const result = await firstValueFrom(navigation.options$(SomeUser));
|
|
|
|
expect(result).toEqual(settings);
|
|
});
|
|
});
|
|
});
|