add 400+ unit tests for domain and application layers
Some checks failed
CI / Check / Test (push) Has been cancelled
Some checks failed
CI / Check / Test (push) Has been cancelled
Extract ReviewLogger trait to decouple import/integrations from diary::log_review (cross-module coupling smell). Add in-memory fakes for all repository ports, enabling isolated testing of every use case module without a database. Coverage: domain+application 22% → 80%, 427 tests.
This commit is contained in:
68
crates/application/src/integrations/tests/get_tokens.rs
Normal file
68
crates/application/src/integrations/tests/get_tokens.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use domain::models::WatchEventSource;
|
||||
use domain::testing::InMemoryWebhookTokenRepository;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::integrations::{
|
||||
commands::GenerateWebhookTokenCommand, generate_token, get_tokens,
|
||||
queries::GetWebhookTokensQuery,
|
||||
};
|
||||
use crate::test_helpers::TestContextBuilder;
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_empty_when_no_tokens() {
|
||||
let tokens = InMemoryWebhookTokenRepository::new();
|
||||
let ctx = TestContextBuilder::new()
|
||||
.with_webhook_tokens(Arc::clone(&tokens) as _)
|
||||
.build();
|
||||
|
||||
let result = get_tokens::execute(
|
||||
&ctx,
|
||||
GetWebhookTokensQuery {
|
||||
user_id: Uuid::new_v4(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(result.is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_tokens_after_generate() {
|
||||
let tokens = InMemoryWebhookTokenRepository::new();
|
||||
let ctx = TestContextBuilder::new()
|
||||
.with_webhook_tokens(Arc::clone(&tokens) as _)
|
||||
.build();
|
||||
|
||||
let user_id = Uuid::new_v4();
|
||||
|
||||
generate_token::execute(
|
||||
&ctx,
|
||||
GenerateWebhookTokenCommand {
|
||||
user_id,
|
||||
provider: WatchEventSource::Jellyfin,
|
||||
label: None,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
generate_token::execute(
|
||||
&ctx,
|
||||
GenerateWebhookTokenCommand {
|
||||
user_id,
|
||||
provider: WatchEventSource::Plex,
|
||||
label: Some("living room".into()),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let result = get_tokens::execute(&ctx, GetWebhookTokensQuery { user_id })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result.len(), 2);
|
||||
}
|
||||
Reference in New Issue
Block a user