Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/JAVA/Openclaw/extensions/matrix/src/matrix/actions/   (KI Agentensystem Version 22©)  Datei vom 26.3.2026 mit Größe 2 kB image not shown  

Quelle  pins.test.ts

  Sprache: JAVA
 

Spracherkennung für: .ts vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

import { describe, expect, it, vi } from "vitest";
import type { MatrixClient } from "../sdk.js";
import { listMatrixPins, pinMatrixMessage, unpinMatrixMessage } from "./pins.js";

function createPinsClient(seedPinned: string[], knownBodies: Record<string, string> = {}) {
  let pinned = [...seedPinned];
  const getRoomStateEvent = vi.fn(async () => ({ pinned: [...pinned] }));
  const sendStateEvent = vi.fn(
    async (_roomId: string, _type: string, _key: string, payload: unknown) => {
      pinned = [...((payload as { pinned: string[] }).pinned ?? [])];
    },
  );
  const getEvent = vi.fn(async (_roomId: string, eventId: string) => {
    const body = knownBodies[eventId];
    if (!body) {
      throw new Error("missing");
    }
    return {
      event_id: eventId,
      sender: "@alice:example.org",
      type: "m.room.message",
      origin_server_ts: 123,
      content: { msgtype: "m.text", body },
    };
  });

  return {
    client: {
      getRoomStateEvent,
      sendStateEvent,
      getEvent,
      stop: vi.fn(),
    } as unknown as MatrixClient,
    getPinned: () => pinned,
    sendStateEvent,
  };
}

describe("matrix pins actions", () => {
  it("pins a message once even when asked twice", async () => {
    const { client, getPinned, sendStateEvent } = createPinsClient(["$a"]);

    const first = await pinMatrixMessage("!room:example.org", "$b", { client });
    const second = await pinMatrixMessage("!room:example.org", "$b", { client });

    expect(first.pinned).toEqual(["$a", "$b"]);
    expect(second.pinned).toEqual(["$a", "$b"]);
    expect(getPinned()).toEqual(["$a", "$b"]);
    expect(sendStateEvent).toHaveBeenCalledTimes(2);
  });

  it("unpinds only the selected message id", async () => {
    const { client, getPinned } = createPinsClient(["$a", "$b", "$c"]);

    const result = await unpinMatrixMessage("!room:example.org", "$b", { client });

    expect(result.pinned).toEqual(["$a", "$c"]);
    expect(getPinned()).toEqual(["$a", "$c"]);
  });

  it("lists pinned ids and summarizes only resolvable events", async () => {
    const { client } = createPinsClient(["$a", "$missing"], { $a: "hello" });

    const result = await listMatrixPins("!room:example.org", { client });

    expect(result.pinned).toEqual(["$a", "$missing"]);
    expect(result.events).toEqual([
      expect.objectContaining({
        eventId: "$a",
        body: "hello",
      }),
    ]);
  });
});

¤ Dauer der Verarbeitung: 0.14 Sekunden  (vorverarbeitet am  2026-04-27) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.