peppa/bench/tasks/06-refactor/checks/visible-report.test.mjs.txt
Асель d108197f0f PEP-184: задачи 5–8, тест набора, archive change, память
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 02:09:17 +05:00

37 lines
2.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// BENCH-HIDDEN — видимые тесты на момент старта (их нельзя ослаблять).
import { test } from "node:test";
import assert from "node:assert/strict";
import { buildReport, renderReport } from "../report.mjs";
const orders = [
{ id: 1, date: "2026-11-01", manager: "Аса", city: "Алматы", status: "paid", items: [{ title: "Чайник", qty: 1, price: 12000 }] },
{ id: 2, date: "2026-11-01", manager: "Бек", city: "Астана", status: "paid", items: [{ title: "Кружка", qty: 4, price: 1500 }], promo: "HALF" },
{ id: 3, date: "2026-11-02", manager: "Аса", city: "Алматы", status: "cancelled", items: [{ title: "Чайник", qty: 1, price: 12000 }] },
{ id: 4, date: "2026-11-02", manager: "Аса", city: " ", status: "refunded", items: [{ title: "Тарелка", qty: 2, price: 2500 }] },
{ id: 5, date: "2026-11-03", city: "Алматы", status: "paid", items: [{ title: "Ложка", qty: 3, price: 300 }], promo: "MINUS500" },
];
test("по дням", () => {
const r = buildReport(orders, { groupBy: "day" });
assert.deepEqual(r.rows.map((x) => [x.key, x.orders, x.revenue, x.items]), [["2026-11-01", 2, 15000, 5], ["2026-11-03", 1, 400, 3]]);
assert.deepEqual(r.total, { orders: 3, revenue: 15400, items: 8, avgCheck: 5133 });
assert.equal(r.cancelled, 1);
assert.deepEqual(r.refunded, { orders: 1, sum: 5000 });
});
test("по менеджерам — по выручке", () => {
const r = buildReport(orders, { groupBy: "manager" });
assert.deepEqual(r.rows.map((x) => x.key), ["Аса", "Бек", "Без менеджера"]);
});
test("период", () => {
const r = buildReport(orders, { groupBy: "city", from: "2026-11-02", to: "2026-11-03" });
assert.deepEqual(r.rows.map((x) => [x.key, x.revenue]), [["Алматы", 400]]);
});
test("таблица", () => {
const html = renderReport(buildReport(orders, { groupBy: "day" }), "day");
assert.match(html, /01\.11\.2026/);
assert.match(html, /Возвратов: 1/);
});