- Add lib crate exposing modules for integration testing - Add dev-dependencies: tokio-test 0.4, tempfile - Refactor parse_csv_fields() as pure function for unit testing - Add field validation (minimum 16 fields required) - Fix repository last_insert_id using SELECT LAST_INSERT_ID() - Add 10 lib tests for CSV parsing and date formatting - Add 10 config tests for environment configuration - Add 7 import tests for CSV file parsing - Add 6 models tests for database structs - Add 12 repository tests for CRUD operations
81 lines
3.6 KiB
Rust
81 lines
3.6 KiB
Rust
//! Test fixtures for CSV parsing tests.
|
|
//!
|
|
//! AI AGENT NOTE: These fixtures provide sample data for testing CSV parsing
|
|
//! and other components without requiring real files.
|
|
|
|
/// Header row for CSV files.
|
|
pub const CSV_HEADER: &str = "Date\tBatch number\tAmount\tVolume\tPrice\tQuality\tQualityName\tCard number\tCard type\tCustomer number\tStation\tTerminal\tPump\tReceipt\tCard report group number\tControl number";
|
|
|
|
/// A valid CSV row with a known customer (fleet account).
|
|
///
|
|
/// AI AGENT NOTE: This represents a typical fleet customer transaction.
|
|
/// - Customer number: "1861" (known customer)
|
|
/// - Card number: Full card number (not anonymized)
|
|
/// - Amount: Positive (should be imported)
|
|
pub const CSV_ROW_KNOWN_CUSTOMER: &str = "2026-02-01 10:15:16\t409\t559.26\t35.85\t15.60\t1001\t95 Oktan\t7825017523017000642\t7825017523017000642\t1861\t97254\t1\t2\t000910\t1\t";
|
|
|
|
/// A valid CSV row with an anonymized card (retail customer).
|
|
///
|
|
/// AI AGENT NOTE: This represents a retail transaction.
|
|
/// - Customer number: "" (empty - anonymized)
|
|
/// - Card number: Contains asterisks (partially masked)
|
|
/// - Amount: Positive (should be imported)
|
|
pub const CSV_ROW_ANONYMIZED: &str = "2026-02-01 06:40:14\t409\t267.23\t17.13\t15.60\t1001\t95 Oktan\t554477******9952\t554477******9952\t\t97254\t1\t2\t000898\t4\t756969";
|
|
|
|
/// A CSV row with zero amount (should be filtered out).
|
|
///
|
|
/// AI AGENT NOTE: Zero amounts typically represent authorizations
|
|
/// that were never completed.
|
|
pub const CSV_ROW_ZERO_AMOUNT: &str = "2026-02-01 06:40:14\t409\t0.00\t0.00\t15.60\t1001\t95 Oktan\t554477******9952\t554477******9952\t\t97254\t1\t2\t000898\t4\t756969";
|
|
|
|
/// A CSV row with negative amount (should be filtered out).
|
|
///
|
|
/// AI AGENT NOTE: Negative amounts typically represent cancellations
|
|
/// or refunds.
|
|
pub const CSV_ROW_NEGATIVE_AMOUNT: &str = "2026-02-01 06:40:14\t409\t-50.00\t-3.00\t15.60\t1001\t95 Oktan\t7825017523017000642\t7825017523017000642\t1861\t97254\t1\t2\t000898\t1\t";
|
|
|
|
/// A CSV row with US date format (MM/DD/YYYY).
|
|
///
|
|
/// AI AGENT NOTE: Some source files may use US date format.
|
|
pub const CSV_ROW_US_DATE: &str = "02/01/2026 10:15:16 AM\t409\t559.26\t35.85\t15.60\t1001\t95 Oktan\t7825017523017000642\t7825017523017000642\t1861\t97254\t1\t2\t000910\t1\t";
|
|
|
|
/// Creates a multi-row CSV string for testing.
|
|
///
|
|
/// AI AGENT NOTE: Combines header and multiple data rows for
|
|
/// testing full CSV parsing.
|
|
pub fn create_test_csv(rows: &[&str]) -> String {
|
|
let mut csv = CSV_HEADER.to_string();
|
|
csv.push('\n');
|
|
for row in rows {
|
|
csv.push_str(row);
|
|
csv.push('\n');
|
|
}
|
|
csv
|
|
}
|
|
|
|
/// Sample CSV with mixed transactions (known, anonymized, etc.).
|
|
pub fn sample_csv_mixed() -> String {
|
|
create_test_csv(&[
|
|
CSV_ROW_ANONYMIZED,
|
|
CSV_ROW_KNOWN_CUSTOMER,
|
|
CSV_ROW_ZERO_AMOUNT,
|
|
])
|
|
}
|
|
|
|
/// Sample CSV with only known customer transactions.
|
|
pub fn sample_csv_known_only() -> String {
|
|
create_test_csv(&[
|
|
CSV_ROW_KNOWN_CUSTOMER,
|
|
"2026-02-01 10:32:18\t409\t508.40\t32.59\t15.60\t1001\t95 Oktan\t7825017523017000717\t7825017523017000717\t1861\t97254\t1\t2\t000912\t1\t",
|
|
"2026-02-01 10:57:33\t409\t174.41\t11.18\t15.60\t1001\t95 Oktan\t7825017523017001053\t7825017523017001053\t1980\t97254\t1\t1\t000913\t1\t",
|
|
])
|
|
}
|
|
|
|
/// Sample CSV with Diesel transaction.
|
|
pub fn sample_csv_diesel() -> String {
|
|
create_test_csv(&[
|
|
"2026-02-01 10:05:16\t409\t543.22\t31.40\t17.30\t4\tDiesel\t673706*********0155\t673706*********0155\t\t97254\t1\t2\t000909\t4\tD00824",
|
|
"2026-02-01 11:10:21\t409\t612.25\t35.39\t17.30\t4\tDiesel\t7825017523017000873\t7825017523017000873\t1866\t97254\t1\t1\t000916\t1\t",
|
|
])
|
|
}
|