Capture running_balance from v2 API data.balance
This commit is contained in:
@@ -147,11 +147,14 @@ function processLogEntries($logEntries, $user, $insertStmt) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$runningBalance = isset($entry['data']['balance']) ? (int)$entry['data']['balance'] : null;
|
||||||
|
|
||||||
$insertStmt->bindValue(':id', $id);
|
$insertStmt->bindValue(':id', $id);
|
||||||
$insertStmt->bindValue(':user', $user);
|
$insertStmt->bindValue(':user', $user);
|
||||||
$insertStmt->bindValue(':timestamp', $timestamp);
|
$insertStmt->bindValue(':timestamp', $timestamp);
|
||||||
$insertStmt->bindValue(':description', $description);
|
$insertStmt->bindValue(':description', $description);
|
||||||
$insertStmt->bindValue(':amount', $amount);
|
$insertStmt->bindValue(':amount', $amount);
|
||||||
|
$insertStmt->bindValue(':running_balance', $runningBalance);
|
||||||
$insertStmt->execute();
|
$insertStmt->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,8 +253,8 @@ function fetchAndStoreLogPage($pdo, $user, $url) {
|
|||||||
validateApiResponse($responseData);
|
validateApiResponse($responseData);
|
||||||
|
|
||||||
$insertStmt = $pdo->prepare(
|
$insertStmt = $pdo->prepare(
|
||||||
'INSERT INTO vault (id, user, timestamp, description, amount) '
|
'INSERT INTO vault (id, user, timestamp, description, amount, running_balance) '
|
||||||
. 'VALUES (:id, :user, :timestamp, :description, :amount) '
|
. 'VALUES (:id, :user, :timestamp, :description, :amount, :running_balance) '
|
||||||
. 'ON CONFLICT(id) DO NOTHING'
|
. 'ON CONFLICT(id) DO NOTHING'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -73,13 +73,14 @@ $pdo->exec(
|
|||||||
user TEXT NOT NULL,
|
user TEXT NOT NULL,
|
||||||
timestamp INTEGER NOT NULL,
|
timestamp INTEGER NOT NULL,
|
||||||
description TEXT NOT NULL,
|
description TEXT NOT NULL,
|
||||||
amount REAL NOT NULL
|
amount REAL NOT NULL,
|
||||||
|
running_balance INTEGER
|
||||||
)'
|
)'
|
||||||
);
|
);
|
||||||
|
|
||||||
$insertStmt = $pdo->prepare(
|
$insertStmt = $pdo->prepare(
|
||||||
'INSERT INTO vault (id, user, timestamp, description, amount) '
|
'INSERT INTO vault (id, user, timestamp, description, amount, running_balance) '
|
||||||
. 'VALUES (:id, :user, :timestamp, :description, :amount) '
|
. 'VALUES (:id, :user, :timestamp, :description, :amount, :running_balance) '
|
||||||
. 'ON CONFLICT(id) DO NOTHING'
|
. 'ON CONFLICT(id) DO NOTHING'
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -100,7 +101,7 @@ $count = (int)$pdo->query('SELECT COUNT(*) FROM vault')->fetchColumn();
|
|||||||
assertSame(100, $count, 'row count');
|
assertSame(100, $count, 'row count');
|
||||||
|
|
||||||
// Spot-check first entry (newest, withdraw) and last (oldest, deposit).
|
// Spot-check first entry (newest, withdraw) and last (oldest, deposit).
|
||||||
$rows = $pdo->query('SELECT id, user, timestamp, description, amount FROM vault ORDER BY timestamp DESC')->fetchAll(PDO::FETCH_ASSOC);
|
$rows = $pdo->query('SELECT id, user, timestamp, description, amount, running_balance FROM vault ORDER BY timestamp DESC')->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
$first = $rows[0];
|
$first = $rows[0];
|
||||||
assertSame('c1pEDQ7jl3kuBHV4NqDI', $first['id'], 'first.id');
|
assertSame('c1pEDQ7jl3kuBHV4NqDI', $first['id'], 'first.id');
|
||||||
@@ -120,4 +121,10 @@ processLogEntries($fixture['log'], 'zarathos', $insertStmt);
|
|||||||
$count2 = (int)$pdo->query('SELECT COUNT(*) FROM vault')->fetchColumn();
|
$count2 = (int)$pdo->query('SELECT COUNT(*) FROM vault')->fetchColumn();
|
||||||
assertSame(100, $count2, 'row count after re-run');
|
assertSame(100, $count2, 'row count after re-run');
|
||||||
|
|
||||||
|
// round-trip the running_balance column from $entry['data']['balance']
|
||||||
|
$firstRunning = (int)$first['running_balance'];
|
||||||
|
$lastRunning = (int)$last['running_balance'];
|
||||||
|
assertSame(69235831, $firstRunning, 'first.running_balance');
|
||||||
|
assertSame(509622821, $lastRunning, 'last.running_balance');
|
||||||
|
|
||||||
echo "OK: processLogEntries v2 golden-file test passed (100 entries).\n";
|
echo "OK: processLogEntries v2 golden-file test passed (100 entries).\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user