mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 09:43:23 +00:00
* Add Helper For Preparing a Record For Use in `forkJoin` * Update & Test CryptoService Changes * Delete Unused Code * Update DeviceTrustService * Update CipherService * Make `userPublicKey$` Public * Rename convertValues File * Update libs/common/src/platform/abstractions/crypto.service.ts Co-authored-by: Andreas Coroiu <acoroiu@bitwarden.com> * Add `convertValues` Tests * Add Doc Comments * Convert to `function`'s Co-authored-by: Andreas Coroiu <acoroiu@bitwarden.com> * Fix Test Typos * Add param doc * Update Test Name * Add `@throws` Docs --------- Co-authored-by: Andreas Coroiu <acoroiu@bitwarden.com>
75 lines
1.7 KiB
TypeScript
75 lines
1.7 KiB
TypeScript
import { forkJoin, lastValueFrom, of, switchMap } from "rxjs";
|
|
|
|
import { convertValues } from "./convert-values";
|
|
|
|
describe("convertValues", () => {
|
|
it("returns null if given null", async () => {
|
|
const output = await lastValueFrom(
|
|
of<Record<string, number>>(null).pipe(convertValues((k, v) => of(v + 1))),
|
|
);
|
|
|
|
expect(output).toEqual(null);
|
|
});
|
|
|
|
it("returns empty record if given empty record", async () => {
|
|
const output = await lastValueFrom(
|
|
of<Record<string, number>>({}).pipe(convertValues((k, v) => of(v + 1))),
|
|
);
|
|
|
|
expect(output).toEqual({});
|
|
});
|
|
|
|
const cases: { it: string; input: Record<string, number>; output: Record<string, number> }[] = [
|
|
{
|
|
it: "converts single entry to observable",
|
|
input: {
|
|
one: 1,
|
|
},
|
|
output: {
|
|
one: 2,
|
|
},
|
|
},
|
|
{
|
|
it: "converts multiple entries to observable",
|
|
input: {
|
|
one: 1,
|
|
two: 2,
|
|
three: 3,
|
|
},
|
|
output: {
|
|
one: 2,
|
|
two: 3,
|
|
three: 4,
|
|
},
|
|
},
|
|
];
|
|
|
|
it.each(cases)("$it", async ({ input, output: expectedOutput }) => {
|
|
const output = await lastValueFrom(
|
|
of(input).pipe(
|
|
convertValues((key, value) => of(value + 1)),
|
|
switchMap((values) => forkJoin(values)),
|
|
),
|
|
);
|
|
|
|
expect(output).toEqual(expectedOutput);
|
|
});
|
|
|
|
it("converts async functions to observable", async () => {
|
|
const output = await lastValueFrom(
|
|
of({
|
|
one: 1,
|
|
two: 2,
|
|
}).pipe(
|
|
convertValues(async (key, value) => await Promise.resolve(value + 1)),
|
|
switchMap((values) => forkJoin(values)),
|
|
),
|
|
);
|
|
|
|
expect(output).toEqual({
|
|
one: 2,
|
|
two: 3,
|
|
});
|
|
});
|
|
});
|