- CRM -> Customers: search ignoring case and Greek accents (and part of the phone), visits / spent / last visit, the card (contact, notes, open tab, every visit with what was on a tab), new/edit/remove - Inventory -> Throwaways: log (product, quantity with a comma, reason, note) with its cost, today's list (delete today only), a period's totals by reason and product, every entry; Inventory -> Stock: an honest 'not available yet' - Notes: notes (pinned first, edit in place) and to-dos (urgent first, done folded away, who did it kept) - backend: crm.manage / inventory.manage / notes.use (the customer search also with the dashboard key, for orders); spending counted by services/sales.py (refunds off, tab lines in); null clears a field; names/notes not blank, priorities checked; waste ?date_from=&date_to= venue dates; the Greek reason labels left the API; live customers.changed / waste.changed / notes.changed - the overview's notes card needs notes.use and refreshes live - tests: test_customers_waste_notes.py (4), crm.test.mjs (3), e2e manager.mjs (customers, throwaways, notes, stock, Greek) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
2.5 KiB
JavaScript
38 lines
2.5 KiB
JavaScript
// Customers, throwaways and notes as plain data (plan step 6.13b).
|
|
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { customerBody, customerForm, customerLabel, customerProblems, perVisit } from '../src/pages/customers/customersLogic.js'
|
|
import { wasteProducts, wasteQuantity, wasteTotals } from '../src/pages/inventory/wasteLogic.js'
|
|
import { splitNotes, splitTodos } from '../src/pages/notes/notesLogic.js'
|
|
|
|
test('a customer: a name needed, a wrong e-mail caught, empty fields cleared', () => {
|
|
const f = customerForm(null)
|
|
assert.deepEqual(customerProblems(f), ['name'])
|
|
assert.deepEqual(customerProblems({ ...f, name: 'Γιώργος', email: 'x@' }), ['email'])
|
|
assert.deepEqual(customerBody({ ...f, name: ' Γιώργος ', nickname: ' ', phone: '697' }), { name: 'Γιώργος', nickname: null, phone: '697', email: null, notes: null })
|
|
assert.equal(customerLabel({ name: 'Kostas', nickname: 'Big K' }), 'Kostas «Big K»')
|
|
assert.equal(perVisit({ visit_count: 3, total_spent: 50 }), 16.67)
|
|
assert.equal(perVisit({ visit_count: 0, total_spent: 0 }), null)
|
|
})
|
|
|
|
test('throwaways: quantities with a comma, totals, the products offered', () => {
|
|
assert.equal(wasteQuantity('1,5'), 1.5)
|
|
assert.equal(wasteQuantity('0'), null)
|
|
assert.equal(wasteQuantity('x'), null)
|
|
assert.deepEqual(wasteTotals([{ total_cost: 2.5 }, { total_cost: null }, { total_cost: 1.25 }]), { count: 3, cost: 3.75, uncosted: 1 })
|
|
const products = [{ name: 'Σουβλάκι' }, { name: 'Απλή πίτα' }, { name: 'Off', is_available: false }, { name: 'Delivery', system_key: 'delivery_fee' }]
|
|
assert.deepEqual(wasteProducts(products, 'el').map(p => p.name), ['Απλή πίτα', 'Σουβλάκι'])
|
|
})
|
|
|
|
test('notes: pinned first; to-dos: urgent first, done apart', () => {
|
|
const { pinned, rest } = splitNotes([
|
|
{ id: 1, is_pinned: false, updated_at: '2026-11-19T10:00:00Z' }, { id: 2, is_pinned: true, updated_at: '2026-11-18T10:00:00Z' },
|
|
{ id: 3, is_pinned: false, updated_at: '2026-11-19T11:00:00Z' }])
|
|
assert.deepEqual([pinned.map(n => n.id), rest.map(n => n.id)], [[2], [3, 1]])
|
|
const { open, done } = splitTodos([
|
|
{ id: 1, is_done: false, priority: 'normal', created_at: '2026-11-19T12:00:00Z' },
|
|
{ id: 2, is_done: false, priority: 'high', created_at: '2026-11-18T12:00:00Z' },
|
|
{ id: 3, is_done: true, priority: 'high', done_at: '2026-11-19T09:00:00Z' }])
|
|
assert.deepEqual([open.map(t => t.id), done.map(t => t.id)], [[2, 1], [3]])
|
|
})
|