From 8ae4b405d0648465b378d64471073c8e35e74fcd Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 17 Dec 2024 11:29:43 +0100 Subject: [PATCH] fix api tests --- api_tests/package.json | 2 +- api_tests/pnpm-lock.yaml | 10 +++++----- api_tests/src/community.spec.ts | 3 +-- api_tests/src/follow.spec.ts | 1 - api_tests/src/image.spec.ts | 1 - api_tests/src/post.spec.ts | 1 - api_tests/src/shared.ts | 11 +++++------ api_tests/src/user.spec.ts | 25 +++---------------------- 8 files changed, 15 insertions(+), 39 deletions(-) diff --git a/api_tests/package.json b/api_tests/package.json index 5ace77ecf..f4c6dd285 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -28,7 +28,7 @@ "eslint": "^9.14.0", "eslint-plugin-prettier": "^5.1.3", "jest": "^29.5.0", - "lemmy-js-client": "0.20.0-image-api-rework.3", + "lemmy-js-client": "0.20.0-image-api-rework.5", "prettier": "^3.2.5", "ts-jest": "^29.1.0", "typescript": "^5.5.4", diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index 615a0ceca..509b5bb5e 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^29.5.0 version: 29.7.0(@types/node@22.9.0) lemmy-js-client: - specifier: 0.20.0-image-api-rework.3 - version: 0.20.0-image-api-rework.3 + specifier: 0.20.0-image-api-rework.5 + version: 0.20.0-image-api-rework.5 prettier: specifier: ^3.2.5 version: 3.3.3 @@ -1167,8 +1167,8 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - lemmy-js-client@0.20.0-image-api-rework.3: - resolution: {integrity: sha512-SB20z+WD2S821q05OxzI2Lkwq1BWBNWM6Xd1l1bqKL310CRSAG4lln26+j8bjWxMgl/fYTqre8KG6l1YDiV3+Q==} + lemmy-js-client@0.20.0-image-api-rework.5: + resolution: {integrity: sha512-fMbgLefWy7B1QtX6c7Y/CMAbV70tKpT5eDKsdnCtKhV1eB73pATKNPaFtrMuAYu9h13M6LDlry6mX7CeWuJb6Q==} leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} @@ -3077,7 +3077,7 @@ snapshots: kleur@3.0.3: {} - lemmy-js-client@0.20.0-image-api-rework.3: {} + lemmy-js-client@0.20.0-image-api-rework.5: {} leven@3.1.0: {} diff --git a/api_tests/src/community.spec.ts b/api_tests/src/community.spec.ts index 2bb092088..a0b9d41d2 100644 --- a/api_tests/src/community.spec.ts +++ b/api_tests/src/community.spec.ts @@ -16,7 +16,6 @@ import { followCommunity, banPersonFromCommunity, resolvePerson, - getSite, createPost, getPost, resolvePost, @@ -36,7 +35,7 @@ import { userBlockInstance, } from "./shared"; import { AdminAllowInstanceParams } from "lemmy-js-client/dist/types/AdminAllowInstanceParams"; -import { EditCommunity, EditSite, GetPosts } from "lemmy-js-client"; +import { EditCommunity, GetPosts } from "lemmy-js-client"; beforeAll(setupLogins); afterAll(unfollows); diff --git a/api_tests/src/follow.spec.ts b/api_tests/src/follow.spec.ts index 936ce2606..c447e14cd 100644 --- a/api_tests/src/follow.spec.ts +++ b/api_tests/src/follow.spec.ts @@ -5,7 +5,6 @@ import { setupLogins, resolveBetaCommunity, followCommunity, - getSite, waitUntil, beta, betaUrl, diff --git a/api_tests/src/image.spec.ts b/api_tests/src/image.spec.ts index fa22f271d..d25ab7f4c 100644 --- a/api_tests/src/image.spec.ts +++ b/api_tests/src/image.spec.ts @@ -18,7 +18,6 @@ import { epsilon, followCommunity, gamma, - getSite, imageFetchLimit, registerUser, resolveBetaCommunity, diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index 4158bbdc7..c7193c573 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -30,7 +30,6 @@ import { listPostReports, randomString, registerUser, - getSite, unfollows, resolveCommunity, waitUntil, diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index 1ed13d9cf..79614cb70 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -1,12 +1,11 @@ import { - AdminBlockInstanceParams, ApproveCommunityPendingFollower, BlockCommunity, BlockCommunityResponse, CommunityId, CommunityVisibility, CreatePrivateMessageReport, - DeleteImage, + DeleteImageParams, EditCommunity, GetCommunityPendingFollowsCountResponse, GetReplies, @@ -210,7 +209,9 @@ async function allowInstance(api: LemmyHttp, instance: string) { // Ignore errors from duplicate allows (because setup gets called for each test file) try { await api.adminAllowInstance(params); - } catch {} + } catch { + //console.log("Failed to allow instance"); + } } export async function createPost( @@ -715,7 +716,6 @@ export async function saveUserSettingsBio( export async function saveUserSettingsFederated( api: LemmyHttp, ): Promise { - let avatar = sampleImage; let banner = sampleImage; let bio = "a changed bio"; let form: SaveUserSettings = { @@ -724,7 +724,6 @@ export async function saveUserSettingsFederated( default_post_sort_type: "Hot", default_listing_type: "All", interface_language: "", - avatar, banner, display_name: "user321", show_avatars: false, @@ -947,7 +946,7 @@ export async function deleteAllImages(api: LemmyHttp) { Promise.all( imagesRes.images .map(image => { - const form: DeleteImage = { + const form: DeleteImageParams = { token: image.local_image.pictrs_delete_token, filename: image.local_image.pictrs_alias, }; diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index f7f80aecb..7a25e6140 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -21,7 +21,6 @@ import { fetchFunction, alphaImage, unfollows, - saveUserSettingsBio, getMyUser, getPersonDetails, } from "./shared"; @@ -182,42 +181,24 @@ test("Set a new avatar, old avatar is deleted", async () => { const upload_form1: UploadImage = { image: Buffer.from("test1"), }; - const upload1 = await alphaImage.uploadImage(upload_form1); - expect(upload1.url).toBeDefined(); - - let form1 = { - avatar: upload1.url, - }; - await saveUserSettings(alpha, form1); + await alpha.userUploadAvatar(upload_form1); const listMediaRes1 = await alphaImage.listMedia(); expect(listMediaRes1.images.length).toBe(1); const upload_form2: UploadImage = { image: Buffer.from("test2"), }; - const upload2 = await alphaImage.uploadImage(upload_form2); - expect(upload2.url).toBeDefined(); - - let form2 = { - avatar: upload2.url, - }; - await saveUserSettings(alpha, form2); + await alpha.userUploadAvatar(upload_form2); // make sure only the new avatar is kept const listMediaRes2 = await alphaImage.listMedia(); expect(listMediaRes2.images.length).toBe(1); // Upload that same form2 avatar, make sure it isn't replaced / deleted - await saveUserSettings(alpha, form2); + await alpha.userUploadAvatar(upload_form2); // make sure only the new avatar is kept const listMediaRes3 = await alphaImage.listMedia(); expect(listMediaRes3.images.length).toBe(1); - // Now try to save a user settings, with the icon missing, - // and make sure it doesn't clear the data, or delete the image - await saveUserSettingsBio(alpha); - let my_user = await getMyUser(alpha); - expect(my_user.local_user_view.person.avatar).toBe(upload2.url); - // make sure only the new avatar is kept const listMediaRes4 = await alphaImage.listMedia(); expect(listMediaRes4.images.length).toBe(1);