From 0b551ecbac838035cf42d91dd91a29d37deb4031 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 26 Aug 2020 17:31:05 -0400 Subject: [PATCH] Fixing unit tests. --- server/lemmy_db/src/comment.rs | 4 +++- ui/src/api_tests/comment.spec.ts | 2 +- ui/src/api_tests/community.spec.ts | 1 + ui/src/api_tests/post.spec.ts | 10 +++++++--- ui/src/api_tests/private_message.spec.ts | 4 ++-- ui/src/api_tests/shared.ts | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/server/lemmy_db/src/comment.rs b/server/lemmy_db/src/comment.rs index 99fa0d379..0e8ff50ae 100644 --- a/server/lemmy_db/src/comment.rs +++ b/server/lemmy_db/src/comment.rs @@ -61,7 +61,9 @@ impl Crud for Comment { } fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result { - // println!("creating {}", &comment_form.ap_id.as_ref().unwrap()); + if let Some(for_ap_id) = &comment_form.ap_id { + println!("creating {}", for_ap_id); + } use crate::schema::comment::dsl::*; insert_into(comment) .values(comment_form) diff --git a/ui/src/api_tests/comment.spec.ts b/ui/src/api_tests/comment.spec.ts index eabdb9634..f56f45243 100644 --- a/ui/src/api_tests/comment.spec.ts +++ b/ui/src/api_tests/comment.spec.ts @@ -99,10 +99,10 @@ test('Delete a comment', async () => { // let betaComment = searchBeta.comments[0]; // Create a fake post, just to get the previous new post id let createdBetaPostJustToGetId = await createPost(beta, 2); - await delay(); let betaPost = await getPost(beta, createdBetaPostJustToGetId.post.id - 1); let betaComment = betaPost.comments[0]; expect(betaComment.deleted).toBe(true); + await delay(); let undeleteCommentRes = await deleteComment( alpha, diff --git a/ui/src/api_tests/community.spec.ts b/ui/src/api_tests/community.spec.ts index 26f2182a4..bd498009a 100644 --- a/ui/src/api_tests/community.spec.ts +++ b/ui/src/api_tests/community.spec.ts @@ -71,6 +71,7 @@ test('Remove community', async () => { let communityA = search.communities[0]; // TODO this fails currently, because no updates are pushed // expect(communityA.removed).toBe(true); + await delay(); // unremove let unremoveCommunityRes = await removeCommunity( diff --git a/ui/src/api_tests/post.spec.ts b/ui/src/api_tests/post.spec.ts index 0abcfa2d2..525439936 100644 --- a/ui/src/api_tests/post.spec.ts +++ b/ui/src/api_tests/post.spec.ts @@ -1,3 +1,4 @@ +jest.setTimeout(120000); import { alpha, beta, @@ -203,13 +204,14 @@ test('Delete a post', async () => { let deletedPost = await deletePost(alpha, true, postRes.post); expect(deletedPost.post.deleted).toBe(true); - await delay(); + await delay(5000); // Make sure lemmy beta sees post is deleted let createFakeBetaPostToGetId = (await createPost(beta, 2)).post.id - 1; await delay(); let betaPost = await getPost(beta, createFakeBetaPostToGetId); expect(betaPost.post.deleted).toBe(true); + await delay(); // Undelete let undeletedPost = await deletePost(alpha, false, postRes.post); @@ -239,6 +241,7 @@ test('Remove a post from admin and community on different instance', async () => await delay(); let betaPost = await getPost(beta, createFakeBetaPostToGetId); expect(betaPost.post.removed).toBe(false); + await delay(); // Undelete let undeletedPost = await removePost(alpha, false, postRes.post); @@ -257,17 +260,18 @@ test('Remove a post from admin and community on same instance', async () => { // Get the id for beta let createFakeBetaPostToGetId = (await createPost(beta, 2)).post.id - 1; - await delay(); let betaPost = await getPost(beta, createFakeBetaPostToGetId); + await delay(); // The beta admin removes it (the community lives on beta) let removePostRes = await removePost(beta, true, betaPost.post); expect(removePostRes.post.removed).toBe(true); - await delay(); + await delay(5000); // Make sure lemmy alpha sees post is removed let alphaPost = await getPost(alpha, postRes.post.id); expect(alphaPost.post.removed).toBe(true); + await delay(); // Undelete let undeletedPost = await removePost(beta, false, betaPost.post); diff --git a/ui/src/api_tests/private_message.spec.ts b/ui/src/api_tests/private_message.spec.ts index 587f8c4dc..ac5a87859 100644 --- a/ui/src/api_tests/private_message.spec.ts +++ b/ui/src/api_tests/private_message.spec.ts @@ -41,10 +41,9 @@ test('Update a private message', async () => { let updatedContent = 'A jest test federated private message edited'; let pmRes = await createPrivateMessage(alpha, recipient_id); - await delay(); let pmUpdated = await updatePrivateMessage(alpha, pmRes.message.id); - await delay(); expect(pmUpdated.message.content).toBe(updatedContent); + await delay(); let betaPms = await listPrivateMessages(beta); expect(betaPms.messages[0].content).toBe(updatedContent); @@ -63,6 +62,7 @@ test('Delete a private message', async () => { // no reason to show them let betaPms2 = await listPrivateMessages(beta); expect(betaPms2.messages.length).toBe(betaPms1.messages.length - 1); + await delay(); // Undelete let undeletedPmRes = await deletePrivateMessage( diff --git a/ui/src/api_tests/shared.ts b/ui/src/api_tests/shared.ts index 7fc44bf69..b9d9a4786 100644 --- a/ui/src/api_tests/shared.ts +++ b/ui/src/api_tests/shared.ts @@ -524,7 +524,7 @@ export async function followBeta(api: API): Promise { } } -export const delay = (millis: number = 500) => +export const delay = (millis: number = 1000) => new Promise((resolve, _reject) => { setTimeout(_ => resolve(), millis); });