+
+ #[tokio::test]
+ #[serial]
+ async fn follow() {
+ let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
+ let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+ .await
+ .unwrap();
+
+ let person_form_1 = PersonInsertForm::builder()
+ .name("erich".into())
+ .public_key("pubkey".to_string())
+ .instance_id(inserted_instance.id)
+ .build();
+ let person_1 = Person::create(pool, &person_form_1).await.unwrap();
+ let person_form_2 = PersonInsertForm::builder()
+ .name("michele".into())
+ .public_key("pubkey".to_string())
+ .instance_id(inserted_instance.id)
+ .build();
+ let person_2 = Person::create(pool, &person_form_2).await.unwrap();
+
+ let follow_form = PersonFollowerForm {
+ person_id: person_1.id,
+ follower_id: person_2.id,
+ pending: false,
+ };
+ let person_follower = PersonFollower::follow(pool, &follow_form).await.unwrap();
+ assert_eq!(person_1.id, person_follower.person_id);
+ assert_eq!(person_2.id, person_follower.follower_id);
+ assert!(!person_follower.pending);
+
+ let followers = PersonFollower::list_followers(pool, person_1.id)
+ .await
+ .unwrap();
+ assert_eq!(vec![person_2], followers);
+
+ let unfollow = PersonFollower::unfollow(pool, &follow_form).await.unwrap();
+ assert_eq!(1, unfollow);
+ }