more new feature fixes + sentry logging
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Has been cancelled
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Has been cancelled
This commit is contained in:
@@ -54,23 +54,23 @@ describe('E2E Receipt Processing Journey', () => {
|
||||
afterAll(async () => {
|
||||
const pool = getPool();
|
||||
|
||||
// Clean up inventory items
|
||||
// Clean up inventory items (pantry_items table)
|
||||
if (createdInventoryIds.length > 0) {
|
||||
await pool.query('DELETE FROM public.user_inventory WHERE inventory_id = ANY($1::int[])', [
|
||||
await pool.query('DELETE FROM public.pantry_items WHERE pantry_item_id = ANY($1::bigint[])', [
|
||||
createdInventoryIds,
|
||||
]);
|
||||
}
|
||||
|
||||
// Clean up receipt items and receipts
|
||||
if (createdReceiptIds.length > 0) {
|
||||
await pool.query('DELETE FROM public.receipt_items WHERE receipt_id = ANY($1::int[])', [
|
||||
await pool.query('DELETE FROM public.receipt_items WHERE receipt_id = ANY($1::bigint[])', [
|
||||
createdReceiptIds,
|
||||
]);
|
||||
await pool.query(
|
||||
'DELETE FROM public.receipt_processing_logs WHERE receipt_id = ANY($1::int[])',
|
||||
'DELETE FROM public.receipt_processing_log WHERE receipt_id = ANY($1::bigint[])',
|
||||
[createdReceiptIds],
|
||||
);
|
||||
await pool.query('DELETE FROM public.receipts WHERE receipt_id = ANY($1::int[])', [
|
||||
await pool.query('DELETE FROM public.receipts WHERE receipt_id = ANY($1::bigint[])', [
|
||||
createdReceiptIds,
|
||||
]);
|
||||
}
|
||||
@@ -108,23 +108,35 @@ describe('E2E Receipt Processing Journey', () => {
|
||||
|
||||
// Step 3: Create a receipt directly in the database (simulating a completed upload)
|
||||
// In a real E2E test with full BullMQ setup, we would upload and wait for processing
|
||||
// Note: receipts table uses store_id (FK to stores) and total_amount_cents (integer cents)
|
||||
const pool = getPool();
|
||||
|
||||
// First, create or get a test store
|
||||
const storeResult = await pool.query(
|
||||
`INSERT INTO public.stores (name)
|
||||
VALUES ('E2E Test Store')
|
||||
ON CONFLICT (name) DO UPDATE SET name = EXCLUDED.name
|
||||
RETURNING store_id`,
|
||||
);
|
||||
const storeId = storeResult.rows[0].store_id;
|
||||
|
||||
const receiptResult = await pool.query(
|
||||
`INSERT INTO public.receipts (user_id, receipt_image_url, status, store_name, total_amount, transaction_date)
|
||||
VALUES ($1, '/uploads/receipts/e2e-test.jpg', 'completed', 'E2E Test Store', 49.99, '2024-01-15')
|
||||
`INSERT INTO public.receipts (user_id, receipt_image_url, status, store_id, total_amount_cents, transaction_date)
|
||||
VALUES ($1, '/uploads/receipts/e2e-test.jpg', 'completed', $2, 4999, '2024-01-15')
|
||||
RETURNING receipt_id`,
|
||||
[userId],
|
||||
[userId, storeId],
|
||||
);
|
||||
const receiptId = receiptResult.rows[0].receipt_id;
|
||||
createdReceiptIds.push(receiptId);
|
||||
|
||||
// Add receipt items
|
||||
// receipt_items uses: raw_item_description, quantity, price_paid_cents, status
|
||||
const itemsResult = await pool.query(
|
||||
`INSERT INTO public.receipt_items (receipt_id, raw_text, parsed_name, quantity, unit_price, total_price, status, added_to_inventory)
|
||||
`INSERT INTO public.receipt_items (receipt_id, raw_item_description, quantity, price_paid_cents, status)
|
||||
VALUES
|
||||
($1, 'MILK 2% 4L', 'Milk 2%', 1, 5.99, 5.99, 'matched', false),
|
||||
($1, 'BREAD WHITE', 'White Bread', 2, 2.49, 4.98, 'unmatched', false),
|
||||
($1, 'EGGS LARGE 12', 'Large Eggs', 1, 4.99, 4.99, 'matched', false)
|
||||
($1, 'MILK 2% 4L', 1, 599, 'matched'),
|
||||
($1, 'BREAD WHITE', 2, 498, 'unmatched'),
|
||||
($1, 'EGGS LARGE 12', 1, 499, 'matched')
|
||||
RETURNING receipt_item_id`,
|
||||
[receiptId],
|
||||
);
|
||||
@@ -146,7 +158,7 @@ describe('E2E Receipt Processing Journey', () => {
|
||||
(r: { receipt_id: number }) => r.receipt_id === receiptId,
|
||||
);
|
||||
expect(ourReceipt).toBeDefined();
|
||||
expect(ourReceipt.store_name).toBe('E2E Test Store');
|
||||
expect(ourReceipt.store_id).toBe(storeId);
|
||||
|
||||
// Step 5: View receipt details
|
||||
const detailResponse = await authedFetch(`/receipts/${receiptId}`, {
|
||||
@@ -295,11 +307,12 @@ describe('E2E Receipt Processing Journey', () => {
|
||||
await cleanupDb({ userIds: [otherUserId] });
|
||||
|
||||
// Step 14: Create a second receipt to test listing and filtering
|
||||
// Use the same store_id we created earlier, and use total_amount_cents (integer cents)
|
||||
const receipt2Result = await pool.query(
|
||||
`INSERT INTO public.receipts (user_id, receipt_image_url, status, store_name, total_amount)
|
||||
VALUES ($1, '/uploads/receipts/e2e-test-2.jpg', 'failed', 'Failed Store', 25.00)
|
||||
`INSERT INTO public.receipts (user_id, receipt_image_url, status, store_id, total_amount_cents)
|
||||
VALUES ($1, '/uploads/receipts/e2e-test-2.jpg', 'failed', $2, 2500)
|
||||
RETURNING receipt_id`,
|
||||
[userId],
|
||||
[userId, storeId],
|
||||
);
|
||||
createdReceiptIds.push(receipt2Result.rows[0].receipt_id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user