feat(orders): implement order ingestion pipeline, review ratings schema, and [Family] exclusion
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { readFileSync } from "fs";
|
||||
import { resolve } from "path";
|
||||
import { parseOrderHTML, validateOrderTotals, resolveMerchantCategory } from "../../lib/order-ingestion";
|
||||
|
||||
describe("Order Ingestion - Unit Tests", () => {
|
||||
const fixturesDir = resolve(__dirname, "../fixtures/orders");
|
||||
|
||||
it("1. total_charged extracted, not subtotal — Mad Mex fixture => 14.64 (I3)", () => {
|
||||
const html = readFileSync(resolve(fixturesDir, "doordash-credits-restaurant.html"), "utf-8");
|
||||
const parsed = parseOrderHTML(html);
|
||||
expect(parsed.totals.total_charged).toBe(14.64);
|
||||
expect(parsed.totals.subtotal).toBe(22.10);
|
||||
});
|
||||
|
||||
it("2. Discount from structured HTML => 9.45, not 24.09 (I9)", () => {
|
||||
const html = readFileSync(resolve(fixturesDir, "doordash-credits-restaurant.html"), "utf-8");
|
||||
const parsed = parseOrderHTML(html);
|
||||
expect(parsed.totals.discounts).toBe(9.45);
|
||||
expect(parsed.totals.discounts).not.toBe(24.09);
|
||||
});
|
||||
|
||||
it("3. Arithmetic validation rejects a tampered fixture (totals ±$1)", () => {
|
||||
const html = readFileSync(resolve(fixturesDir, "doordash-credits-restaurant.html"), "utf-8");
|
||||
const parsed = parseOrderHTML(html);
|
||||
parsed.totals.total_charged = 100.00; // Tampered
|
||||
const isValid = validateOrderTotals(parsed);
|
||||
expect(isValid).toBe(false);
|
||||
});
|
||||
|
||||
it("4. Missing payment line => nulls, not a guess", () => {
|
||||
const html = "<div>Total Charged $15.00</div><div>Subtotal $15.00</div>";
|
||||
const parsed = parseOrderHTML(html);
|
||||
expect(parsed.payment.credits_amount).toBeNull();
|
||||
expect(parsed.payment.card_amount).toBeNull();
|
||||
});
|
||||
|
||||
it("5. Grocery fixture => groceries; assert category != 'dining' (I4)", () => {
|
||||
const html = readFileSync(resolve(fixturesDir, "doordash-credits-grocery.html"), "utf-8");
|
||||
const parsed = parseOrderHTML(html);
|
||||
const resolved = resolveMerchantCategory(parsed.merchant_name);
|
||||
expect(resolved.category).toBe("groceries");
|
||||
expect(resolved.category).not.toBe("dining");
|
||||
});
|
||||
|
||||
it("6. Unresolvable merchant => other + review flag, never dining", () => {
|
||||
const resolved = resolveMerchantCategory("Random Food Truck");
|
||||
expect(resolved.category).toBe("other");
|
||||
expect(resolved.flagReview).toBe(true);
|
||||
expect(resolved.category).not.toBe("dining");
|
||||
});
|
||||
|
||||
it("7. Rating scale accepts only 'again', 'fine', 'never'", () => {
|
||||
const validRatings = ["again", "fine", "never"];
|
||||
const invalidRating = "superb";
|
||||
expect(validRatings.includes("again")).toBe(true);
|
||||
expect(validRatings.includes(invalidRating)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user