--
This commit is contained in:
@@ -151,3 +151,48 @@ class TestMonthlyDownload:
|
||||
async def test_a_form_without_a_month_rejects_the_filter(self, client, auth, forms):
|
||||
resp = await client.get(f"{API}/fare_chart/pdf", headers=auth["mr1"], params={"month": "November"})
|
||||
assert resp.status_code == 422
|
||||
|
||||
|
||||
class TestExpenseStatement:
|
||||
async def test_the_total_is_worked_out_by_the_server(self, client, auth, db):
|
||||
await _make_table(db, "expense_statement", owned=True)
|
||||
made = await client.post(
|
||||
f"{API}/expense_statement/rows", headers=auth["mr1"],
|
||||
json={"report_date": "2026-10-01", "fare": "120.50", "da_hq": "100", "total": "1"},
|
||||
)
|
||||
assert made.status_code == 201, made.text
|
||||
assert made.json()["total"] == "220.50" and made.json()["name"] == "Ravi Das"
|
||||
row = made.json()["id"]
|
||||
changed = await client.patch(f"{API}/expense_statement/rows/{row}", headers=auth["mr1"], json={"postage": "9.50", "total": "5"})
|
||||
assert changed.status_code == 200 and changed.json()["total"] == "230.00"
|
||||
bad = await client.patch(f"{API}/expense_statement/rows/{row}", headers=auth["mr1"], json={"fare": "abc"})
|
||||
assert bad.status_code == 422
|
||||
|
||||
async def test_clearing_one_cell_of_a_row_that_has_other_values_is_allowed(self, client, auth, db):
|
||||
await _make_table(db, "expense_statement", owned=True)
|
||||
made = await client.post(f"{API}/expense_statement/rows", headers=auth["admin"], json={"from_location": "A", "fare": "10"}, params={"owner_id": str((await client.get(f"{API}/owners", headers=auth["admin"])).json()[0]["id"])})
|
||||
assert made.status_code == 201, made.text
|
||||
cleared = await client.patch(f"{API}/expense_statement/rows/{made.json()['id']}", headers=auth["admin"], json={"fare": ""})
|
||||
assert cleared.status_code == 200, cleared.text
|
||||
assert cleared.json()["fare"] == "" and cleared.json()["total"] is None
|
||||
|
||||
|
||||
class TestRemovingAMistake:
|
||||
async def test_an_mr_removes_their_own_row_and_the_rest_are_renumbered(self, client, auth, forms):
|
||||
first = await _add(client, auth["mr1"], "A")
|
||||
await _add(client, auth["mr1"], "B")
|
||||
assert (await client.delete(f"{API}/fare_chart/rows/{first}", headers=auth["mr1"])).status_code == 204
|
||||
mine = (await client.get(f"{API}/fare_chart/rows", headers=auth["mr1"])).json()
|
||||
assert [(r["from_location"], r["serial_no"]) for r in mine] == [("B", "1")]
|
||||
|
||||
async def test_an_mr_removes_an_extra_copy_of_a_product_but_never_its_only_row(self, client, auth, db):
|
||||
await _make_table(db, "sales_projection", owned=False)
|
||||
made = await client.post(f"{API}/sales_projection/rows", headers=auth["admin"], json={"product_name": "INTEZOLE-PD", "pts": "106.92"})
|
||||
assert made.status_code == 201, made.text
|
||||
row = made.json()["id"]
|
||||
extra = await client.post(f"{API}/sales_projection/rows", headers=auth["mr1"], json={"product_name": "INTEZOLE-PD", "month": "August"})
|
||||
assert extra.status_code == 201, extra.text
|
||||
assert (await client.delete(f"{API}/sales_projection/rows/{extra.json()['id']}", headers=auth["mr1"])).status_code == 204
|
||||
assert (await client.delete(f"{API}/sales_projection/rows/{row}", headers=auth["mr1"])).status_code == 403
|
||||
cleared = await client.patch(f"{API}/sales_projection/rows/{row}", headers=auth["mr1"], json={"closing_qty": "", "month": ""})
|
||||
assert cleared.status_code == 200 and cleared.json()["product_name"] == "INTEZOLE-PD"
|
||||
|
||||
Reference in New Issue
Block a user