Thursday, 25 May 2017

I'm working on api-testing with supertest, chai and mocha, what are the different verbs I can use with post and get?

Also, what is the difference between ".set" and ".send"? I've used the body parser to send the data in primary as a part of the request body.

This is what I am specifying in my test:

var chai = require('chai');
var bodyParser = require('body-parser');
var supertest = require('supertest');
var express = require('express');
var expect = chai.expect;
chaiHttp = require('chai-http');

var primary = require('./data/file_containing_json_data.json');

describe('Is Server running?',function () {
        it('server is alive', function(done) {
        supertest('http://localhost:9999')
            .post('/api/messages')
            .set({"Content-type": "application/json"})
            .send(primary)
            .end(function(err, res) {
                console.log(res.body);
                expect(res.status).to.eq(202);
                done();
            });
        });
    });

**This is primary, the json file file_containing_json_data.json **

{
  "type": "conversationUpdate",
  "membersAdded": [
    {
      "id": "default-bot",
      "name": "Bot"
    }
  ],
  "channelId": "emulator",
  "recipient": {
    "id": "default-bot",
    "name": "Bot"
  },
  "conversation": {
    "id": "583l7c0m84bjedel4c"
  },
  "from": {
    "id": "default-user",
    "name": "User"
  },
  "serviceUrl": "http://127.0.0.1:49370"
}



via user2825406

No comments:

Post a Comment