Fixing unit tests.

This commit is contained in:
Dessalines 2020-08-26 17:31:05 -04:00
parent 4db6585da0
commit 0b551ecbac
6 changed files with 15 additions and 8 deletions

View file

@ -61,7 +61,9 @@ impl Crud<CommentForm> for Comment {
} }
fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> { fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
// 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::*; use crate::schema::comment::dsl::*;
insert_into(comment) insert_into(comment)
.values(comment_form) .values(comment_form)

View file

@ -99,10 +99,10 @@ test('Delete a comment', async () => {
// let betaComment = searchBeta.comments[0]; // let betaComment = searchBeta.comments[0];
// Create a fake post, just to get the previous new post id // Create a fake post, just to get the previous new post id
let createdBetaPostJustToGetId = await createPost(beta, 2); let createdBetaPostJustToGetId = await createPost(beta, 2);
await delay();
let betaPost = await getPost(beta, createdBetaPostJustToGetId.post.id - 1); let betaPost = await getPost(beta, createdBetaPostJustToGetId.post.id - 1);
let betaComment = betaPost.comments[0]; let betaComment = betaPost.comments[0];
expect(betaComment.deleted).toBe(true); expect(betaComment.deleted).toBe(true);
await delay();
let undeleteCommentRes = await deleteComment( let undeleteCommentRes = await deleteComment(
alpha, alpha,

View file

@ -71,6 +71,7 @@ test('Remove community', async () => {
let communityA = search.communities[0]; let communityA = search.communities[0];
// TODO this fails currently, because no updates are pushed // TODO this fails currently, because no updates are pushed
// expect(communityA.removed).toBe(true); // expect(communityA.removed).toBe(true);
await delay();
// unremove // unremove
let unremoveCommunityRes = await removeCommunity( let unremoveCommunityRes = await removeCommunity(

View file

@ -1,3 +1,4 @@
jest.setTimeout(120000);
import { import {
alpha, alpha,
beta, beta,
@ -203,13 +204,14 @@ test('Delete a post', async () => {
let deletedPost = await deletePost(alpha, true, postRes.post); let deletedPost = await deletePost(alpha, true, postRes.post);
expect(deletedPost.post.deleted).toBe(true); expect(deletedPost.post.deleted).toBe(true);
await delay(); await delay(5000);
// Make sure lemmy beta sees post is deleted // Make sure lemmy beta sees post is deleted
let createFakeBetaPostToGetId = (await createPost(beta, 2)).post.id - 1; let createFakeBetaPostToGetId = (await createPost(beta, 2)).post.id - 1;
await delay(); await delay();
let betaPost = await getPost(beta, createFakeBetaPostToGetId); let betaPost = await getPost(beta, createFakeBetaPostToGetId);
expect(betaPost.post.deleted).toBe(true); expect(betaPost.post.deleted).toBe(true);
await delay();
// Undelete // Undelete
let undeletedPost = await deletePost(alpha, false, postRes.post); 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(); await delay();
let betaPost = await getPost(beta, createFakeBetaPostToGetId); let betaPost = await getPost(beta, createFakeBetaPostToGetId);
expect(betaPost.post.removed).toBe(false); expect(betaPost.post.removed).toBe(false);
await delay();
// Undelete // Undelete
let undeletedPost = await removePost(alpha, false, postRes.post); 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 // Get the id for beta
let createFakeBetaPostToGetId = (await createPost(beta, 2)).post.id - 1; let createFakeBetaPostToGetId = (await createPost(beta, 2)).post.id - 1;
await delay();
let betaPost = await getPost(beta, createFakeBetaPostToGetId); let betaPost = await getPost(beta, createFakeBetaPostToGetId);
await delay();
// The beta admin removes it (the community lives on beta) // The beta admin removes it (the community lives on beta)
let removePostRes = await removePost(beta, true, betaPost.post); let removePostRes = await removePost(beta, true, betaPost.post);
expect(removePostRes.post.removed).toBe(true); expect(removePostRes.post.removed).toBe(true);
await delay(); await delay(5000);
// Make sure lemmy alpha sees post is removed // Make sure lemmy alpha sees post is removed
let alphaPost = await getPost(alpha, postRes.post.id); let alphaPost = await getPost(alpha, postRes.post.id);
expect(alphaPost.post.removed).toBe(true); expect(alphaPost.post.removed).toBe(true);
await delay();
// Undelete // Undelete
let undeletedPost = await removePost(beta, false, betaPost.post); let undeletedPost = await removePost(beta, false, betaPost.post);

View file

@ -41,10 +41,9 @@ test('Update a private message', async () => {
let updatedContent = 'A jest test federated private message edited'; let updatedContent = 'A jest test federated private message edited';
let pmRes = await createPrivateMessage(alpha, recipient_id); let pmRes = await createPrivateMessage(alpha, recipient_id);
await delay();
let pmUpdated = await updatePrivateMessage(alpha, pmRes.message.id); let pmUpdated = await updatePrivateMessage(alpha, pmRes.message.id);
await delay();
expect(pmUpdated.message.content).toBe(updatedContent); expect(pmUpdated.message.content).toBe(updatedContent);
await delay();
let betaPms = await listPrivateMessages(beta); let betaPms = await listPrivateMessages(beta);
expect(betaPms.messages[0].content).toBe(updatedContent); expect(betaPms.messages[0].content).toBe(updatedContent);
@ -63,6 +62,7 @@ test('Delete a private message', async () => {
// no reason to show them // no reason to show them
let betaPms2 = await listPrivateMessages(beta); let betaPms2 = await listPrivateMessages(beta);
expect(betaPms2.messages.length).toBe(betaPms1.messages.length - 1); expect(betaPms2.messages.length).toBe(betaPms1.messages.length - 1);
await delay();
// Undelete // Undelete
let undeletedPmRes = await deletePrivateMessage( let undeletedPmRes = await deletePrivateMessage(

View file

@ -524,7 +524,7 @@ export async function followBeta(api: API): Promise<CommunityResponse> {
} }
} }
export const delay = (millis: number = 500) => export const delay = (millis: number = 1000) =>
new Promise((resolve, _reject) => { new Promise((resolve, _reject) => {
setTimeout(_ => resolve(), millis); setTimeout(_ => resolve(), millis);
}); });