test_support/test_helpers -> tests/support; watched_at unified w/ domain test_watched_at (2024-03-15). Kept inline: users::diary_filter tests (feed_sort_to_direction_all_variants, paged_user_filter_builds_correctly) - pub(super) helpers in private module. Dropped stale never-compiled users/tests/get_users.rs (old execute signature).
92 lines
2.6 KiB
Rust
92 lines
2.6 KiB
Rust
use crate::support::generate_webhook_token_command;
|
|
use std::sync::Arc;
|
|
|
|
use domain::models::WatchEventSource;
|
|
use domain::ports::EventPublisher;
|
|
use domain::testing::{InMemoryStore, NoopEventPublisher};
|
|
use uuid::Uuid;
|
|
|
|
use application::integrations::commands::IngestWatchEventCommand;
|
|
use application::integrations::deps::{GenerateWebhookTokenDeps, IngestWatchEventDeps};
|
|
use application::integrations::{generate_token, ingest};
|
|
|
|
struct FakeParser;
|
|
|
|
impl domain::ports::MediaServerParser for FakeParser {
|
|
fn parse_playback_event(
|
|
&self,
|
|
_: &[u8],
|
|
) -> Result<Option<domain::models::ParsedPlaybackEvent>, domain::errors::DomainError> {
|
|
Ok(Some(domain::models::ParsedPlaybackEvent {
|
|
title: "Test".into(),
|
|
year: Some(2024),
|
|
tmdb_id: None,
|
|
imdb_id: None,
|
|
}))
|
|
}
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn ingests_watch_event() {
|
|
let tokens = InMemoryStore::new();
|
|
let watch_events = Arc::clone(&tokens);
|
|
let event_publisher: Arc<dyn EventPublisher> = NoopEventPublisher::new();
|
|
|
|
let user_id = Uuid::new_v4();
|
|
let generated = generate_token::execute(
|
|
&GenerateWebhookTokenDeps {
|
|
webhook_token: Arc::clone(&tokens) as _,
|
|
},
|
|
generate_webhook_token_command(user_id),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
let deps = IngestWatchEventDeps {
|
|
webhook_token: Arc::clone(&tokens) as _,
|
|
watch_event_command: Arc::clone(&watch_events) as _,
|
|
watch_event_query: Arc::clone(&watch_events) as _,
|
|
event_publisher: Arc::clone(&event_publisher),
|
|
};
|
|
|
|
let result = ingest::execute(
|
|
&deps,
|
|
IngestWatchEventCommand {
|
|
token: generated.token_plaintext,
|
|
raw_payload: vec![],
|
|
source: WatchEventSource::Jellyfin,
|
|
},
|
|
&FakeParser,
|
|
)
|
|
.await;
|
|
|
|
assert!(result.is_ok());
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn rejects_invalid_token() {
|
|
let tokens = InMemoryStore::new();
|
|
let watch_events = Arc::clone(&tokens);
|
|
let event_publisher: Arc<dyn EventPublisher> = NoopEventPublisher::new();
|
|
|
|
let deps = IngestWatchEventDeps {
|
|
webhook_token: Arc::clone(&tokens) as _,
|
|
watch_event_command: Arc::clone(&watch_events) as _,
|
|
watch_event_query: Arc::clone(&watch_events) as _,
|
|
event_publisher: Arc::clone(&event_publisher),
|
|
};
|
|
|
|
let result = ingest::execute(
|
|
&deps,
|
|
IngestWatchEventCommand {
|
|
token: "bad-token".into(),
|
|
raw_payload: vec![],
|
|
source: WatchEventSource::Jellyfin,
|
|
},
|
|
&FakeParser,
|
|
)
|
|
.await;
|
|
|
|
assert!(result.is_err());
|
|
}
|