var expect = require('chai').expect;
var nock = require('nock');
var wrapi = require('../index');


describe("Misc. test cases", function() {
  before(function() {
    nock('http://api.a2zbooks.local/v1')

      .get('/hello')
      .query({echo: false})
      .reply(200, "Hi there!")

      .get('/bye')
      .query({echo: false})
      .reply(200, JSON.stringify({"response":"Good Bye!"}))

      .get('/echo')
      .query({echo: false})
      .reply(200, "Echo ...")

      .get('/echo')
      .query({echo: true})
      .reply(200, "Who are you?")
      ;

    this.client = new wrapi('http://api.a2zbooks.local/v1/', 
      {
        "hello": {
          "method": "GET",
          "path": "hello"
        },
        "bye": {
          "method": "GET",
          "path": "bye"
        },
        "echo": {
          "method": "GET",
          "path": "echo"
        }
      },
      {
        headers: {
          'User-Agent': 'wrapi-test'
        },
        qs: {
          echo: false
        }
      }
    );
  });

  after(function() {
     nock.cleanAll();
  });

  describe("Response types", function() {
    it("text response", function(done) {
      this.client.hello(function(err, data, res) {
        expect(err).to.equal(null);
        expect(data).to.equal("Hi there!");
        expect(res.statusCode).to.equal(200);
        done();
      });
    });

    it("json response as text", function(done) {
      this.client.bye(function(err, data, res) {
        expect(err).to.equal(null);
        expect(data).to.deep.equal({response:"Good Bye!"});
        expect(res.statusCode).to.equal(200);
        done();
      });
    });

  });

  describe("Query String Override", function() {
    it("query string default", function(done) {
      this.client.echo(function(err, data, res) {
        expect(err).to.equal(null);
        expect(data).to.equal("Echo ...");
        expect(res.statusCode).to.equal(200);
        done();
      });
    });

    it("query string override", function(done) {
      this.client.echo({echo:true}, function(err, data, res) {
        expect(err).to.equal(null);
        expect(data).to.equal("Who are you?");
        expect(res.statusCode).to.equal(200);
        done();
      });
    });

  });
});

@@ -199,16 +199,62 @@
 l/v1')%0A%0A
+      .get('')%0A      .reply(200, %22Welcome!%22)%0A%0A
       .g
@@ -262,24 +262,24 @@
 t('/hello')%0A
-
       .query
@@ -665,32 +665,112 @@
 /v1/', %0A      %7B%0A
+        %22welcome%22: %7B%0A          %22method%22: %22GET%22,%0A          %22path%22: %22%22%0A        %7D,%0A
         %22hello%22:
@@ -2363,12 +2363,1152 @@
 %0A%0A  %7D);%0A%7D);%0A
+%0Adescribe(%22Empty Path%22, function() %7B%0A  before(function() %7B%0A    nock('http://api.a2zbooks.local/v1')%0A%0A      .get('/')%0A      .reply(200, %22Welcome!%22)%0A%0A      .get('/')%0A      .query(%7Becho: true%7D)%0A      .reply(200, %22Hi there!%22)%0A      ;%0A%0A    this.client = new wrapi('http://api.a2zbooks.local/v1/', %0A      %7B%0A        %22welcome%22: %7B%0A          %22method%22: %22GET%22,%0A          %22path%22: %22%22%0A        %7D,%0A        %22hello%22: %7B%0A          %22method%22: %22GET%22,%0A          %22path%22: %22%22,%0A          %22query%22: %7B%0A            echo: true%0A          %7D%0A        %7D%0A      %7D,%0A      %7B%0A        headers: %7B%0A          'User-Agent': 'wrapi-test'%0A        %7D%0A      %7D%0A    );%0A  %7D);%0A%0A  after(function() %7B%0A     nock.cleanAll();%0A  %7D);%0A%0A  it(%22root%22, function(done) %7B%0A    this.client.welcome(function(err, data, res) %7B%0A      expect(err).to.equal(null);%0A      expect(data).to.equal(%22Welcome!%22);%0A      expect(res.statusCode).to.equal(200);%0A      done();%0A    %7D);%0A  %7D);%0A%0A  it(%22root with query%22, function(done) %7B%0A    this.client.hello(function(err, data, res) %7B%0A      expect(err).to.equal(null);%0A      expect(data).to.equal(%22Hi there!%22);%0A      expect(res.statusCode).to.equal(200);%0A      done();%0A    %7D);%0A  %7D);%0A%7D);

add testcase for empty path