- fn test_crud() {
- let conn = establish_unpooled_connection();
-
- let new_person = PersonForm {
- name: "thommy_comment_agg".into(),
- public_key: Some("pubkey".to_string()),
- ..PersonForm::default()
- };
-
- let inserted_person = Person::create(&conn, &new_person).unwrap();
-
- let another_person = PersonForm {
- name: "jerry_comment_agg".into(),
- public_key: Some("pubkey".to_string()),
- ..PersonForm::default()
- };
-
- let another_inserted_person = Person::create(&conn, &another_person).unwrap();
-
- let new_community = CommunityForm {
- name: "TIL_comment_agg".into(),
- title: "nada".to_owned(),
- public_key: Some("pubkey".to_string()),
- ..CommunityForm::default()
- };
-
- let inserted_community = Community::create(&conn, &new_community).unwrap();
-
- let new_post = PostForm {
- name: "A test post".into(),
- creator_id: inserted_person.id,
- community_id: inserted_community.id,
- ..PostForm::default()
- };
-
- let inserted_post = Post::create(&conn, &new_post).unwrap();
-
- let comment_form = CommentForm {
- content: "A test comment".into(),
- creator_id: inserted_person.id,
- post_id: inserted_post.id,
- ..CommentForm::default()
- };
-
- let inserted_comment = Comment::create(&conn, &comment_form).unwrap();
-
- let child_comment_form = CommentForm {
- content: "A test comment".into(),
- creator_id: inserted_person.id,
- post_id: inserted_post.id,
- parent_id: Some(inserted_comment.id),
- ..CommentForm::default()
- };
-
- let _inserted_child_comment = Comment::create(&conn, &child_comment_form).unwrap();
+ async fn test_crud() {
+ 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 new_person = PersonInsertForm::builder()
+ .name("thommy_comment_agg".into())
+ .public_key("pubkey".into())
+ .instance_id(inserted_instance.id)
+ .build();
+
+ let inserted_person = Person::create(pool, &new_person).await.unwrap();
+
+ let another_person = PersonInsertForm::builder()
+ .name("jerry_comment_agg".into())
+ .public_key("pubkey".into())
+ .instance_id(inserted_instance.id)
+ .build();
+
+ let another_inserted_person = Person::create(pool, &another_person).await.unwrap();
+
+ let new_community = CommunityInsertForm::builder()
+ .name("TIL_comment_agg".into())
+ .title("nada".to_owned())
+ .public_key("pubkey".to_string())
+ .instance_id(inserted_instance.id)
+ .build();
+
+ let inserted_community = Community::create(pool, &new_community).await.unwrap();
+
+ let new_post = PostInsertForm::builder()
+ .name("A test post".into())
+ .creator_id(inserted_person.id)
+ .community_id(inserted_community.id)
+ .build();
+
+ let inserted_post = Post::create(pool, &new_post).await.unwrap();
+
+ let comment_form = CommentInsertForm::builder()
+ .content("A test comment".into())
+ .creator_id(inserted_person.id)
+ .post_id(inserted_post.id)
+ .build();
+
+ let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
+
+ let child_comment_form = CommentInsertForm::builder()
+ .content("A test comment".into())
+ .creator_id(inserted_person.id)
+ .post_id(inserted_post.id)
+ .build();
+
+ let _inserted_child_comment =
+ Comment::create(pool, &child_comment_form, Some(&inserted_comment.path))
+ .await
+ .unwrap();