How to test multipart/form-data using chai - express

I have a signup endpoint in my project which works fine. However, I added profile image uploading field to the inputs to allow users upload images.
This works fine, my problem is with testing.
I'm trying to test using chai but I don't know how to parse image files to the POST request.
I discovered there's an attach() method which takes in file but how do I parse in the other fields.

Related

API request by fetch/axios makes PDF content bigger

I have a Nest.js generated PDF that I am trying to download in React frontend.
Everything works fine when I use Postman or any other API client to request the PDF directly on the endpoint, but when I make a fetch/axios request in my frontend with the same method as stated here (conversion to blob/arraybuffer), the overall content is bigger (fonts, assets) and the texts are not selectable before. I sense that it has to be due to the responseType: blob, but I have not found any other solution whatsoever anywhere.
Does anybody have any idea how to overcome this issue?
The desired result (not working images is ok)
The fetch/axios result

API requires HMAC authentication JMeter

I am getting error when setting up API test in Jmeter, same is working fine in POSTMAN.
Using HMAC authentication.
I have some basic knowledge of Jmeter new to the tool.
https://developer.firstdata.com/marketplace/api/authentication.html?shell#authentication.
Postman Pre-request Script
And Postman Header details
Postman API response is working fine.
Same as been work in Jmeter but I' getting response message as {"message":"HMAC signature cannot be verified, a valid date or x-date header is required for HMAC Authentication"}
I have added JSR223 PostProcessor and HTTP Header Manager.
and here are the details for both image attached below.
** JMeter - JSR223 PostProcessor**
JMeter HTTP Header Manager
Copying and pasting code from Postman won't work in JMeter because:
Postman is a browser extension and is capable of executing JavaScript and according to JMeter project main page:
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
If you're trying to run JavaScript code you need to choose the appropriate language from the dropdown
JMeter doesn't include CryptoJS library, you will need to download it and load before running the JavaScript
Since JMeter 3.1 it's recommended to use Groovy language for scripting as this option provides maximum performance especially when it comes to "heavy" cryptographic operations so I would recommend re-writing your code in Groovy
I see you like screenshots so I include an example implementation as a screenshot here:
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It

DownLoad VichBundle file Api Platform

I'm using API platform with VichBundle to store file on the back side and React Native on the Front side.
I've followed the documentation of API platform and the upload part is working well, but I don't know how to download the document.
When I make a GET request I have the entity with the url of the file but I can't do a GET request with this url because there is no route to this file.
Can somebody give me an exemple of how to download file with api platform and Vichbundle.
Thanks
If you are following Api Platfom's documentation your files should be uploaded to your project's ./app/public/media/ folder and available making an HTTP GET request to http(s)://<yourdomain>/public/media/<filename>.<extension>. Just open the URL in your browser.
To get the exact url query yout API for me mediaObject information (for example, /api/media_objects/{id}) and check the contentUrl property.

Capture JSON response through Selenium

I'm testing a webpage using Selenium (either IDE or webdriver). The webpage has a "search" function, basically just a GET call with params. The javascript also output to console the JSON returned from the search call, i.e. something like console.log(data). And I'm able to inspect the response data in Firefox console.
My question is: is there anyway I can capture this data from Firefox console in Selenium (so that I can further inspect and doing asserts)? Writing a direct GET request (eg, from Python) does not work since the search url is protected through a login page.
Thanks.
AFAIK Selenium doesnt provide any in built API/method to play with console.
You can redirect console output file and read from file.
Link: How to redirect Firefox console output to file.
It was possible at one point using Firebug. Not sure if it still works.

Upload files by GWT to Rails server

I am working on an app that I need to upload files using GWT in the client side, then a servlet receives the uploaded file. My problem that I need to pass the file from the servlet to the ruby on rails controller (on the same server with the servlet). Any suggestion is appreciated.
I am do not see any particular problem here. Just prepare somewhere a non GWT html page with a form, an input and submit that can send a file to your Rails server. Now everything that you need is to prepare the same form using GWT components. In a case of standart GWT components you can use FormPanel and FileUpload components. Be sure that encoding and method was correctly set (example for built-in GWT components):
FormPanel form = prepareForm();
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
// sending file
form.submit();