Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send query string parameters using supertest?

Tags:

supertest

I'm using supertest to send get query string parameters, how can I do that?

I tried

var imsServer = supertest.agent("https://example.com");  imsServer.get("/")   .send({     username: username,     password: password,     client_id: 'Test1',     scope: 'openid,TestID',     response_type: 'token',     redirect_uri: 'https://example.com/test.jsp'   })   .expect(200)    .end(function (err, res) {     // HTTP status should be 200     expect(res.status).to.be.equal(200);     body = res.body;     userId = body.userId;     accessToken = body.access_token;     done();   }); 

but that didn't send the parameters username, password, client_id as query string to the endpoint. Is there a way to send query string parameters using supertest?

like image 708
J K Avatar asked Oct 28 '16 16:10

J K


People also ask

How do I send a supertest query?

get("/") . send({ username: username, password: password, client_id: 'Test1', scope: 'openid,TestID', response_type: 'token', redirect_uri: 'https://example.com/test.jsp' }) . expect(200) . end(function (err, res) { // HTTP status should be 200 expect(res.

What is query string parameters in Adobe Analytics?

Query String & Processing Rule Query strings are parameters appended to page URL's and you can set them to whatever you want. Adobe Analytics processing rules allow you to set Adobe Analytics variables using rules instead of JavaScript code.


1 Answers

Although supertest is not that well documented, you can have a look into the tests/supertest.js.

There you have a test suite only for the query strings.

Something like:

request(app)   .get('/')   .query({ val: 'Test1' })   .expect(200, function(err, res) {     res.text.should.be.equal('Test1');     done();   }); 

Therefore:

.query({   key1: value1,   ...   keyN: valueN }) 

should work.

like image 65
Robert T. Avatar answered Sep 20 '22 15:09

Robert T.