Add test for Like::build_undo07()

This commit is contained in:
Kitaiti Makoto 2022-04-24 07:03:06 +09:00
parent 4ea29d29a0
commit 3093f713ef

View file

@ -3,7 +3,12 @@ use crate::{
users::User, Connection, Error, Result, CONFIG,
};
use activitypub::activity;
use activitystreams::{activity::Like as Like07, iri_string::types::IriString, prelude::*};
use activitystreams::{
activity::{Like as Like07, Undo as Undo07},
base::AnyBase,
iri_string::types::IriString,
prelude::*,
};
use chrono::NaiveDateTime;
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use plume_common::activity_pub::{
@ -275,4 +280,35 @@ mod tests {
Ok(())
});
}
#[test]
fn build_undo07() {
let conn = db();
conn.test_transaction::<_, Error, _>(|| {
let (posts, _users, _blogs) = fill_database(&conn);
let post = &posts[0];
let user = &post.get_authors(&conn)?[0];
let like = Like::insert(&*conn, NewLike::new(post, user))?;
let act = like.build_undo07(&*conn)?;
let expected = json!({
"actor": "https://plu.me/@/admin/",
"cc": ["https://plu.me/@/admin/followers"],
"id": "https://plu.me/@/admin/like/https://plu.me/~/BlogName/testing#delete",
"object": {
"actor": "https://plu.me/@/admin/",
"cc": ["https://plu.me/@/admin/followers"],
"id": "https://plu.me/@/admin/like/https://plu.me/~/BlogName/testing",
"object": "https://plu.me/~/BlogName/testing",
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"type": "Like",
},
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"type": "Undo",
});
assert_json_eq!(to_value(act)?, expected);
Ok(())
});
}
}