strings not used internally10

This commit is contained in:
Priec
2026-09-07 10:17:06 +02:00
parent e4364e1c44
commit 042993fafc
14 changed files with 417 additions and 44 deletions

View File

@@ -71,9 +71,14 @@ pub(crate) async fn load_ecb_page(
batches: status
.batches
.into_iter()
.map(|batch| ImportBatchView {
.map(|batch| Ok(ImportBatchView {
batch_id: batch.batch_id,
status: batch.status,
status: match crate::ecb::ImportBatchStatus::try_from(batch.status) {
Ok(status @ (crate::ecb::ImportBatchStatus::Running
| crate::ecb::ImportBatchStatus::Succeeded
| crate::ecb::ImportBatchStatus::Failed)) => status,
_ => return Err(LoadError::Backend(format!("Invalid import batch status: {}", batch.status))),
},
requested_from: batch.requested_from,
requested_through: batch.requested_through,
endpoint: batch.endpoint,
@@ -83,7 +88,7 @@ pub(crate) async fn load_ecb_page(
observation_count: batch.observation_count,
inserted_observation_count: batch.inserted_observation_count,
error_message: batch.error_message,
})
.collect(),
}))
.collect::<Result<Vec<_>, LoadError>>()?,
})
}

View File

@@ -77,7 +77,7 @@ fn from_now(locale: Locale, raw: &str) -> Option<String> {
/// One import attempt, as the audit log recorded it.
pub(crate) struct ImportBatchView {
pub batch_id: i64,
pub status: String,
pub status: crate::ecb::ImportBatchStatus,
pub requested_from: String,
pub requested_through: String,
pub endpoint: String,
@@ -91,15 +91,15 @@ pub(crate) struct ImportBatchView {
impl ImportBatchView {
pub(crate) fn succeeded(&self) -> bool {
self.status == "succeeded"
self.status == crate::ecb::ImportBatchStatus::Succeeded
}
pub(crate) fn running(&self) -> bool {
self.status == "running"
self.status == crate::ecb::ImportBatchStatus::Running
}
pub(crate) fn failed(&self) -> bool {
self.status == "failed"
self.status == crate::ecb::ImportBatchStatus::Failed
}
pub(crate) fn started(&self) -> String {

View File

@@ -63,10 +63,10 @@ mod tests {
use super::*;
use crate::pages::admin::ecb::state::ImportBatchView;
fn batch(id: i64, status: &str) -> ImportBatchView {
fn batch(id: i64, status: crate::ecb::ImportBatchStatus) -> ImportBatchView {
ImportBatchView {
batch_id: id,
status: status.to_string(),
status,
requested_from: "2026-08-10".to_string(),
requested_through: "2026-08-12".to_string(),
endpoint: "https://data.ecb.europa.eu/...".to_string(),
@@ -87,7 +87,7 @@ mod tests {
days_behind: 0,
import_running: false,
next_import_at: "2026-08-13T15:00:00Z".to_string(),
batches: vec![batch(9, "succeeded")],
batches: vec![batch(9, crate::ecb::ImportBatchStatus::Succeeded)],
covered_currencies: vec!["CZK".to_string(), "USD".to_string()],
transactions_postable_through: Some("2026-08-13".to_string()),
statements_postable_through: Some("2026-08-12".to_string()),
@@ -143,8 +143,8 @@ mod tests {
#[test]
fn historical_failures_are_collapsed_as_technical_history() {
let mut page = healthy_page();
page.batches.push(batch(8, "failed"));
page.batches.push(batch(7, "failed"));
page.batches.push(batch(8, crate::ecb::ImportBatchStatus::Failed));
page.batches.push(batch(7, crate::ecb::ImportBatchStatus::Failed));
let html = render_page(&page);
@@ -196,7 +196,7 @@ mod tests {
fn a_running_import_polls_until_it_finishes() {
let mut page = healthy_page();
page.import_running = true;
page.batches.insert(0, batch(10, "running"));
page.batches.insert(0, batch(10, crate::ecb::ImportBatchStatus::Running));
let html = render_page(&page);
assert!(!html.contains("Template error"), "{html}");
@@ -219,13 +219,13 @@ mod tests {
let mut page = healthy_page();
page.healthy = false;
page.batches = vec![ImportBatchView {
status: "failed".to_string(),
status: crate::ecb::ImportBatchStatus::Failed,
completed_at: None,
verified_through_date: None,
observation_count: None,
inserted_observation_count: None,
error_message: Some("the ECB endpoint returned 503".to_string()),
..batch(11, "failed")
..batch(11, crate::ecb::ImportBatchStatus::Failed)
}];
let html = render_page(&page);