fix api tests

This commit is contained in:
Felix Ableitner 2024-12-17 11:29:43 +01:00
parent 7c771d2113
commit 8ae4b405d0
8 changed files with 15 additions and 39 deletions

View file

@ -28,7 +28,7 @@
"eslint": "^9.14.0", "eslint": "^9.14.0",
"eslint-plugin-prettier": "^5.1.3", "eslint-plugin-prettier": "^5.1.3",
"jest": "^29.5.0", "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", "prettier": "^3.2.5",
"ts-jest": "^29.1.0", "ts-jest": "^29.1.0",
"typescript": "^5.5.4", "typescript": "^5.5.4",

View file

@ -30,8 +30,8 @@ importers:
specifier: ^29.5.0 specifier: ^29.5.0
version: 29.7.0(@types/node@22.9.0) version: 29.7.0(@types/node@22.9.0)
lemmy-js-client: lemmy-js-client:
specifier: 0.20.0-image-api-rework.3 specifier: 0.20.0-image-api-rework.5
version: 0.20.0-image-api-rework.3 version: 0.20.0-image-api-rework.5
prettier: prettier:
specifier: ^3.2.5 specifier: ^3.2.5
version: 3.3.3 version: 3.3.3
@ -1167,8 +1167,8 @@ packages:
resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==}
engines: {node: '>=6'} engines: {node: '>=6'}
lemmy-js-client@0.20.0-image-api-rework.3: lemmy-js-client@0.20.0-image-api-rework.5:
resolution: {integrity: sha512-SB20z+WD2S821q05OxzI2Lkwq1BWBNWM6Xd1l1bqKL310CRSAG4lln26+j8bjWxMgl/fYTqre8KG6l1YDiV3+Q==} resolution: {integrity: sha512-fMbgLefWy7B1QtX6c7Y/CMAbV70tKpT5eDKsdnCtKhV1eB73pATKNPaFtrMuAYu9h13M6LDlry6mX7CeWuJb6Q==}
leven@3.1.0: leven@3.1.0:
resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==}
@ -3077,7 +3077,7 @@ snapshots:
kleur@3.0.3: {} 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: {} leven@3.1.0: {}

View file

@ -16,7 +16,6 @@ import {
followCommunity, followCommunity,
banPersonFromCommunity, banPersonFromCommunity,
resolvePerson, resolvePerson,
getSite,
createPost, createPost,
getPost, getPost,
resolvePost, resolvePost,
@ -36,7 +35,7 @@ import {
userBlockInstance, userBlockInstance,
} from "./shared"; } from "./shared";
import { AdminAllowInstanceParams } from "lemmy-js-client/dist/types/AdminAllowInstanceParams"; 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); beforeAll(setupLogins);
afterAll(unfollows); afterAll(unfollows);

View file

