(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

View file

@ -97,32 +97,42 @@ impl Item {
#[cfg(test)]
mod tests {
use super::*;
use reqwest::Url;
use crate::{
Adapter,
AdapterBuilder,
db::{
Channel,
}
use crate::test_utils::{
ITEM_GUID, ITEM_TITLE, ITEM_DESC, ITEM_CONT,
setup_adapter,
setup_channel,
};
use chrono::TimeZone;
const FEED1: &str = "https://example.com/feed";
const ITEM_GUID: &str = "item-guid";
// UnparsedItem tests
#[test]
fn parse_unparsed_item() {
const ITEM_ID: i64 = 1;
const CHANNEL_ID: i64 = 1;
async fn setup_adapter() -> Adapter {
AdapterBuilder::new()
.database_url("sqlite::memory:")
.create().await.unwrap()
}
let date: DateTime<Utc> = Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap();
let raw_item = UnparsedItem {
id: ITEM_ID,
channel_id: CHANNEL_ID,
fetched_at: Some(date.to_rfc2822()),
title: Some(ITEM_TITLE.to_string()),
description: Some(ITEM_DESC.to_string()),
content: Some(ITEM_CONT.to_string()),
};
let item = raw_item.parse().unwrap();
assert_eq!(item.id.0, ITEM_ID);
assert_eq!(item.channel_id.0, CHANNEL_ID);
assert_eq!(item.fetched_at, Some(date));
assert_eq!(item.title, Some(ITEM_TITLE.to_string()));
assert_eq!(item.description, Some(ITEM_DESC.to_string()));
assert_eq!(item.content, Some(ITEM_CONT.to_string()));
async fn setup_channel(pool: &AdapterPool) -> Channel {
let url = Url::parse(FEED1).unwrap();
Channel::get_or_create(pool, url).await.unwrap()
}
// Item Tests
#[tokio::test]
pub async fn get_or_create_duplicate() {
async fn get_or_create_duplicate() {
let adapter = setup_adapter().await;
let pool = adapter.get_pool();
let channel = setup_channel(pool).await;