command.test.ts 854 B

12345678910111213141516171819202122232425
  1. import { describe, expect, test } from "bun:test"
  2. import { upsertCommandRegistration } from "./command"
  3. describe("upsertCommandRegistration", () => {
  4. test("replaces keyed registrations", () => {
  5. const one = () => [{ id: "one", title: "One" }]
  6. const two = () => [{ id: "two", title: "Two" }]
  7. const next = upsertCommandRegistration([{ key: "layout", options: one }], { key: "layout", options: two })
  8. expect(next).toHaveLength(1)
  9. expect(next[0]?.options).toBe(two)
  10. })
  11. test("keeps unkeyed registrations additive", () => {
  12. const one = () => [{ id: "one", title: "One" }]
  13. const two = () => [{ id: "two", title: "Two" }]
  14. const next = upsertCommandRegistration([{ options: one }], { options: two })
  15. expect(next).toHaveLength(2)
  16. expect(next[0]?.options).toBe(two)
  17. expect(next[1]?.options).toBe(one)
  18. })
  19. })