- React SPA: dashboard, data sources CRUD, widgets CRUD, layout builder, presets. TanStack Router + Query, shadcn/ui, Vite proxy to :3000 - wire media + rss adapters into polling loop, remove xtb source type - media adapter: read username/password from headers, proper subsonic auth - event handler: subscribe to LayoutChanged, push screen update to clients - fix clippy warnings across workspace (Default impls, collapsible ifs, redundant closures, is_none_or, unused imports)
60 lines
1.7 KiB
Rust
60 lines
1.7 KiB
Rust
use domain::{DataSource, DataSourceConfig, DataSourceType, DataSourceValidationError};
|
|
use std::time::Duration;
|
|
|
|
fn make_source(source_type: DataSourceType, url: Option<&str>, poll: Duration) -> DataSource {
|
|
DataSource {
|
|
id: 1,
|
|
name: "test".into(),
|
|
source_type,
|
|
poll_interval: poll,
|
|
config: DataSourceConfig {
|
|
url: url.map(Into::into),
|
|
headers: vec![],
|
|
api_key: None,
|
|
},
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn http_json_requires_url() {
|
|
let source = make_source(DataSourceType::HttpJson, None, Duration::from_secs(60));
|
|
let errors = source.validate();
|
|
assert!(errors.contains(&DataSourceValidationError::UrlRequired));
|
|
}
|
|
|
|
#[test]
|
|
fn webhook_does_not_allow_poll_interval() {
|
|
let source = make_source(DataSourceType::Webhook, None, Duration::from_secs(60));
|
|
let errors = source.validate();
|
|
assert!(errors.contains(&DataSourceValidationError::PollIntervalNotAllowed));
|
|
}
|
|
|
|
#[test]
|
|
fn webhook_with_zero_interval_is_valid() {
|
|
let source = make_source(DataSourceType::Webhook, None, Duration::ZERO);
|
|
let errors = source.validate();
|
|
assert!(errors.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn poll_based_source_requires_nonzero_interval() {
|
|
let source = make_source(
|
|
DataSourceType::Weather,
|
|
Some("https://api.weather.com"),
|
|
Duration::ZERO,
|
|
);
|
|
let errors = source.validate();
|
|
assert!(errors.contains(&DataSourceValidationError::PollIntervalRequired));
|
|
}
|
|
|
|
#[test]
|
|
fn valid_poll_source_has_no_errors() {
|
|
let source = make_source(
|
|
DataSourceType::Rss,
|
|
Some("https://feed.example.com"),
|
|
Duration::from_secs(300),
|
|
);
|
|
let errors = source.validate();
|
|
assert!(errors.is_empty());
|
|
}
|