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

Using reqresnext to test a file upload #32

Open
ErisDS opened this issue Feb 5, 2022 · 4 comments
Open

Using reqresnext to test a file upload #32

ErisDS opened this issue Feb 5, 2022 · 4 comments

Comments

@ErisDS
Copy link
Collaborator

ErisDS commented Feb 5, 2022

I'm trying to figure out how to test a file upload endpoint using reqresnext :grim: Any idea if it's even possible?

I think it might depend on too many internals of http 🤔

@antongolub
Copy link
Owner

Sorry, no ideas right now ((

@antongolub
Copy link
Owner

antongolub commented Feb 15, 2022

I think we can take an API contract from https://www.npmjs.com/package/express-fileupload to synthesize body field.

new Request({
  files:
    foo: {
      name: 'foo',
      mimeType: 'foo',
      data: <path/buffer>,
      md5: ...
    },
    bar: {...}
})

Connection: keep-alive
Content-Type: multipart/form-data; boundary=---------------------------9051914041544843365972754266
Content-Length: 554

-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="text"

text default
-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="foo"; filename="foo.txt"
Content-Type: text/plain

Content of a.txt.

-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="bar"; filename="bar.txt"

@ErisDS
Copy link
Collaborator Author

ErisDS commented Mar 31, 2022

Hey @antongolub just wanted to say thank you for all your speedy responses to our issues and PRs :) We've written a test framework for testing express routes in Ghost that doesn't use http, instead it uses this module as its heart. It's really similar to supertest, but no http = faster :D

It lives here: https://github.com/TryGhost/framework/tree/main/packages/express-test and is totally agnostic, all the Ghost-specific code is in a wrapper in the Ghost repo.

It doesn't support file uploads yet as I've not had chance to look again since you replied, however I will at some point want to add that feature. Really grateful for your help, the commit bit & for this module ❤️

@antongolub
Copy link
Owner

@ErisDS,

Wow! Thank a lot for the feedback. I apreciate, that's truly motivating.

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

No branches or pull requests

2 participants