@ -5,7 +5,6 @@ import {
setupLogins, setupLogins,
resolveBetaCommunity, resolveBetaCommunity,
followCommunity, followCommunity,
getSite,
waitUntil, waitUntil,
beta, beta,
betaUrl, betaUrl,

View file

@ -18,7 +18,6 @@ import {
epsilon, epsilon,
followCommunity, followCommunity,
gamma, gamma,
getSite,
imageFetchLimit, imageFetchLimit,
registerUser, registerUser,
resolveBetaCommunity, resolveBetaCommunity,

View file

@ -30,7 +30,6 @@ import {
listPostReports, listPostReports,
randomString, randomString,
registerUser, registerUser,
getSite,
unfollows, unfollows,
resolveCommunity, resolveCommunity,
waitUntil, waitUntil,

View file

@ -1,12 +1,11 @@
import { import {
AdminBlockInstanceParams,
ApproveCommunityPendingFollower, ApproveCommunityPendingFollower,
BlockCommunity, BlockCommunity,
BlockCommunityResponse, BlockCommunityResponse,
CommunityId, CommunityId,
CommunityVisibility, CommunityVisibility,
CreatePrivateMessageReport, CreatePrivateMessageReport,
DeleteImage, DeleteImageParams,
EditCommunity, EditCommunity,
GetCommunityPendingFollowsCountResponse, GetCommunityPendingFollowsCountResponse,
GetReplies, 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) // Ignore errors from duplicate allows (because setup gets called for each test file)
try { try {
await api.adminAllowInstance(params); await api.adminAllowInstance(params);
} catch {} } catch {
//console.log("Failed to allow instance");
}
} }
export async function createPost( export async function createPost(
@ -715,7 +716,6 @@ export async function saveUserSettingsBio(
export async function saveUserSettingsFederated( export async function saveUserSettingsFederated(
api: LemmyHttp, api: LemmyHttp,
): Promise<SuccessResponse> { ): Promise<SuccessResponse> {
let avatar = sampleImage;
let banner = sampleImage; let banner = sampleImage;
let bio = "a changed bio"; let bio = "a changed bio";
let form: SaveUserSettings = { let form: SaveUserSettings = {
@ -724,7 +724,6 @@ export async function saveUserSettingsFederated(
default_post_sort_type: "Hot", default_post_sort_type: "Hot",
default_listing_type: "All", default_listing_type: "All",
interface_language: "", interface_language: "",
avatar,
banner, banner,
display_name: "user321", display_name: "user321",
show_avatars: false, show_avatars: false,
@ -947,7 +946,7 @@ export async function deleteAllImages(api: LemmyHttp) {
Promise.all( Promise.all(
imagesRes.images imagesRes.images
.map(image => { .map(image => {
const form: DeleteImage = { const form: DeleteImageParams = {
token: image.local_image.pictrs_delete_token, token: image.local_image.pictrs_delete_token,
filename: image.local_image.pictrs_alias, filename: image.local_image.pictrs_alias,
}; };

View file

@ -21,7 +21,6 @@ import {
fetchFunction, fetchFunction,
alphaImage, alphaImage,
unfollows, unfollows,
saveUserSettingsBio,
getMyUser, getMyUser,
getPersonDetails, getPersonDetails,
} from "./shared"; } from "./shared";
@ -182,42 +181,24 @@ test("Set a new avatar, old avatar is deleted", async () => {
const upload_form1: UploadImage = { const upload_form1: UploadImage = {
image: Buffer.from("test1"), image: Buffer.from("test1"),
}; };
const upload1 = await alphaImage.uploadImage(upload_form1); await alpha.userUploadAvatar(upload_form1);
expect(upload1.url).toBeDefined();
let form1 = {
avatar: upload1.url,
};
await saveUserSettings(alpha, form1);
const listMediaRes1 = await alphaImage.listMedia(); const listMediaRes1 = await alphaImage.listMedia();
expect(listMediaRes1.images.length).toBe(1); expect(listMediaRes1.images.length).toBe(1);
const upload_form2: UploadImage = { const upload_form2: UploadImage = {
image: Buffer.from("test2"), image: Buffer.from("test2"),
}; };
const upload2 = await alphaImage.uploadImage(upload_form2); await alpha.userUploadAvatar(upload_form2);
expect(upload2.url).toBeDefined();
let form2 = {
avatar: upload2.url,
};
await saveUserSettings(alpha, form2);
// make sure only the new avatar is kept // make sure only the new avatar is kept
const listMediaRes2 = await alphaImage.listMedia(); const listMediaRes2 = await alphaImage.listMedia();
expect(listMediaRes2.images.length).toBe(1); expect(listMediaRes2.images.length).toBe(1);
// Upload that same form2 avatar, make sure it isn't replaced / deleted // 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 // make sure only the new avatar is kept
const listMediaRes3 = await alphaImage.listMedia(); const listMediaRes3 = await alphaImage.listMedia();
expect(listMediaRes3.images.length).toBe(1); 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 // make sure only the new avatar is kept
const listMediaRes4 = await alphaImage.listMedia(); const listMediaRes4 = await alphaImage.listMedia();
expect(listMediaRes4.images.length).toBe(1); expect(listMediaRes4.images.length).toBe(1);