use super::*;
fn ch() -> ChannelId {
crate::state::test_channel_id(7)
}
const AUTH: &str = "00000000000000000000000001";
const OTHER: &str = "00000000000000000000000002";
#[test]
fn post_updates_other_visible_increments_s3() {
let data = serde_json::json!({
"id": "00000000000000000000000099",
"type": "POST",
"userId": OTHER,
"viewers": ["all"],
});
let upd = post_updates(ch(), &data, AUTH, 1000);
assert_eq!(upd.unread_delta, 1, "他人可见消息 +1");
assert_eq!(
upd.unread_post_id.as_deref(),
Some("00000000000000000000000099")
);
assert_eq!(upd.msg_create_at, 1000);
assert!(!upd.last_post.is_empty());
}
#[test]
fn post_updates_self_message_zero_s3() {
let data = serde_json::json!({
"id": "00000000000000000000000099",
"type": "POST",
"userId": AUTH, "viewers": ["all"],
});
let upd = post_updates(ch(), &data, AUTH, 1000);
assert_eq!(upd.unread_delta, 0, "自己的消息 +0");
assert!(upd.unread_post_id.is_none());
assert!(!upd.last_post.is_empty());
}
#[test]
fn post_updates_invisible_zero_s3() {
let data = serde_json::json!({
"id": "00000000000000000000000099",
"type": "POST",
"userId": OTHER,
"viewers": ["00000000000000000000000003"], });
let upd = post_updates(ch(), &data, AUTH, 1000);
assert_eq!(upd.unread_delta, 0, "不可见 +0");
assert!(upd.unread_post_id.is_none());
assert!(upd.last_post.is_empty(), "不可见 → last_post 不写(空)");
}
#[test]
fn post_updates_user_snapshot_priority_s3() {
let data = serde_json::json!({
"id": "00000000000000000000000099",
"type": "POST",
"userId": OTHER, "userSnapshot": { "userId": AUTH }, "viewers": ["all"],
});
let upd = post_updates(ch(), &data, AUTH, 1000);
assert_eq!(upd.unread_delta, 0, "userSnapshot.userId==auth → 自己 +0");
}
#[test]
fn post_updates_notice_and_schedule_s3() {
let data = serde_json::json!({
"id": "00000000000000000000000099",
"type": "NOTICE",
"userId": OTHER,
"isSchedule": true,
});
let upd = post_updates(ch(), &data, AUTH, 1000);
assert!(!upd.last_post.is_empty(), "NOTICE 恒可见 → last_post 写");
assert!(upd.has_schedule_post);
assert_eq!(upd.unread_delta, 1, "NOTICE 他人 → +1");
}