Add an HTTP heartbeat, and file bills under the till that rang them
Two faults found while checking whether today's live bills had landed. They had — 17 of them, complete — but both of these were sitting in the same data. **Health existed only over MQTT.** The consumer subscribes to the health topic and has done since startup, but a terminal on the HTTP route has no way to reach it. Today's terminal was on HTTP, so it reported nothing and the board showed "online 0 of 1" while the till was demonstrably alive and selling. POST /pos/health now takes the same payload the broker carries, into the same Redis record, so the board cannot tell the two routes apart and does not need to. It answers 202 and swallows failures: a till that cannot say how it is must still sell. **terminalid was empty on 16 of 17 bills.** The consumer backfills a missing terminal code from the topic, but onto the batch, while the row was built from the order — the two never met, and importPosOrder was not handed the batch's value at all. Over HTTP there was no topic to fall back on either. So the invoice numbers read INV-2608-T5EDD-000NN while the column they should have matched was blank, and `byterminal` on the sales summary grouped almost everything under "". The bill's own terminal now wins with the batch's as the fallback, trimmed, so whitespace is not mistaken for a code. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -160,3 +160,40 @@ func TestAnOutletCannotReplayAnotherOutletsRevision(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The bug this covers reached production and stayed invisible for a day.
|
||||
//
|
||||
// The MQTT consumer backfills a missing terminal code from the topic, but it
|
||||
// wrote it onto the *batch* while the row was built from the *order*, so the
|
||||
// two never met. Bills arriving over HTTP had no topic to fall back on at all.
|
||||
// The result: 16 of 17 live bills carried an empty terminalid while their own
|
||||
// invoice numbers read INV-2608-T5EDD-000NN, and `byterminal` on the sales
|
||||
// summary grouped almost everything under "".
|
||||
func TestABillTakesItsTerminalFromTheBatchWhenItNamesNone(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
orderTerminal string
|
||||
batchTerminal string
|
||||
want string
|
||||
}{
|
||||
{"bill names its own", "T5EDD", "TOTHER", "T5EDD"},
|
||||
{"bill is silent, batch knows", "", "T5EDD", "T5EDD"},
|
||||
{"neither knows", "", "", ""},
|
||||
|
||||
// Whitespace is not a terminal code. Treating it as one would file
|
||||
// bills under a blank that reads identically to the missing value
|
||||
// this fallback exists to prevent.
|
||||
{"bill sends whitespace", " ", "T5EDD", "T5EDD"},
|
||||
{"batch sends whitespace", "", " ", ""},
|
||||
{"codes are trimmed", " T5EDD ", "", "T5EDD"},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
if got := posTerminalFor(c.orderTerminal, c.batchTerminal); got != c.want {
|
||||
t.Errorf("posTerminalFor(%q, %q) = %q, want %q",
|
||||
c.orderTerminal, c.batchTerminal, got, c.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user