#![allow(clippy::missing_assert_message)]
#![allow(clippy::tests_outside_test_module)]
#![allow(clippy::unwrap_used)]
use std::{convert::Infallible, sync::LazyLock};
use fetcher::{
actions::sink,
entry::{Entry, EntryId},
read_filter::MarkAsRead,
sinks::{
Sink,
message::{Message, MessageId},
},
sources::{Fetch, Source},
task::{Task, entry_to_msg_map::EntryToMsgMap},
};
static ENTRY_ID: LazyLock<EntryId> = LazyLock::new(|| EntryId::new("0".to_owned()).unwrap());
const MESSAGE_ID: i64 = 0;
struct DummySource;
struct DummySink;
impl Fetch for DummySource {
type Err = Infallible;
async fn fetch(&mut self) -> Result<Vec<Entry>, Self::Err> {
let entry = Entry::builder().reply_to(ENTRY_ID.clone()).build();
Ok(vec![entry])
}
}
impl MarkAsRead for DummySource {
type Err = Infallible;
async fn mark_as_read(&mut self, _id: &EntryId) -> Result<(), Self::Err> {
Ok(())
}
async fn set_read_only(&mut self) {}
}
impl Source for DummySource {}
impl Sink for DummySink {
type Err = Infallible;
async fn send(
&mut self,
_message: &Message,
reply_to: Option<&MessageId>,
_tag: Option<&str>,
) -> Result<Option<MessageId>, Self::Err> {
assert_eq!(reply_to.unwrap().0, MESSAGE_ID);
Ok(None)
}
}
#[tokio::test]
async fn reply_to() {
let mut entry_to_msg_map = EntryToMsgMap::default();
entry_to_msg_map
.insert(ENTRY_ID.to_owned(), MESSAGE_ID.into())
.await
.unwrap();
let mut task = Task::builder("reply_to_test")
.source(DummySource)
.action(sink(DummySink))
.entry_to_msg_map(entry_to_msg_map)
.build();
task.run().await.unwrap();
}