fix(vat): resolve non-deterministic ORDER BY in TestVAT_ToggleLifecycle
Frontend Lint & Vulns / Lint & vulns (push) Failing after 48s
Frontend Lint & Vulns / Lint & vulns (push) Failing after 48s
The phase 3 payment query used ORDER BY created_at DESC LIMIT 1. Within a single transaction, NOW() returns the same timestamp for all inserts, making the ordering non-deterministic when other parallel tests insert payment rows with the same timestamp. Fix by parsing the response's payment ID and querying by it directly. Also revert eslint.config.js back to error-level rules for all categories (removing the previous 'warn' overrides).
This commit is contained in:
@@ -1202,12 +1202,19 @@ func TestVAT_ToggleLifecycle(t *testing.T) {
|
||||
t.Fatalf("phase 3: expected 200, got %d: %s", w3.Code, w3.Body.String())
|
||||
}
|
||||
|
||||
var phase3Resp CheckoutResponse
|
||||
if err := json.Unmarshal(w3.Body.Bytes(), &phase3Resp); err != nil {
|
||||
t.Fatalf("phase 3: failed to parse response: %v", err)
|
||||
}
|
||||
|
||||
var phase3VAT sql.NullFloat64
|
||||
var phase3Net sql.NullFloat64
|
||||
var phase3VATApplicable bool
|
||||
var phase3Amount float64
|
||||
// Get the latest cash payment (the second one)
|
||||
err = tx.QueryRow(ctx, `SELECT amount, is_vat_applicable, vat_amount, net_amount FROM payments WHERE booking_id = $1 AND payment_method = 'cash' ORDER BY created_at DESC LIMIT 1`, bookingID).Scan(&phase3Amount, &phase3VATApplicable, &phase3VAT, &phase3Net)
|
||||
// Get the specific payment by its ID from the response (avoiding
|
||||
// non-deterministic ORDER BY created_at DESC when NOW() returns the same
|
||||
// transaction start time for all inserts within a transaction).
|
||||
err = tx.QueryRow(ctx, `SELECT amount, is_vat_applicable, vat_amount, net_amount FROM payments WHERE id = $1`, phase3Resp.CheckoutID).Scan(&phase3Amount, &phase3VATApplicable, &phase3VAT, &phase3Net)
|
||||
if err != nil {
|
||||
t.Fatalf("phase 3: failed to query payment: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user