test: move application tests to tests/
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).
This commit is contained in:
12
crates/application/tests/integrations/cleanup_test.rs
Normal file
12
crates/application/tests/integrations/cleanup_test.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use domain::testing::InMemoryStore;
|
||||
|
||||
use application::integrations::cleanup;
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_zero_when_nothing_to_clean() {
|
||||
let watch_events = InMemoryStore::new();
|
||||
|
||||
let count = cleanup::execute(watch_events).await.unwrap();
|
||||
|
||||
assert_eq!(count, 0);
|
||||
}
|
||||
315
crates/application/tests/integrations/confirm_test.rs
Normal file
315
crates/application/tests/integrations/confirm_test.rs
Normal file
@@ -0,0 +1,315 @@
|
||||
use crate::support::confirm_watch_events_command;
|
||||
use std::sync::Arc;
|
||||
|
||||
use domain::models::{WatchEvent, WatchEventSource};
|
||||
use domain::ports::{MovieCommand, WatchEventCommand};
|
||||
use domain::testing::{InMemoryStore, NoopEventPublisher};
|
||||
use domain::value_objects::UserId;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::support::NoopReviewLogger;
|
||||
use application::integrations::commands::{ConfirmWatchEventsCommand, WatchEventConfirmation};
|
||||
use application::integrations::confirm;
|
||||
use application::integrations::deps::ConfirmWatchEventsDeps;
|
||||
|
||||
fn noop_logger() -> Arc<dyn application::ports::ReviewLogger> {
|
||||
Arc::new(NoopReviewLogger)
|
||||
}
|
||||
|
||||
fn deps(
|
||||
watch_events: &Arc<InMemoryStore>,
|
||||
review_logger: Arc<dyn application::ports::ReviewLogger>,
|
||||
) -> ConfirmWatchEventsDeps {
|
||||
ConfirmWatchEventsDeps {
|
||||
watch_event_command: Arc::clone(watch_events) as _,
|
||||
watch_event_query: Arc::clone(watch_events) as _,
|
||||
review_logger,
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn confirms_watch_event_via_review_logger() {
|
||||
let watch_events = InMemoryStore::new();
|
||||
let uid = Uuid::new_v4();
|
||||
|
||||
let event = WatchEvent::new(
|
||||
UserId::from_uuid(uid),
|
||||
"Test Movie".into(),
|
||||
Some(2024),
|
||||
None,
|
||||
WatchEventSource::Jellyfin,
|
||||
chrono::Utc::now().naive_utc(),
|
||||
None,
|
||||
);
|
||||
let event_id = event.id().value();
|
||||
watch_events.save(&event).await.unwrap();
|
||||
|
||||
let result = confirm::execute(
|
||||
&deps(&watch_events, noop_logger()),
|
||||
confirm_watch_events_command(uid, event_id, 4),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn empty_confirmations_returns_zero() {
|
||||
let watch_events = InMemoryStore::new();
|
||||
|
||||
let result = confirm::execute(
|
||||
&deps(&watch_events, noop_logger()),
|
||||
ConfirmWatchEventsCommand {
|
||||
user_id: Uuid::new_v4(),
|
||||
confirmations: vec![],
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, 0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn confirms_event_with_external_metadata_id_and_no_movie_id() {
|
||||
let watch_events = InMemoryStore::new();
|
||||
let uid = Uuid::new_v4();
|
||||
|
||||
let event = WatchEvent::new(
|
||||
UserId::from_uuid(uid),
|
||||
"External Movie".into(),
|
||||
Some(2023),
|
||||
Some("tt1234567".into()),
|
||||
WatchEventSource::Jellyfin,
|
||||
chrono::Utc::now().naive_utc(),
|
||||
None,
|
||||
);
|
||||
let event_id = event.id().value();
|
||||
watch_events.save(&event).await.unwrap();
|
||||
|
||||
let result = confirm::execute(
|
||||
&deps(&watch_events, noop_logger()),
|
||||
ConfirmWatchEventsCommand {
|
||||
user_id: uid,
|
||||
confirmations: vec![WatchEventConfirmation {
|
||||
watch_event_id: event_id,
|
||||
rating: 3,
|
||||
comment: Some("Great film".into()),
|
||||
}],
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn rejects_other_users_event() {
|
||||
let watch_events = InMemoryStore::new();
|
||||
let owner = Uuid::new_v4();
|
||||
let intruder = Uuid::new_v4();
|
||||
|
||||
let event = WatchEvent::new(
|
||||
UserId::from_uuid(owner),
|
||||
"Movie".into(),
|
||||
None,
|
||||
None,
|
||||
WatchEventSource::Jellyfin,
|
||||
chrono::Utc::now().naive_utc(),
|
||||
None,
|
||||
);
|
||||
let event_id = event.id().value();
|
||||
watch_events.save(&event).await.unwrap();
|
||||
|
||||
let result = confirm::execute(
|
||||
&deps(&watch_events, noop_logger()),
|
||||
confirm_watch_events_command(intruder, event_id, 3),
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn fails_when_event_not_found() {
|
||||
let watch_events = InMemoryStore::new();
|
||||
|
||||
let result = confirm::execute(
|
||||
&deps(&watch_events, noop_logger()),
|
||||
confirm_watch_events_command(Uuid::new_v4(), Uuid::new_v4(), 4),
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn confirms_event_with_movie_id() {
|
||||
let watch_events = InMemoryStore::new();
|
||||
let events = NoopEventPublisher::new();
|
||||
let uid = Uuid::new_v4();
|
||||
let movie_uuid = Uuid::new_v4();
|
||||
|
||||
let event = WatchEvent::new(
|
||||
UserId::from_uuid(uid),
|
||||
"Movie With Id".into(),
|
||||
Some(2024),
|
||||
None,
|
||||
WatchEventSource::Jellyfin,
|
||||
chrono::Utc::now().naive_utc(),
|
||||
Some(domain::value_objects::MovieId::from_uuid(movie_uuid)),
|
||||
);
|
||||
let event_id = event.id().value();
|
||||
watch_events.save(&event).await.unwrap();
|
||||
|
||||
// Also seed movie repo so review_logger can find it
|
||||
let movies = domain::testing::InMemoryStore::new();
|
||||
let movie = domain::models::Movie::from_persistence(
|
||||
domain::value_objects::MovieId::from_uuid(movie_uuid),
|
||||
None,
|
||||
domain::value_objects::MovieTitle::new("Movie With Id".into()).unwrap(),
|
||||
domain::value_objects::ReleaseYear::new(2024).unwrap(),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
movies.upsert_movie(&movie).await.unwrap();
|
||||
|
||||
// Build a real review logger
|
||||
let reviews = domain::testing::InMemoryStore::new();
|
||||
let watchlist = domain::testing::InMemoryStore::new();
|
||||
let review_logger: Arc<dyn application::ports::ReviewLogger> =
|
||||
Arc::new(application::diary::review_logger::DefaultReviewLogger::new(
|
||||
Arc::clone(&movies) as _,
|
||||
Arc::clone(&movies) as _,
|
||||
Arc::clone(&reviews) as _,
|
||||
Arc::clone(&watchlist) as _,
|
||||
Arc::new(domain::testing::FakeMetadataClient) as _,
|
||||
Arc::clone(&events) as _,
|
||||
));
|
||||
|
||||
let result = confirm::execute(
|
||||
&deps(&watch_events, review_logger),
|
||||
confirm_watch_events_command(uid, event_id, 4),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn confirms_event_without_movie_id_and_without_external_metadata_id() {
|
||||
let watch_events = InMemoryStore::new();
|
||||
let uid = Uuid::new_v4();
|
||||
|
||||
let event = WatchEvent::new(
|
||||
UserId::from_uuid(uid),
|
||||
"Title Only Movie".into(),
|
||||
Some(2022),
|
||||
None,
|
||||
WatchEventSource::Jellyfin,
|
||||
chrono::Utc::now().naive_utc(),
|
||||
None,
|
||||
);
|
||||
let event_id = event.id().value();
|
||||
watch_events.save(&event).await.unwrap();
|
||||
|
||||
let result = confirm::execute(
|
||||
&deps(&watch_events, noop_logger()),
|
||||
ConfirmWatchEventsCommand {
|
||||
user_id: uid,
|
||||
confirmations: vec![WatchEventConfirmation {
|
||||
watch_event_id: event_id,
|
||||
rating: 5,
|
||||
comment: Some("Amazing".into()),
|
||||
}],
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn confirms_multiple_events() {
|
||||
let watch_events = InMemoryStore::new();
|
||||
let uid = Uuid::new_v4();
|
||||
|
||||
let event1 = WatchEvent::new(
|
||||
UserId::from_uuid(uid),
|
||||
"Movie One".into(),
|
||||
Some(2020),
|
||||
None,
|
||||
WatchEventSource::Jellyfin,
|
||||
chrono::Utc::now().naive_utc(),
|
||||
None,
|
||||
);
|
||||
let id1 = event1.id().value();
|
||||
|
||||
let event2 = WatchEvent::new(
|
||||
UserId::from_uuid(uid),
|
||||
"Movie Two".into(),
|
||||
Some(2021),
|
||||
None,
|
||||
WatchEventSource::Jellyfin,
|
||||
chrono::Utc::now().naive_utc(),
|
||||
None,
|
||||
);
|
||||
let id2 = event2.id().value();
|
||||
|
||||
watch_events.save(&event1).await.unwrap();
|
||||
watch_events.save(&event2).await.unwrap();
|
||||
|
||||
let result = confirm::execute(
|
||||
&deps(&watch_events, noop_logger()),
|
||||
ConfirmWatchEventsCommand {
|
||||
confirmations: vec![
|
||||
WatchEventConfirmation {
|
||||
watch_event_id: id1,
|
||||
rating: 3,
|
||||
comment: None,
|
||||
},
|
||||
WatchEventConfirmation {
|
||||
watch_event_id: id2,
|
||||
rating: 4,
|
||||
comment: None,
|
||||
},
|
||||
],
|
||||
..confirm_watch_events_command(uid, id1, 3)
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, 2);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn confirms_event_without_year() {
|
||||
let watch_events = InMemoryStore::new();
|
||||
let uid = Uuid::new_v4();
|
||||
|
||||
let event = WatchEvent::new(
|
||||
UserId::from_uuid(uid),
|
||||
"No Year Movie".into(),
|
||||
None,
|
||||
None,
|
||||
WatchEventSource::Jellyfin,
|
||||
chrono::Utc::now().naive_utc(),
|
||||
None,
|
||||
);
|
||||
let event_id = event.id().value();
|
||||
watch_events.save(&event).await.unwrap();
|
||||
|
||||
let result = confirm::execute(
|
||||
&deps(&watch_events, noop_logger()),
|
||||
confirm_watch_events_command(uid, event_id, 3),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, 1);
|
||||
}
|
||||
84
crates/application/tests/integrations/dismiss_test.rs
Normal file
84
crates/application/tests/integrations/dismiss_test.rs
Normal file
@@ -0,0 +1,84 @@
|
||||
use crate::support::dismiss_watch_events_command;
|
||||
use std::sync::Arc;
|
||||
|
||||
use domain::models::{WatchEvent, WatchEventSource};
|
||||
use domain::ports::WatchEventCommand;
|
||||
use domain::testing::InMemoryStore;
|
||||
use domain::value_objects::UserId;
|
||||
use uuid::Uuid;
|
||||
|
||||
use application::integrations::deps::DismissWatchEventsDeps;
|
||||
use application::integrations::dismiss;
|
||||
|
||||
fn deps(watch_events: &Arc<InMemoryStore>) -> DismissWatchEventsDeps {
|
||||
DismissWatchEventsDeps {
|
||||
watch_event_command: Arc::clone(watch_events) as _,
|
||||
watch_event_query: Arc::clone(watch_events) as _,
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn dismisses_empty_list_returns_zero() {
|
||||
let events = InMemoryStore::new();
|
||||
|
||||
let result = dismiss::execute(
|
||||
&deps(&events),
|
||||
dismiss_watch_events_command(Uuid::new_v4(), vec![]),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, 0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn fails_when_event_not_found() {
|
||||
let events = InMemoryStore::new();
|
||||
|
||||
let result = dismiss::execute(
|
||||
&deps(&events),
|
||||
dismiss_watch_events_command(Uuid::new_v4(), vec![Uuid::new_v4()]),
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn dismisses_existing_events() {
|
||||
let watch_events = InMemoryStore::new();
|
||||
let uid = Uuid::new_v4();
|
||||
let user_id = UserId::from_uuid(uid);
|
||||
|
||||
let e1 = WatchEvent::new(
|
||||
user_id.clone(),
|
||||
"Movie A".into(),
|
||||
Some(2024),
|
||||
None,
|
||||
WatchEventSource::Jellyfin,
|
||||
chrono::Utc::now().naive_utc(),
|
||||
None,
|
||||
);
|
||||
let e2 = WatchEvent::new(
|
||||
user_id,
|
||||
"Movie B".into(),
|
||||
Some(2023),
|
||||
None,
|
||||
WatchEventSource::Jellyfin,
|
||||
chrono::Utc::now().naive_utc(),
|
||||
None,
|
||||
);
|
||||
let id1 = e1.id().value();
|
||||
let id2 = e2.id().value();
|
||||
watch_events.save(&e1).await.unwrap();
|
||||
watch_events.save(&e2).await.unwrap();
|
||||
|
||||
let result = dismiss::execute(
|
||||
&deps(&watch_events),
|
||||
dismiss_watch_events_command(uid, vec![id1, id2]),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, 2);
|
||||
}
|
||||
33
crates/application/tests/integrations/generate_token_test.rs
Normal file
33
crates/application/tests/integrations/generate_token_test.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use crate::support::generate_webhook_token_command;
|
||||
use std::sync::Arc;
|
||||
|
||||
use domain::ports::WebhookTokenRepository;
|
||||
use domain::testing::InMemoryStore;
|
||||
use uuid::Uuid;
|
||||
|
||||
use application::integrations::deps::GenerateWebhookTokenDeps;
|
||||
use application::integrations::generate_token;
|
||||
|
||||
#[tokio::test]
|
||||
async fn generates_token_and_saves() {
|
||||
let tokens: Arc<dyn WebhookTokenRepository> = InMemoryStore::new();
|
||||
|
||||
let user_id = Uuid::new_v4();
|
||||
let result = generate_token::execute(
|
||||
&GenerateWebhookTokenDeps {
|
||||
webhook_token: Arc::clone(&tokens),
|
||||
},
|
||||
generate_webhook_token_command(user_id),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(!result.token_plaintext.is_empty());
|
||||
|
||||
let saved = tokens
|
||||
.list_by_user(&domain::value_objects::UserId::from_uuid(user_id))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(saved.len(), 1);
|
||||
assert_eq!(saved[0].id().value(), result.token.id().value());
|
||||
}
|
||||
56
crates/application/tests/integrations/get_queue_test.rs
Normal file
56
crates/application/tests/integrations/get_queue_test.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use chrono::Utc;
|
||||
use domain::models::{WatchEvent, WatchEventSource};
|
||||
use domain::ports::WatchEventCommand;
|
||||
use domain::testing::InMemoryStore;
|
||||
use domain::value_objects::UserId;
|
||||
use uuid::Uuid;
|
||||
|
||||
use application::integrations::deps::GetWatchQueueDeps;
|
||||
use application::integrations::{get_queue, queries::GetWatchQueueQuery};
|
||||
|
||||
fn deps(events: &Arc<InMemoryStore>) -> GetWatchQueueDeps {
|
||||
GetWatchQueueDeps {
|
||||
watch_event_query: Arc::clone(events) as _,
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_empty_when_no_events() {
|
||||
let events = InMemoryStore::new();
|
||||
|
||||
let result = get_queue::execute(
|
||||
&deps(&events),
|
||||
GetWatchQueueQuery {
|
||||
user_id: Uuid::new_v4(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(result.is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_pending_events() {
|
||||
let events = InMemoryStore::new();
|
||||
|
||||
let user_id = Uuid::new_v4();
|
||||
let event = WatchEvent::new(
|
||||
UserId::from_uuid(user_id),
|
||||
"Blade Runner 2049".into(),
|
||||
Some(2017),
|
||||
None,
|
||||
WatchEventSource::Jellyfin,
|
||||
Utc::now().naive_utc(),
|
||||
None,
|
||||
);
|
||||
events.save(&event).await.unwrap();
|
||||
|
||||
let result = get_queue::execute(&deps(&events), GetWatchQueueQuery { user_id })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result.len(), 1);
|
||||
}
|
||||
72
crates/application/tests/integrations/get_tokens_test.rs
Normal file
72
crates/application/tests/integrations/get_tokens_test.rs
Normal file
@@ -0,0 +1,72 @@
|
||||
use crate::support::generate_webhook_token_command;
|
||||
use std::sync::Arc;
|
||||
|
||||
use domain::models::WatchEventSource;
|
||||
use domain::ports::WebhookTokenRepository;
|
||||
use domain::testing::InMemoryStore;
|
||||
use uuid::Uuid;
|
||||
|
||||
use application::integrations::deps::{GenerateWebhookTokenDeps, GetWebhookTokensDeps};
|
||||
use application::integrations::{
|
||||
commands::GenerateWebhookTokenCommand, generate_token, get_tokens,
|
||||
queries::GetWebhookTokensQuery,
|
||||
};
|
||||
|
||||
fn generate_deps(tokens: &Arc<dyn WebhookTokenRepository>) -> GenerateWebhookTokenDeps {
|
||||
GenerateWebhookTokenDeps {
|
||||
webhook_token: Arc::clone(tokens),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_deps(tokens: &Arc<dyn WebhookTokenRepository>) -> GetWebhookTokensDeps {
|
||||
GetWebhookTokensDeps {
|
||||
webhook_token: Arc::clone(tokens),
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_empty_when_no_tokens() {
|
||||
let tokens: Arc<dyn WebhookTokenRepository> = InMemoryStore::new();
|
||||
|
||||
let result = get_tokens::execute(
|
||||
&get_deps(&tokens),
|
||||
GetWebhookTokensQuery {
|
||||
user_id: Uuid::new_v4(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(result.is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_tokens_after_generate() {
|
||||
let tokens: Arc<dyn WebhookTokenRepository> = InMemoryStore::new();
|
||||
|
||||
let user_id = Uuid::new_v4();
|
||||
|
||||
generate_token::execute(
|
||||
&generate_deps(&tokens),
|
||||
generate_webhook_token_command(user_id),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
generate_token::execute(
|
||||
&generate_deps(&tokens),
|
||||
GenerateWebhookTokenCommand {
|
||||
provider: WatchEventSource::Plex,
|
||||
label: Some("living room".into()),
|
||||
..generate_webhook_token_command(user_id)
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let result = get_tokens::execute(&get_deps(&tokens), GetWebhookTokensQuery { user_id })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result.len(), 2);
|
||||
}
|
||||
91
crates/application/tests/integrations/ingest_test.rs
Normal file
91
crates/application/tests/integrations/ingest_test.rs
Normal file
@@ -0,0 +1,91 @@
|
||||
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());
|
||||
}
|
||||
52
crates/application/tests/integrations/revoke_token_test.rs
Normal file
52
crates/application/tests/integrations/revoke_token_test.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use crate::support::generate_webhook_token_command;
|
||||
use std::sync::Arc;
|
||||
|
||||
use domain::ports::WebhookTokenRepository;
|
||||
use domain::testing::InMemoryStore;
|
||||
use uuid::Uuid;
|
||||
|
||||
use application::integrations::deps::{
|
||||
GenerateWebhookTokenDeps, GetWebhookTokensDeps, RevokeWebhookTokenDeps,
|
||||
};
|
||||
use application::integrations::{
|
||||
commands::RevokeWebhookTokenCommand, generate_token, get_tokens,
|
||||
queries::GetWebhookTokensQuery, revoke_token,
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn revokes_existing_token() {
|
||||
let tokens: Arc<dyn WebhookTokenRepository> = InMemoryStore::new();
|
||||
|
||||
let user_id = Uuid::new_v4();
|
||||
|
||||
let generated = generate_token::execute(
|
||||
&GenerateWebhookTokenDeps {
|
||||
webhook_token: Arc::clone(&tokens),
|
||||
},
|
||||
generate_webhook_token_command(user_id),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let token_id = generated.token.id().value();
|
||||
|
||||
revoke_token::execute(
|
||||
&RevokeWebhookTokenDeps {
|
||||
webhook_token: Arc::clone(&tokens),
|
||||
},
|
||||
RevokeWebhookTokenCommand { user_id, token_id },
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let remaining = get_tokens::execute(
|
||||
&GetWebhookTokensDeps {
|
||||
webhook_token: Arc::clone(&tokens),
|
||||
},
|
||||
GetWebhookTokensQuery { user_id },
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(remaining.is_empty());
|
||||
}
|
||||
Reference in New Issue
Block a user