import { describe, it, expect } from "vitest";
import { RecordingDataRectify } from "./recording-data-rectify";

describe("RecordingDataRectify", () => {
  it("records updateSubjectField calls", async () => {
    const rectifier = new RecordingDataRectify();
    await rectifier.updateSubjectField("alice", "users", "name", "Alice New");

    expect(rectifier.calls).toHaveLength(1);
    expect(rectifier.calls[0]).toEqual({
      subjectId: "alice",
      collection: "users",
      field: "name",
      value: "Alice New",
    });
  });

  it("returns void (undefined)", async () => {
    const rectifier = new RecordingDataRectify();
    const result = await rectifier.updateSubjectField(
      "alice",
      "users",
      "name",
      "x",
    );

    expect(result).toBeUndefined();
  });

  it("records multiple calls in order", async () => {
    const rectifier = new RecordingDataRectify();
    await rectifier.updateSubjectField("alice", "users", "name", "A");
    await rectifier.updateSubjectField("alice", "users", "email", "a@ex.com");

    expect(rectifier.calls).toHaveLength(2);
    expect(rectifier.calls[0]?.field).toBe("name");
    expect(rectifier.calls[1]?.field).toBe("email");
  });

  it("reset() clears recorded calls", async () => {
    const rectifier = new RecordingDataRectify();
    await rectifier.updateSubjectField("alice", "users", "name", "A");
    rectifier.reset();

    expect(rectifier.calls).toHaveLength(0);
  });
});
