- delete clippy.toml (too-many-arguments-threshold=20 hack) - ChannelRow/MediaItemRow/LibraryItemRow structs for from_persistence - SnapshotId/ActivityEventId/PlaybackRecordId newtypes - DomainError variants use ChannelId/UserId instead of Uuid - ActivityEvent.channel_id: Option<ChannelId> not Option<Uuid> - InMemory repos key on newtype IDs - AlgorithmicParams struct for schedule engine - update all adapters/application/presentation callers
76 lines
1.8 KiB
Rust
76 lines
1.8 KiB
Rust
use std::sync::Arc;
|
|
|
|
use domain::models::Channel;
|
|
use domain::testing::InMemoryChannelRepository;
|
|
use domain::value_objects::UserId;
|
|
|
|
use crate::config_snapshots::commands::SaveSnapshotCommand;
|
|
use crate::config_snapshots::deps::ConfigSnapshotDeps;
|
|
use crate::config_snapshots::save;
|
|
|
|
fn make_deps() -> (ConfigSnapshotDeps, Arc<InMemoryChannelRepository>) {
|
|
let repo = Arc::new(InMemoryChannelRepository::new());
|
|
let deps = ConfigSnapshotDeps {
|
|
channel_command: repo.clone(),
|
|
channel_query: repo.clone(),
|
|
};
|
|
(deps, repo)
|
|
}
|
|
|
|
async fn seed_channel(repo: &InMemoryChannelRepository) -> Channel {
|
|
let channel = Channel::new(UserId::generate(), "Test Channel", "UTC");
|
|
repo.channels
|
|
.lock()
|
|
.unwrap()
|
|
.insert(channel.id(), channel.clone());
|
|
channel
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn save_creates_snapshot() {
|
|
let (deps, repo) = make_deps();
|
|
let channel = seed_channel(&repo).await;
|
|
|
|
let snap = save::execute(
|
|
&deps,
|
|
SaveSnapshotCommand {
|
|
channel_id: channel.id(),
|
|
label: Some("v1".into()),
|
|
},
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(snap.channel_id(), channel.id());
|
|
assert_eq!(snap.label(), Some("v1"));
|
|
assert_eq!(snap.version_num(), 1);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn save_increments_version() {
|
|
let (deps, repo) = make_deps();
|
|
let channel = seed_channel(&repo).await;
|
|
|
|
save::execute(
|
|
&deps,
|
|
SaveSnapshotCommand {
|
|
channel_id: channel.id(),
|
|
label: None,
|
|
},
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
let snap2 = save::execute(
|
|
&deps,
|
|
SaveSnapshotCommand {
|
|
channel_id: channel.id(),
|
|
label: None,
|
|
},
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(snap2.version_num(), 2);
|
|
}
|