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 1 kB image not shown  

Quelle  polls.test.ts

  Sprache: JAVA
 

import { describe, expect, it, vi } from "vitest";
import type { MatrixClient } from "../sdk.js";
import { voteMatrixPoll } from "./polls.js";

function createPollClient(pollContent?: Record<string, unknown>) {
  const getEvent = vi.fn(async () => ({
    type: "m.poll.start",
    content: pollContent ?? {
      "m.poll.start": {
        question: { "m.text""Favorite fruit?" },
        max_selections: 1,
        answers: [
          { id: "apple""m.text""Apple" },
          { id: "berry""m.text""Berry" },
        ],
      },
    },
  }));
  const sendEvent = vi.fn(async () => "$vote1");

  return {
    client: {
      getEvent,
      sendEvent,
      stop: vi.fn(),
    } as unknown as MatrixClient,
    getEvent,
    sendEvent,
  };
}

describe("matrix poll actions", () => {
  it("votes by option index against the resolved room id", async () => {
    const { client, getEvent, sendEvent } = createPollClient();

    const result = await voteMatrixPoll("room:!room:example.org""$poll", {
      client,
      optionIndex: 2,
    });

    expect(getEvent).toHaveBeenCalledWith("!room:example.org""$poll");
    expect(sendEvent).toHaveBeenCalledWith(
      "!room:example.org",
      "m.poll.response",
      expect.objectContaining({
        "m.poll.response": { answers: ["berry"] },
      }),
    );
    expect(result).toEqual({
      eventId: "$vote1",
      roomId: "!room:example.org",
      pollId: "$poll",
      answerIds: ["berry"],
      labels: ["Berry"],
      maxSelections: 1,
    });
  });

  it("rejects option indexes that are outside the poll range", async () => {
    const { client, sendEvent } = createPollClient();

    await expect(
      voteMatrixPoll("room:!room:example.org""$poll", {
        client,
        optionIndex: 3,
      }),
    ).rejects.toThrow("out of range");

    expect(sendEvent).not.toHaveBeenCalled();
  });
});

Messung V0.5 in Prozent
C=98 H=99 G=98

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet am  2026-06-06) ¤

*© 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.