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

describe("Default options", function() {
  before(function() {
    nock('http://api.a2zbooks.local/v1')
      .get('/books')
      .reply(200, [
        {id:1, name:"<NAME>"},
        {id:2, name:"Odyssey"}
      ])
      
      .get('/books/1')
      .reply(200, {id:1, name:"<NAME>"})
      
      .get('/books/2')
      .reply(404, {id:2, message:"Not found"})

      ;

    this.client = new wrapi('http://api.a2zbooks.local/v1/');
    var t = this.client.register("list", {
          "method" : "GET",
          "path": "books"
        });

    this.client.register("item", {
          "method" : "GET",
          "path": "books/:id"
        });

  });

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

  describe("GETs", function() {
    it("list", function(done) {
      this.client.list(function (err, data, res) {
        expect(err).to.equal(null);
        expect(data).to.deep.equal([
          {id:1, name:"<NAME>"},
          {id:2, name:"Odyssey"}
        ]);
        expect(res.statusCode).to.equal(200);
        done();
      });
    });


    it("valid item", function(done) {
      this.client.item(1, function (err, data, res) {
        expect(err).to.equal(null);
        expect(data).to.deep.equal(
          {id:1, name:"<NAME>"}
        );
        expect(res.statusCode).to.equal(200);
        done();
      });
    });

    it("invalid item", function(done) {
      this.client.item(2, function (err, data, res) {
        expect(err).to.equal(null);
        expect(data).to.deep.equal(
          {id:2, message:"Not found"}
        );
        expect(res.statusCode).to.equal(404);
        done();
      });
    });
    
  });
});


describe("Custom catchHTTP4xx5xx", function() {
  before(function() {
    nock('http://api.a2zbooks.local/v1')
      .get('/books')
      .reply(200, [
        {id:1, name:"<NAME>"},
        {id:2, name:"Odyssey"}
      ])
      
      .get('/books/1')
      .reply(200, {id:1, name:"<NAME>"})
      
      .get('/books/2')
      .reply(404, {id:2, message:"Not found"})

      ;

    this.client = new wrapi('http://api.a2zbooks.local/v1/',
      {},
      {
        catchHTTP4xx5xx: true
      });
    var t = this.client.register("list", {
          "method" : "GET",
          "path": "books"
        });

    this.client.register("item", {
          "method" : "GET",
          "path": "books/:id"
        });

  });

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

  describe("GETs", function() {
    it("list", function(done) {
      this.client.list(function (err, data, res) {
        expect(err).to.equal(null);
        expect(data).to.deep.equal([
          {id:1, name:"<NAME>"},
          {id:2, name:"Odyssey"}
        ]);
        expect(res.statusCode).to.equal(200);
        done();
      });
    });


    it("valid item", function(done) {
      this.client.item(1, function (err, data, res) {
        expect(err).to.equal(null);
        expect(data).to.deep.equal(
          {id:1, name:"<NAME>"}
        );
        expect(res.statusCode).to.equal(200);
        done();
      });
    });

    it("invalid item", function(done) {
      this.client.item(2, function (err, data, res) {
        expect(err).to.deep.equal(
          {id:2, message:"Not found"}
        );
        expect(res.statusCode).to.equal(404);
        done();
      });
    });
    
  });
});<commit_msg>test case for empty 404 response<commit_after>var expect = require('chai').expect;
var nock = require('nock');
var wrapi = require('../index');
var http = require('http');

describe("Default options", function() {
  before(function() {
    nock('http://api.a2zbooks.local/v1')
      .get('/books')
      .reply(200, [
        {id:1, name:"<NAME>"},
        {id:2, name:"Odyssey"}
      ])

      .get('/books/1')
      .reply(200, {id:1, name:"<NAME>"})

      .get('/books/2')
      .reply(404, {id:2, message:"Not found"})

      ;

    this.client = new wrapi('http://api.a2zbooks.local/v1/');
    var t = this.client.register("list", {
          "method" : "GET",
          "path": "books"
        });

    this.client.register("item", {
          "method" : "GET",
          "path": "books/:id"
        });

  });

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

  describe("GETs", function() {
    it("list", function(done) {
      this.client.list(function (err, data, res) {
        expect(err).to.equal(null);
        expect(data).to.deep.equal([
          {id:1, name:"<NAME>"},
          {id:2, name:"Odyssey"}
        ]);
        expect(res.statusCode).to.equal(200);
        done();
      });
    });


    it("valid item", function(done) {
      this.client.item(1, function (err, data, res) {
        expect(err).to.equal(null);
        expect(data).to.deep.equal(
          {id:1, name:"<NAME>"}
        );
        expect(res.statusCode).to.equal(200);
        done();
      });
    });

    it("invalid item", function(done) {
      this.client.item(2, function (err, data, res) {
        expect(err).to.equal(null);
        expect(data).to.deep.equal(
          {id:2, message:"Not found"}
        );
        expect(res.statusCode).to.equal(404);
        done();
      });
    });

  });
});


describe("Custom catchHTTP4xx5xx", function() {
  before(function() {
    nock('http://api.a2zbooks.local/v1')
      .get('/books')
      .reply(200, [
        {id:1, name:"<NAME>"},
        {id:2, name:"Odyssey"}
      ])

      .get('/books/1')
      .reply(200, {id:1, name:"<NAME>"})

      .get('/books/2')
      .reply(404, {id:2, message:"Not found"})

      .get('/books/3')
      .reply(404)
      ;

    this.client = new wrapi('http://api.a2zbooks.local/v1/',
      {},
      {
        catchHTTP4xx5xx: true
      });
    var t = this.client.register("list", {
          "method" : "GET",
          "path": "books"
        });

    this.client.register("item", {
          "method" : "GET",
          "path": "books/:id"
        });

  });

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

  describe("GETs", function() {
    it("list", function(done) {
      this.client.list(function (err, data, res) {
        expect(err).to.equal(null);
        expect(data).to.deep.equal([
          {id:1, name:"<NAME>"},
          {id:2, name:"Odyssey"}
        ]);
        expect(res.statusCode).to.equal(200);
        done();
      });
    });


    it("valid item", function(done) {
      this.client.item(1, function (err, data, res) {
        expect(err).to.equal(null);
        expect(data).to.deep.equal(
          {id:1, name:"The Martian"}
        );
        expect(res.statusCode).to.equal(200);
        done();
      });
    });

    it("invalid item", function(done) {
      this.client.item(2, function (err, data, res) {
        expect(err).to.deep.equal(
          {
            statusCode: 404,
            body: {id:2, message:"Not found"}
          }
        );
        expect(res.statusCode).to.equal(404);
        done();
      });
    });

    it("emtpy error response", function(done) {
      this.client.item(3, function (err, data, res) {
        expect(err).to.deep.equal(
          {
            statusCode: 404,
            body: ''
          }
        );
        expect(res.statusCode).to.equal(404);
        done();
      });
    });


  });
});
{'fraction_non_alphanumeric': 0.20791406037530596, 'fraction_numerical': 0.021892847429970084, 'mean_word_length': 1.8899803536345776, 'pattern_counts': {'":': 8, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5794973', 'n_tokens_mistral': 2616, 'n_tokens_neox': 2496, 'n_words': 377}