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

JSON content not handled properly. #21

Open
ggb667 opened this issue Mar 15, 2018 · 0 comments
Open

JSON content not handled properly. #21

ggb667 opened this issue Mar 15, 2018 · 0 comments

Comments

@ggb667
Copy link

ggb667 commented Mar 15, 2018

Doing:

const server = require("../../server/server");
const supertest = require('supertest');
const upr = require('supertest')(server);
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";//No CA for our certs.
...
        upr
          .post(apiPathInfo)
          .set('Accept', 'application/json')
          .send(requestBody)
          .end(function (err, res) {
            if (err) {
              return done(err);
            }
            res.statusCode.should.be.equal(201);
            done();

There is a bug in cache.js. If chunk on line 145 is a object with properties, the next call return new Buffer(chunk) will fail. You can test for json and fix it with

          if((chunk && typeof chunk === 'object' && chunk.constructor === Object)){
            for(var prop in chunk) {
              if (chunk.hasOwnProperty(prop)) {
                chunk = JSON.stringify(chunk);
              }
            }
          }

If you do, it exposes another bug - now the body of requests are showing as "body": {},
instead of having content (so the actual calls fail, even if they are not in the cache). Turning off replayer shows the calls completing normally.

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

1 participant