Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add api tests for image endpoints #4150

Merged
merged 12 commits into from
Nov 17, 2023
Merged

Add api tests for image endpoints #4150

merged 12 commits into from
Nov 17, 2023

Conversation

Nutomic
Copy link
Member

@Nutomic Nutomic commented Nov 13, 2023

Im starting to add some test cases for image endpoints to ensure that they are working properly (and keep working in the future). The code is rather messy because Im not familiar with js/ts, improvement suggestions welcome.

cc @SleeplessOne1917 @asonix

expect(upload.delete_url).toBeDefined();

// ensure that image download is working. theres probably a better way to do this
var downloadFileSync = require('download-file-sync');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you're importing this with require inside this test instead of importing it at the top like the rest of the dependencies?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I move it to the other imports at the top it throws error TS7016: Could not find a declaration file for module 'download-file-sync'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That shouldn't be a breaking error, but you can also probably do yarn add -D @types/download-file-sync

.gitignore Show resolved Hide resolved
let upload_image = fs.readFileSync("test.png");
let upload_form: UploadImage = {
image: upload_image,
auth: undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably needs the alpha auth.

Copy link
Member Author

@Nutomic Nutomic Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upload is successful, only delete fails. Anyway there is no reason to pass separate auth tokens for these calls anymore, as image endpoints use the same cookie/header auth as all other api endpoints.

LemmyNet/lemmy-js-client#212

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.19.0-alpha.17 is deployed now, and it should have that.

@Nutomic
Copy link
Member Author

Nutomic commented Nov 14, 2023

Btw with "lemmy-js-client": "0.19.0-alpha.16" there are various test failures like this, not sure how to fix:

Expected: "no_post_edit_allowed"
Received: [Error: no_post_edit_allowed]

@phiresky
Copy link
Collaborator

Expected: "no_post_edit_allowed"
Received: [Error: no_post_edit_allowed]

That's due to LemmyNet/lemmy-js-client#207 . The fix would be to compare e.message instead of e itself

@Nutomic
Copy link
Member Author

Nutomic commented Nov 15, 2023

Its passing now!

api_tests/src/image.spec.ts Outdated Show resolved Hide resolved
api_tests/src/image.spec.ts Outdated Show resolved Hide resolved
api_tests/src/image.spec.ts Outdated Show resolved Hide resolved
@SleeplessOne1917 SleeplessOne1917 merged commit 525359f into main Nov 17, 2023
2 checks passed
@SleeplessOne1917 SleeplessOne1917 deleted the image-api-tests branch November 17, 2023 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants