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:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user