mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 17:23:37 +00:00
Add messaging & messaging-internal libraries (#15711)
This commit is contained in:
47
libs/messaging-internal/src/helpers.spec.ts
Normal file
47
libs/messaging-internal/src/helpers.spec.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Subject, firstValueFrom } from "rxjs";
|
||||
|
||||
import { CommandDefinition, isExternalMessage, Message } from "@bitwarden/messaging";
|
||||
|
||||
import { getCommand, tagAsExternal } from "./helpers";
|
||||
|
||||
describe("helpers", () => {
|
||||
describe("getCommand", () => {
|
||||
it("can get the command from just a string", () => {
|
||||
const command = getCommand("myCommand");
|
||||
|
||||
expect(command).toEqual("myCommand");
|
||||
});
|
||||
|
||||
it("can get the command from a message definition", () => {
|
||||
const commandDefinition = new CommandDefinition<Record<string, unknown>>("myCommand");
|
||||
|
||||
const command = getCommand(commandDefinition);
|
||||
|
||||
expect(command).toEqual("myCommand");
|
||||
});
|
||||
});
|
||||
|
||||
describe("tag integration", () => {
|
||||
it("can tag and identify as tagged", async () => {
|
||||
const messagesSubject = new Subject<Message<Record<string, unknown>>>();
|
||||
|
||||
const taggedMessages = messagesSubject.asObservable().pipe(tagAsExternal());
|
||||
|
||||
const firstValuePromise = firstValueFrom(taggedMessages);
|
||||
|
||||
messagesSubject.next({ command: "test" });
|
||||
|
||||
const result = await firstValuePromise;
|
||||
|
||||
expect(isExternalMessage(result)).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isExternalMessage", () => {
|
||||
it.each([null, { command: "myCommand", test: "object" }, undefined] as Message<
|
||||
Record<string, unknown>
|
||||
>[])("returns false when value is %s", (value: Message<Record<string, unknown>>) => {
|
||||
expect(isExternalMessage(value)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user