import assert from "node:assert/strict";
import test from "node:test";
import { runProSheetAction } from "./pro-sheet-action.js";

test("a Pro sheet action closes first and resumes account add only after activation", async () => {
  const calls = [];
  const result = await runProSheetAction(async () => { calls.push("action"); return { state:"activated" }; }, {
    close() { calls.push("close"); }, resume() { calls.push("resume"); },
  });
  assert.equal(result.state, "activated");
  assert.deepEqual(calls, ["close", "action", "resume"]);
});

test("canceled and pending actions close without resuming account add", async () => {
  for (const state of ["canceled", "pending"]) {
    let resumed = 0;
    await runProSheetAction(async () => ({ state }), { close() {}, resume() { resumed += 1; } });
    assert.equal(resumed, 0);
  }
});
