mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 14:53:33 +00:00
[PM-14161] Add getById and getByIds rjxs helpers (#11742)
This commit is contained in:
58
libs/common/src/platform/misc/rxjs-operators.spec.ts
Normal file
58
libs/common/src/platform/misc/rxjs-operators.spec.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { firstValueFrom, of } from "rxjs";
|
||||
|
||||
import { getById, getByIds } from "./rxjs-operators";
|
||||
|
||||
describe("custom rxjs operators", () => {
|
||||
describe("getById", () => {
|
||||
it("returns an object with a matching id", async () => {
|
||||
const obs = of([
|
||||
{
|
||||
id: 1,
|
||||
data: "one",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
data: "two",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
data: "three",
|
||||
},
|
||||
]).pipe(getById(2));
|
||||
|
||||
const result = await firstValueFrom(obs);
|
||||
|
||||
expect(result).toEqual({ id: 2, data: "two" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("getByIds", () => {
|
||||
it("returns an array of objects with matching ids", async () => {
|
||||
const obs = of([
|
||||
{
|
||||
id: 1,
|
||||
data: "one",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
data: "two",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
data: "three",
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
data: "four",
|
||||
},
|
||||
]).pipe(getByIds([2, 3]));
|
||||
|
||||
const result = await firstValueFrom(obs);
|
||||
|
||||
expect(result).toEqual([
|
||||
{ id: 2, data: "two" },
|
||||
{ id: 3, data: "three" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user