Kibou is a federated social networking server.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

activity.rs 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. use activity;
  2. use activitypub::activity as ap_activity;
  3. use database;
  4. use tests::utils::valid_local_dummy_create_activity;
  5. use tests::utils::valid_remote_dummy_create_activity;
  6. #[test]
  7. fn get_ap_object_by_id()
  8. {
  9. let database = database::establish_connection();
  10. let test_object_id = String::from("https://remote.tld/objects/9c247a1d-5aed-4a3f-922d-d88eaf9938a2");
  11. let test_actor = String::from("https://remote.tld/ben");
  12. activity::insert_activity(&database, ap_activity::create_internal_activity(valid_remote_dummy_create_activity(test_object_id.clone(), None), String::from("https://remote.tld/ben")));
  13. let result = activity::get_ap_object_by_id(&database, &test_object_id.clone());
  14. activity::delete_ap_object_by_id(&database, test_object_id);
  15. match result
  16. {
  17. Ok(_) => assert!(true),
  18. Err(_) => assert!(false, "AP object should exist")
  19. }
  20. }
  21. #[test]
  22. fn get_ap_object_replies_by_id()
  23. {
  24. let database = database::establish_connection();
  25. let test_object_id = String::from("https://remote.tld/objects/6d5fbaa1-82b6-434d-b885-7865b07deae4");
  26. let test_reply_id = String::from("https://remote.tld/objects/b7435596-e01d-4474-bbd5-b033149bddbf");
  27. activity::insert_activity(&database, ap_activity::create_internal_activity(valid_local_dummy_create_activity(test_object_id.clone(), None), String::from("https://example.tld/alyssa")));
  28. activity::insert_activity(&database, ap_activity::create_internal_activity(valid_remote_dummy_create_activity(test_reply_id.clone(), Some(test_object_id.clone())), String::from("https://remote.tld/ben")));
  29. match activity::get_ap_object_replies_by_id(&database, &test_object_id.clone())
  30. {
  31. Ok(activities) =>
  32. {
  33. activity::delete_ap_object_by_id(&database, test_object_id);
  34. activity::delete_ap_object_by_id(&database, test_reply_id.clone());
  35. assert_eq!(test_reply_id, activities[0].data["object"]["id"].as_str().unwrap().to_string())
  36. },
  37. Err(_) =>
  38. {
  39. activity::delete_ap_object_by_id(&database, test_object_id);
  40. activity::delete_ap_object_by_id(&database, test_reply_id);
  41. assert!(false, "Reply should exist")
  42. }
  43. }
  44. }
  45. #[test]
  46. fn count_ap_object_replies_by_id()
  47. {
  48. let database = database::establish_connection();
  49. let test_object_id = String::from("https://remote.tld/objects/1c34ec09-a2dd-4d43-85b9-2c63cbbd1f54");
  50. let test_reply_id = String::from("https://remote.tld/objects/a0aa8551-f1a7-4b83-9493-9dadc378599b");
  51. activity::insert_activity(&database, ap_activity::create_internal_activity(valid_local_dummy_create_activity(test_object_id.clone(), None), String::from("https://example.tld/alyssa")));
  52. activity::insert_activity(&database, ap_activity::create_internal_activity(valid_remote_dummy_create_activity(test_reply_id.clone(), Some(test_object_id.clone())), String::from("https://remote.tld/ben")));
  53. let reply_num: usize = activity::count_ap_object_replies_by_id(&database, &test_object_id.clone()).unwrap_or_else(|_| 0);
  54. activity::delete_ap_object_by_id(&database, test_object_id);
  55. activity::delete_ap_object_by_id(&database, test_reply_id);
  56. assert_eq!(reply_num, 1);
  57. }