mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-10-05 01:12:06 +00:00
test: share the handler/cache fixtures from ctx::test_support
The same fixtures were rebuilt in five test modules: a `CachedPost` literal in `link_cache.rs`, `handlers/urls.rs` and twice in `send/mod.rs`, the edit-before-forward prompt in `handlers/mod.rs` and `handlers/callback.rs`, and a scripted API error in both handler modules. They now live in `ctx::test_support` next to `TestStores`: - `cached_photo()` — the canonical cached post (photo + file id at `https://x.com/u/status/1`, key `twitter:1`); tests mutate the fields they care about, as the caption-quote test already did. - `seed_prompt(template, created_at)` + `PROMPT_ID`/`FORWARDED_ID` — the prompt record, the chat template and the bound forward channel. The two former copies differed only in which knob the caller set (the callback tests backdate it for the expiry cases, the reply tests pick the template), so the union is one helper. - `api_error(message)` — construction only; each test module keeps its own message constant, because the wording is what that module's path answers with (`chat not found` vs `message not found`). `send/mod.rs`'s `cached_sequence_cache_data()` (which re-extracted the post out of the task it had just built) is gone: the two settle tests seed the cache from the same builder the task uses. No behaviour change: the values are the ones the tests used except `file_id` (`AgAC-file-id` everywhere, asserted in the link-cache round-trip) and `sensitive` (the unasserted `true` in the link-cache fixture), and every test still passes unchanged. Verified: `cargo fmt`, `cargo clippy --workspace --all-targets --locked -- -D warnings` and `cargo test --workspace --locked` (180 passed, 14 ignored).
This commit is contained in:
@@ -754,7 +754,7 @@ mod tests {
|
||||
use super::post_send::build_edit_markup;
|
||||
use super::upload::sniff_ext;
|
||||
use super::*;
|
||||
use crate::ctx::test_support::TestStores;
|
||||
use crate::ctx::test_support::{TestStores, cached_photo};
|
||||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -1561,20 +1561,7 @@ mod tests {
|
||||
forward_channel_id: None,
|
||||
notify_chat_id: None,
|
||||
notify_message_id: None,
|
||||
cache_data: Some(CachedPost {
|
||||
url: "https://x.com/u/status/1".into(),
|
||||
caption: "cap".into(),
|
||||
title: "t".into(),
|
||||
content: "c".into(),
|
||||
author: "a".into(),
|
||||
author_url: "au".into(),
|
||||
tags: String::new(),
|
||||
sensitive: false,
|
||||
media: vec![CachedMedia {
|
||||
kind: CachedMediaKind::Photo,
|
||||
file_id: "AgAC-file-id".into(),
|
||||
}],
|
||||
}),
|
||||
cache_data: Some(cached_photo()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1584,10 +1571,7 @@ mod tests {
|
||||
let stores = TestStores::new();
|
||||
let ctx = stores.ctx(&sender);
|
||||
let task = cached_sequence_task();
|
||||
stores
|
||||
.link_cache()
|
||||
.put("twitter:1", &cached_sequence_cache_data())
|
||||
.await;
|
||||
stores.link_cache().put("twitter:1", &cached_photo()).await;
|
||||
|
||||
settle_task(&ctx, &task, Settled::Sent).await;
|
||||
|
||||
@@ -1607,10 +1591,7 @@ mod tests {
|
||||
let stores = TestStores::new();
|
||||
let ctx = stores.ctx(&sender);
|
||||
let task = cached_sequence_task();
|
||||
stores
|
||||
.link_cache()
|
||||
.put("twitter:1", &cached_sequence_cache_data())
|
||||
.await;
|
||||
stores.link_cache().put("twitter:1", &cached_photo()).await;
|
||||
|
||||
settle_task(&ctx, &task, Settled::Failed).await;
|
||||
|
||||
@@ -1623,14 +1604,4 @@ mod tests {
|
||||
"a permanently failed cached send must drop the entry"
|
||||
);
|
||||
}
|
||||
|
||||
fn cached_sequence_cache_data() -> CachedPost {
|
||||
match cached_sequence_task() {
|
||||
Task::SendMediaSequence {
|
||||
cache_data: Some(post),
|
||||
..
|
||||
} => post,
|
||||
other => panic!("expected a cached sequence task, got {other:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user