1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 11:13:46 +00:00

[PM-6818] legacy generator service adapter (#8582)

* introduce legacy generators
* introduce generator navigation service
* Introduce default options. These accept a userId so that they can be policy-defined
* replace `GeneratorOptions` with backwards compatible `GeneratorNavigation`
This commit is contained in:
✨ Audrey ✨
2024-04-03 13:48:33 -04:00
committed by GitHub
parent ff3ff89e20
commit b579bc8f96
64 changed files with 2759 additions and 622 deletions

View File

@@ -10,6 +10,11 @@ import { UserId } from "../../../types/guid";
import { DefaultPolicyEvaluator } from "../default-policy-evaluator";
import { SUBADDRESS_SETTINGS } from "../key-definitions";
import {
DefaultSubaddressOptions,
SubaddressGenerationOptions,
} from "./subaddress-generator-options";
import { SubaddressGeneratorStrategy, UsernameGenerationServiceAbstraction } from ".";
const SomeUser = "some user" as UserId;
@@ -47,6 +52,16 @@ describe("Email subaddress list generation strategy", () => {
});
});
describe("defaults$", () => {
it("should return the default subaddress options", async () => {
const strategy = new SubaddressGeneratorStrategy(null, null);
const result = await firstValueFrom(strategy.defaults$(SomeUser));
expect(result).toEqual(DefaultSubaddressOptions);
});
});
describe("cache_ms", () => {
it("should be a positive non-zero number", () => {
const legacy = mock<UsernameGenerationServiceAbstraction>();
@@ -70,16 +85,14 @@ describe("Email subaddress list generation strategy", () => {
const legacy = mock<UsernameGenerationServiceAbstraction>();
const strategy = new SubaddressGeneratorStrategy(legacy, null);
const options = {
type: "website-name" as const,
email: "someone@example.com",
};
subaddressType: "website-name",
subaddressEmail: "someone@example.com",
website: "foo.com",
} as SubaddressGenerationOptions;
await strategy.generate(options);
expect(legacy.generateSubaddress).toHaveBeenCalledWith({
subaddressType: "website-name" as const,
subaddressEmail: "someone@example.com",
});
expect(legacy.generateSubaddress).toHaveBeenCalledWith(options);
});
});
});