mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-12 21:15:53 +00:00
Add tests for ToApub, private message, remove update script
This commit is contained in:
parent
837c058843
commit
b4d06b7705
11 changed files with 109 additions and 31 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -315,6 +315,16 @@ version = "0.5.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "assert-json-diff"
|
||||||
|
version = "2.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "50f1c3703dd33532d7f0ca049168930e9099ecac238e23cf932f3a69c42f06da"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-mutex"
|
name = "async-mutex"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
|
@ -1811,6 +1821,7 @@ dependencies = [
|
||||||
"actix-rt",
|
"actix-rt",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"assert-json-diff",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"awc",
|
"awc",
|
||||||
"background-jobs",
|
"background-jobs",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# See the documentation for available config fields and descriptions:
|
# See the documentation for available config fields and descriptions:
|
||||||
# https://join-lemmy.org/docs/en/administration/configuration.html
|
# https://join-lemmy.org/docs/en/administration/configuration.html
|
||||||
{
|
{
|
||||||
hostname: lemmy-alphan
|
hostname: lemmy-alpha
|
||||||
federation: {
|
federation: {
|
||||||
enabled: true
|
enabled: true
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,3 +53,4 @@ html2md = "0.2.13"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serial_test = "0.5.1"
|
serial_test = "0.5.1"
|
||||||
|
assert-json-diff = "2.0.1"
|
|
@ -30,9 +30,9 @@
|
||||||
"id": "https://lemmy.ml/c/announcements",
|
"id": "https://lemmy.ml/c/announcements",
|
||||||
"inbox": "https://lemmy.ml/c/announcements/inbox",
|
"inbox": "https://lemmy.ml/c/announcements/inbox",
|
||||||
"mediaType": "text/html",
|
"mediaType": "text/html",
|
||||||
"moderators": "https://lemmy.ml/c/announcements/not_moderators",
|
"moderators": "https://lemmy.ml/c/announcements/moderators",
|
||||||
"name": "Announcements",
|
"name": "Announcements",
|
||||||
"outbox": "https://lemmy.ml/c/announcements/not_outbox",
|
"outbox": "https://lemmy.ml/c/announcements/outbox",
|
||||||
"preferredUsername": "announcements",
|
"preferredUsername": "announcements",
|
||||||
"publicKey": {
|
"publicKey": {
|
||||||
"id": "https://lemmy.ml/c/announcements#main-key",
|
"id": "https://lemmy.ml/c/announcements#main-key",
|
||||||
|
|
32
crates/apub/assets/lemmy-private-message.json
Normal file
32
crates/apub/assets/lemmy-private-message.json
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
{
|
||||||
|
"comments_enabled": {
|
||||||
|
"id": "pt:commentsEnabled",
|
||||||
|
"type": "sc:Boolean"
|
||||||
|
},
|
||||||
|
"matrixUserId": {
|
||||||
|
"id": "as:alsoKnownAs",
|
||||||
|
"type": "sc:Text"
|
||||||
|
},
|
||||||
|
"moderators": "as:moderators",
|
||||||
|
"pt": "https://join-lemmy.org#",
|
||||||
|
"sc": "http://schema.org#",
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"stickied": "as:stickied"
|
||||||
|
},
|
||||||
|
"https://w3id.org/security/v1"
|
||||||
|
],
|
||||||
|
"attributedTo": "https://lemmy.ml/u/nutomic",
|
||||||
|
"content": "test",
|
||||||
|
"id": "https://lemmy.ml/private_message/1621",
|
||||||
|
"mediaType": "text/html",
|
||||||
|
"published": "2021-10-21T10:13:14.597721+00:00",
|
||||||
|
"source": {
|
||||||
|
"content": "test",
|
||||||
|
"mediaType": "text/markdown"
|
||||||
|
},
|
||||||
|
"to": "https://queer.hacktivis.me/users/lanodan",
|
||||||
|
"type": "Note"
|
||||||
|
}
|
|
@ -316,6 +316,7 @@ mod tests {
|
||||||
community::ApubCommunity,
|
community::ApubCommunity,
|
||||||
tests::{file_to_json_object, init_context},
|
tests::{file_to_json_object, init_context},
|
||||||
};
|
};
|
||||||
|
use assert_json_diff::assert_json_include;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
async fn prepare_comment_test(url: &Url, context: &LemmyContext) {
|
async fn prepare_comment_test(url: &Url, context: &LemmyContext) {
|
||||||
|
@ -350,6 +351,9 @@ mod tests {
|
||||||
assert_eq!(comment.content.len(), 1063);
|
assert_eq!(comment.content.len(), 1063);
|
||||||
assert!(!comment.local);
|
assert!(!comment.local);
|
||||||
assert_eq!(request_counter, 0);
|
assert_eq!(request_counter, 0);
|
||||||
|
|
||||||
|
let to_apub = comment.to_apub(context.pool()).await.unwrap();
|
||||||
|
assert_json_include!(actual: json, expected: to_apub);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
|
|
|
@ -318,15 +318,22 @@ impl CommunityType for Community {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::objects::tests::{file_to_json_object, init_context};
|
use crate::objects::tests::{file_to_json_object, init_context};
|
||||||
|
use assert_json_diff::assert_json_include;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_fetch_lemmy_community() {
|
async fn test_fetch_lemmy_community() {
|
||||||
let json = file_to_json_object("assets/lemmy-community.json");
|
let context = init_context();
|
||||||
|
let mut json: Group = file_to_json_object("assets/lemmy-community.json");
|
||||||
|
let json_orig = json.clone();
|
||||||
|
// change these links so they dont fetch over the network
|
||||||
|
json.moderators = Some(Url::parse("https://lemmy.ml/c/announcements/not_moderators").unwrap());
|
||||||
|
json.outbox = Url::parse("https://lemmy.ml/c/announcements/not_outbox").unwrap();
|
||||||
|
|
||||||
let url = Url::parse("https://lemmy.ml/c/announcements").unwrap();
|
let url = Url::parse("https://lemmy.ml/c/announcements").unwrap();
|
||||||
let mut request_counter = 0;
|
let mut request_counter = 0;
|
||||||
let community = ApubCommunity::from_apub(&json, &init_context(), &url, &mut request_counter)
|
let community = ApubCommunity::from_apub(&json, &context, &url, &mut request_counter)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -337,5 +344,8 @@ mod tests {
|
||||||
assert_eq!(community.description.as_ref().unwrap().len(), 126);
|
assert_eq!(community.description.as_ref().unwrap().len(), 126);
|
||||||
// this makes two requests to the (intentionally) broken outbox/moderators collections
|
// this makes two requests to the (intentionally) broken outbox/moderators collections
|
||||||
assert_eq!(request_counter, 2);
|
assert_eq!(request_counter, 2);
|
||||||
|
|
||||||
|
let to_apub = community.to_apub(context.pool()).await.unwrap();
|
||||||
|
assert_json_include!(actual: json_orig, expected: to_apub);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,15 +271,17 @@ impl FromApub for ApubPerson {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::objects::tests::{file_to_json_object, init_context};
|
use crate::objects::tests::{file_to_json_object, init_context};
|
||||||
|
use assert_json_diff::assert_json_include;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_fetch_lemmy_person() {
|
async fn test_fetch_lemmy_person() {
|
||||||
|
let context = init_context();
|
||||||
let json = file_to_json_object("assets/lemmy-person.json");
|
let json = file_to_json_object("assets/lemmy-person.json");
|
||||||
let url = Url::parse("https://lemmy.ml/u/nutomic").unwrap();
|
let url = Url::parse("https://lemmy.ml/u/nutomic").unwrap();
|
||||||
let mut request_counter = 0;
|
let mut request_counter = 0;
|
||||||
let person = ApubPerson::from_apub(&json, &init_context(), &url, &mut request_counter)
|
let person = ApubPerson::from_apub(&json, &context, &url, &mut request_counter)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -289,6 +291,9 @@ mod tests {
|
||||||
assert!(!person.local);
|
assert!(!person.local);
|
||||||
assert!(person.bio.is_some());
|
assert!(person.bio.is_some());
|
||||||
assert_eq!(request_counter, 0);
|
assert_eq!(request_counter, 0);
|
||||||
|
|
||||||
|
let to_apub = person.to_apub(context.pool()).await.unwrap();
|
||||||
|
assert_json_include!(actual: json, expected: to_apub);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
|
|
|
@ -285,6 +285,7 @@ mod tests {
|
||||||
community::ApubCommunity,
|
community::ApubCommunity,
|
||||||
tests::{file_to_json_object, init_context},
|
tests::{file_to_json_object, init_context},
|
||||||
};
|
};
|
||||||
|
use assert_json_diff::assert_json_include;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
|
@ -312,7 +313,9 @@ mod tests {
|
||||||
assert_eq!(post.body.as_ref().unwrap().len(), 2144);
|
assert_eq!(post.body.as_ref().unwrap().len(), 2144);
|
||||||
assert!(!post.locked);
|
assert!(!post.locked);
|
||||||
assert!(post.stickied);
|
assert!(post.stickied);
|
||||||
// see comment in test_fetch_lemmy_community() about this
|
|
||||||
assert_eq!(request_counter, 0);
|
assert_eq!(request_counter, 0);
|
||||||
|
|
||||||
|
let to_apub = post.to_apub(context.pool()).await.unwrap();
|
||||||
|
assert_json_include!(actual: json, expected: to_apub);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,3 +199,39 @@ impl FromApub for ApubPrivateMessage {
|
||||||
Ok(pm.into())
|
Ok(pm.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::objects::tests::{file_to_json_object, init_context};
|
||||||
|
use assert_json_diff::assert_json_include;
|
||||||
|
use serial_test::serial;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
#[serial]
|
||||||
|
async fn test_fetch_lemmy_pm() {
|
||||||
|
let context = init_context();
|
||||||
|
let url = Url::parse("https://lemmy.ml/private_message/1621").unwrap();
|
||||||
|
let lemmy_person = file_to_json_object("assets/lemmy-person.json");
|
||||||
|
ApubPerson::from_apub(&lemmy_person, &context, &url, &mut 0)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let pleroma_person = file_to_json_object("assets/pleroma-person.json");
|
||||||
|
let pleroma_url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap();
|
||||||
|
ApubPerson::from_apub(&pleroma_person, &context, &pleroma_url, &mut 0)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let json = file_to_json_object("assets/lemmy-private-message.json");
|
||||||
|
let mut request_counter = 0;
|
||||||
|
let pm = ApubPrivateMessage::from_apub(&json, &context, &url, &mut request_counter)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(pm.ap_id.clone().into_inner(), url);
|
||||||
|
assert_eq!(pm.content.len(), 4);
|
||||||
|
assert_eq!(request_counter, 0);
|
||||||
|
|
||||||
|
let to_apub = pm.to_apub(context.pool()).await.unwrap();
|
||||||
|
assert_json_include!(actual: json, expected: to_apub);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
curl -H "Accept: application/activity+json" https://lemmy.ml/u/nutomic | jq -S \
|
|
||||||
> crates/apub/assets/lemmy-person.json
|
|
||||||
curl -H "Accept: application/activity+json" https://lemmy.ml/c/announcements | jq -S \
|
|
||||||
> crates/apub/assets/lemmy-community.json
|
|
||||||
# replace these collection links so that tests dont make any actual http requests
|
|
||||||
sed -i 's/https:\/\/lemmy.ml\/c\/announcements\/outbox/https:\/\/lemmy.ml\/c\/announcements\/not_outbox/g' crates/apub/assets/lemmy-community.json
|
|
||||||
sed -i 's/https:\/\/lemmy.ml\/c\/announcements\/moderators/https:\/\/lemmy.ml\/c\/announcements\/not_moderators/g' crates/apub/assets/lemmy-community.json
|
|
||||||
curl -H "Accept: application/activity+json" https://lemmy.ml/post/55143 | jq -S \
|
|
||||||
> crates/apub/assets/lemmy-post.json
|
|
||||||
curl -H "Accept: application/activity+json" https://lemmy.ml/comment/38741 | jq -S \
|
|
||||||
> crates/apub/assets/lemmy-comment.json
|
|
||||||
# replace attributed_to user, so that it takes the same one from above
|
|
||||||
sed -i 's/https:\/\/lemmy.ml\/u\/my_test/https:\/\/lemmy.ml\/u\/nutomic/g' crates/apub/assets/lemmy-comment.json
|
|
||||||
|
|
||||||
curl -H "Accept: application/activity+json" https://queer.hacktivis.me/users/lanodan | jq -S \
|
|
||||||
> crates/apub/assets/pleroma-person.json
|
|
||||||
curl -H "Accept: application/activity+json" https://queer.hacktivis.me/objects/8d4973f4-53de-49cd-8c27-df160e16a9c2 | jq -S \
|
|
||||||
> crates/apub/assets/pleroma-comment.json
|
|
||||||
# rewrite comment inReplyTo so that it refers to our post above (cause lemmy doesnt support standalone comments)
|
|
||||||
sed -i 's/https:\/\/pleroma.popolon.org\/objects\/bf84a0fb-2ec2-4dff-a1d9-6b573f94fb16/https:\/\/lemmy.ml\/post\/55143/g' crates/apub/assets/pleroma-comment.json
|
|
||||||
|
|
Loading…
Reference in a new issue