bursa / client / test / pending.test.mjs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// The in-flight set behind "connecting…": whoever opens a bank session — the
// row's connect button or the boot reopen — holds its token in the store's
// one pending set until the open settles, and the row reads exactly that.
// The bug this pins: the reopen path never marked its dials, so a reopening
// bank spent its whole window as "hasn't connected yet" over a connect button.

import test from "node:test";
import assert from "node:assert/strict";
import * as L from "../test-dist/testlib.js";

test("the token is pending from before the open until it resolves", async () => {
  const pending = new Set();
  let changes = 0;
  let resolve;
  const p = L.trackPending(pending, "tok", () => { changes += 1; },
    () => new Promise((r) => { resolve = r; }));
  // marked BEFORE the session exists — this is the reopen window the UI
  // used to spend showing a connect button
  assert.equal(pending.has("tok"), true);
  assert.equal(changes, 1, "the UI was told at the leading edge");
  resolve(null);
  assert.equal(await p, null, "the settled value passes through");
  assert.equal(pending.has("tok"), false, "cleared on settle");
  assert.equal(changes, 2, "and the UI was told again");
});

test("a refused open clears the token — the row falls back to the button", async () => {
  const pending = new Set();
  const out = await L.trackPending(pending, "tok", () => {},
    () => Promise.resolve("err.bank.open"));
  assert.equal(out, "err.bank.open", "the catalog key stays the caller's");
  assert.equal(pending.has("tok"), false);
});

test("even a rejecting open leaves no token behind", async () => {
  const pending = new Set();
  await assert.rejects(
    L.trackPending(pending, "tok", () => {}, () => Promise.reject(new Error("boom"))),
  );
  assert.equal(pending.has("tok"), false);
});

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/bursa.git