javascript - How do I test a nodejs POST web service with file upload using request js and jasmine? -


i created web service nodejs (express) takes json file, reads , stores content document in mongodb.

the post route works fine. code looks this

var multipart = require('connect-multiparty'); var fs = require('fs'); router.post('/', multipartmiddleware, function(req, res) {   fs.readfile(req.files.swagger.path, 'utf8', function(err, data) {     req.body.swagger = json.parse(data);     .     .   }); }); 

basically, it's picking data json file in req.files , putting inside req.body object.

i need same thing done on jasmine spec file. i'm able physically test web service using postman need test through spec file using jasmine. now, i'd check if web-service throws 200 ok status, it's throwing 500

so far, jasmine-node test suite looks this

describe("post /", function() {  it("returns status code 200", function(done) {   var req = request.post(base_url, function(error, response, body) {         expect(response.statuscode).tobe(200);   });    var form = req.form();   form.append('file','<file_data>', {     filename : "sample.json",     contenttype : "text/plain"   });   console.log("form", form);    }); }); 

how upload files onto nodejs server programatically, can pick file req.files in spec?


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -