- fn test_crud() {
- let conn = &mut establish_unpooled_connection();
-
- let inserted_instance = Instance::create(conn, "my_domain.tld").unwrap();
-
- let creator_form = PersonInsertForm::builder()
- .name("activity_creator_ pm".into())
- .public_key("pubkey".to_string())
- .instance_id(inserted_instance.id)
- .build();
-
- let inserted_creator = Person::create(conn, &creator_form).unwrap();
-
- let ap_id: DbUrl = Url::parse(
- "https://enterprise.lemmy.ml/activities/delete/f1b5d57c-80f8-4e03-a615-688d552e946c",
- )
- .unwrap()
- .into();
- let test_json: Value = serde_json::from_str(
- r#"{
- "@context": "https://www.w3.org/ns/activitystreams",
- "id": "https://enterprise.lemmy.ml/activities/delete/f1b5d57c-80f8-4e03-a615-688d552e946c",
- "type": "Delete",
- "actor": "https://enterprise.lemmy.ml/u/riker",
- "to": "https://www.w3.org/ns/activitystreams#Public",
- "cc": [
- "https://enterprise.lemmy.ml/c/main/"
- ],
- "object": "https://enterprise.lemmy.ml/post/32"
- }"#,
- )
- .unwrap();
- let activity_form = ActivityInsertForm {
- ap_id: ap_id.clone(),
- data: test_json.to_owned(),
- local: Some(true),
- sensitive: Some(false),
- updated: None,
- };
-
- let inserted_activity = Activity::create(conn, &activity_form).unwrap();
+ async fn receive_activity_duplicate() {
+ let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
+ let ap_id: DbUrl = Url::parse("http://example.com/activity/531")
+ .unwrap()
+ .into();
+
+ // inserting activity for first time
+ let res = ReceivedActivity::create(pool, &ap_id).await;
+ assert!(res.is_ok());
+
+ let res = ReceivedActivity::create(pool, &ap_id).await;
+ assert!(res.is_err());
+ }