From 8d782342a11689803b621cd3490af21e9d86764f Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 11 Apr 2024 16:02:37 +0200 Subject: [PATCH] test cleanup --- api_tests/src/image.spec.ts | 22 ++++++++++------------ api_tests/src/shared.ts | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/api_tests/src/image.spec.ts b/api_tests/src/image.spec.ts index a2759f8c5..6816bbb43 100644 --- a/api_tests/src/image.spec.ts +++ b/api_tests/src/image.spec.ts @@ -30,6 +30,7 @@ import { getPost, waitUntil, randomString, + createPostWithThumbnail, } from "./shared"; const downloadFileSync = require("download-file-sync"); @@ -264,13 +265,10 @@ test("Make regular post, and give it a custom thumbnail", async () => { // Use wikipedia since it has an opengraph image const wikipediaUrl = "https://wikipedia.org/"; - let post = await createPost( + let post = await createPostWithThumbnail( alphaImage, community.community_view.community.id, wikipediaUrl, - randomString(10), - randomString(5), - randomString(10), upload1.url!, ); @@ -281,8 +279,7 @@ test("Make regular post, and give it a custom thumbnail", async () => { ); expect(post.post_view.post.url).toBe(wikipediaUrl); expect(post.post_view.post.thumbnail_url).toBeDefined(); - - // Make sure the thumbnail got edited. + // Make sure it uses custom thumbnail expect(post.post_view.post.thumbnail_url).toBe(upload1.url); }); @@ -299,18 +296,19 @@ test("Create an image post, and make sure a custom thumbnail doesnt overwrite it const community = await createCommunity(alphaImage); - const post = await createPost( + let post = await createPostWithThumbnail( alphaImage, community.community_view.community.id, - upload1.url, - "https://example.com/", - randomString(10), - randomString(5), + upload1.url!, upload2.url!, ); + post = await waitUntil( + () => getPost(alphaImage, post.post_view.post.id), + p => p.post_view.post.thumbnail_url != undefined, + ); expect(post.post_view.post.url).toBe(upload1.url); - // Make sure the new custom thumbnail is ignored, and doesn't overwrite the image post expect(post.post_view.post.url).toBe(upload1.url); + // Make sure the custom thumbnail is ignored expect(post.post_view.post.thumbnail_url).toBe( post.post_view.post.thumbnail_url, ); diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index 600fb67a6..57f5ff39f 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -228,6 +228,21 @@ export async function editPost( return api.editPost(form); } +export async function createPostWithThumbnail( + api: LemmyHttp, + community_id: number, + url: string, + custom_thumbnail: string, +): Promise { + let form: CreatePost = { + name: randomString(10), + url, + community_id, + custom_thumbnail, + }; + return api.createPost(form); +} + export async function deletePost( api: LemmyHttp, deleted: boolean,