jeudi 20 octobre 2016

How to stop stream-to-promise changing my original buffer

I'm using the stream-to-promise npm module to create the multipart/form-data payload in my jasmine test. My payload includes an image file as a buffer but when the payload is put through stream-to-promise it changes or corrupts my original image buffer in the payload somehow and so my tests are failing. Is there a way to prevent this?

  it('test /identity-verification/your-first-form-of-id POST with validation passing', function(done){
    var form = new FormData();
    var image = fs.createReadStream("image.png");
    streamToBuffer(image, function (err, buffer) {
      form.append('firstID', 'passport');
      form.append('firstIDImage', buffer);
      var headers = form.getHeaders();
      streamToPromise(form).then(function(payload) {
        var options = {
          method: 'POST',
          url: '/identity-verification/your-first-form-of-id',
          payload: payload,
          headers: headers
        };
        server.inject(options, function(response) {
          expect(response.statusCode).toBe(302);
          expect(response.headers.location).toMatch('/identity-verification/your-first-form-of-id/upload-successful');
          done();
        });
      });
    });
  });

The buffer in the payload after being put through stream-to-promise looks like this:

Aucun commentaire:

Enregistrer un commentaire