Something went wrong. Try again.
Convert CSV banking statements to hledger journals
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091import assert from "assert";import { Api, viewQuery } from "./api.js";
// A server that records what it was asked and answers with `payload`. Before// answering, it runs `meanwhile`, which is where a test moves the controls.function server({ ok = true, payload = { rows: [] }, meanwhile = () => {} } = {}) { const requests = []; const fetch = (url, init) => { requests.push({ url, ...init }); meanwhile(); return Promise.resolve({ ok, json: () => Promise.resolve(payload) }); }; return { fetch, requests };}
Deno.test("M1-UI-005: the view asks for exactly the checked statuses", () => { assert.equal(viewQuery(["zero", "multiple"], ""), "?status=zero,multiple&q=");});
Deno.test("M1-UI-005: no status checked asks for no rows, not for every row", () => { assert.equal(viewQuery([], ""), "?status=&q=");});
Deno.test("M1-UI-006: the search reaches the server as typed", () => { const query = viewQuery(["one"], "Miete & Co #3 ü"); assert.equal(new URLSearchParams(query).get("q"), "Miete & Co #3 ü");});
Deno.test("M1-UI-005: the state is asked for under the current view", async () => { const { fetch, requests } = server(); await new Api(fetch, () => "?status=one&q=").state(); assert.equal(requests[0].url, "/api/state?status=one&q=");});
Deno.test("M1-UI-005: the state comes back when the view is still the one it was for", async () => { const payload = { rows: [1] }; const { fetch } = server({ payload }); assert.equal(await new Api(fetch, () => "?status=one&q=").state(), payload);});
Deno.test("M1-UI-005: state for a view the controls have left is dropped", async () => { let view = "?status=one&q="; const { fetch } = server({ meanwhile: () => { view = "?status=zero&q="; } }); assert.equal(await new Api(fetch, () => view).state(), null);});
Deno.test("M1-UI-010: an edit goes out as JSON, under the current view", async () => { const { fetch, requests } = server(); await new Api(fetch, () => "?status=&q=x").send("PUT", "/api/rules", '{"rules":[]}'); assert.deepEqual(requests, [{ url: "/api/rules?status=&q=x", method: "PUT", headers: { "content-type": "application/json" }, body: '{"rules":[]}', }]);});
Deno.test("M1-UI-010: an edit's answer carries its results and whether it was taken", async () => { const payload = { rows: [1] }; const { fetch } = server({ ok: false, payload }); const outcome = await new Api(fetch, () => "").send("PUT", "/api/rules", "{}"); assert.deepEqual(outcome, { accepted: false, current: true, payload });});
Deno.test("M1-UI-005: an answer for a view the controls have left says so, and still says what happened", async () => { let view = "?status=one&q="; const { fetch } = server({ meanwhile: () => { view = "?status=one&q=a"; } }); const outcome = await new Api(fetch, () => view).send("POST", "/api/save", ""); assert.equal(outcome.current, false); assert.equal(outcome.accepted, true);});
Deno.test("D9: completion asks with the text before the cursor, and no view", async () => { const answer = { candidates: ["payee"], insert: "yee" }; const { fetch, requests } = server({ payload: answer }); assert.equal(await new Api(fetch, () => "?status=one&q=").complete("pa"), answer); assert.deepEqual(requests, [{ url: "/api/complete", method: "POST", headers: { "content-type": "application/json" }, body: '{"before":"pa"}', }]);});
Deno.test("M1-UI-014: the preview is asked for on its own", async () => { const preview = { journal: "", final: true, diagnostics: [] }; const { fetch, requests } = server({ payload: preview }); assert.equal(await new Api(fetch, () => "?status=one&q=").preview(), preview); assert.equal(requests[0].url, "/api/preview");});