(Almost) full test coverage

This commit is contained in:
Julia Lange 2026-01-26 15:00:52 -08:00
parent 0639c5ca12
commit 544e380835
Signed by: Julia
SSH key fingerprint: SHA256:5DJcfxa5/fKCYn57dcabJa2vN2e6eT0pBerYi5SUbto
8 changed files with 417 additions and 100 deletions

43
koucha/src/test_utils.rs Normal file
View file

@ -0,0 +1,43 @@
#![cfg(test)]
use crate::{
Adapter,
AdapterBuilder,
AdapterPool,
db::{
Channel,
Feed,
User,
}
};
use reqwest::Url;
pub const FEED1: &str = "https://example.com/feed";
pub const FEED2: &str = "https://example2.com/feed";
pub const USERNAME: &str = "Alice";
pub const USERNAME2: &str = "Bob";
pub const FEED_TITLE: &str = "My Feed!";
pub const FEED_TITLE2: &str = "My Second Feed!";
pub const CHANNEL_TITLE: &str = "My Channel!";
pub const CHANNEL_DESC: &str = "My Channel's description";
pub const ITEM_GUID: &str = "item-guid";
pub const ITEM_GUID2: &str = "item-guid2";
pub const ITEM_TITLE: &str = "My Item!";
pub const ITEM_DESC: &str = "My Item's description";
pub const ITEM_CONT: &str = "The content of my Item";
pub async fn setup_adapter() -> Adapter {
AdapterBuilder::new()
.database_url("sqlite::memory:")
.create().await.unwrap()
}
pub async fn setup_channel(pool: &AdapterPool) -> Channel {
let url = Url::parse(FEED1).unwrap();
Channel::get_or_create(pool, url).await.unwrap()
}
pub async fn setup_feed(pool: &AdapterPool) -> Feed {
let user = User::create(pool, USERNAME).await.unwrap();
Feed::create(pool, user.id(), FEED_TITLE).await.unwrap()
}