Question

I'd like to write a test to post up some zipped data to a url as follows, but it doesn't work:

    zlib.gzip('foo_bar_data', function (err, buffer) {
        request(app)
            .post('/foo/bar')
            .set('Content-Encoding', 'gzip')
            .send(buffer)
            .expect(200)
            .end(function(err, res){
                if (err) return done(err);
                //various other validations here
                done();
            });
    });

I think the problem is that send doesn't accept a buffer. I'd still like to have the expect() and end() methods work though.

Was it helpful?

Solution

zlib.gzip('foo_bar_data', function (err, buffer) {
        var ra = request(app)
            .post('/foo/bar')
            .set('Content-Encoding', 'gzip');
        ra.write(buffer);
        ra.expect(200);
        ra.end(function(err, res){
                if (err) return done(err);
                //various other validations here
                done();
            });
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top