text: 'use strict';
  var chai = require('chai');
  var ZSchema = require('z-schema');
  var customFormats = module.exports = function(zSchema) {
    // Placeholder file for all custom-formats in known to swagger.json
    // as found on
    // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat
  
    var decimalPattern = /^\d{0,8}.?\d{0,4}[0]+$/;
  
    /** Validates floating point as decimal / money (i.e: 12345678.123400..) */
    zSchema.registerFormat('double', function(val) {
      return !decimalPattern.test(val.toString());
    });
  
    /** Validates value is a 32bit integer */
    zSchema.registerFormat('int32', function(val) {
      // the 32bit shift (>>) truncates any bits beyond max of 32
      return Number.isInteger(val) && ((val >> 0) === val);
    });
  
    zSchema.registerFormat('int64', function(val) {
      return Number.isInteger(val);
    });
  
    zSchema.registerFormat('float', function(val) {
      // better parsing for custom "float" format
      if (Number.parseFloat(val)) {
        return true;
      } else {
        return false;
      }
    });
  
    zSchema.registerFormat('date', function(val) {
      // should parse a a date
      return !isNaN(Date.parse(val));
    });
  
    zSchema.registerFormat('dateTime', function(val) {
      return !isNaN(Date.parse(val));
    });
  
    zSchema.registerFormat('password', function(val) {
      // should parse as a string
      return typeof val === 'string';
    });
  };
  
  customFormats(ZSchema);
  
  var validator = new ZSchema({});
  var request = require('request');
  var assert = chai.assert;
  
  require('dotenv').load();
  
  describe('/', function() {
    describe('get', function() {
      it('should respond with 200 OK', function(done) {
        /*eslint-disable*/
        var schema = {
          "type": "object",
          "properties": {
            "id": {
              "type": "integer"
            },
            "username": {
              "type": "string"
            }
          }
        };
  
        /*eslint-enable*/
        request({
          url: 'https://api.uber.com/',
          json: true,
          qs: {
            accessToken: process.env.KEY
          },
          method: 'GET',
          headers: {
            'Content-Type': 'application/json'
          }
        },
        function(error, res, body) {
          if (error) return done(error);
  
          assert.equal(res.statusCode, 200);
  
          assert.true(validator.validate(body, schema));
          done();
        });
      });
  
      it('should respond with 400 NOT OK', function(done) {
        /*eslint-disable*/
        var schema = {
          "type": "object",
          "properties": {
            "meta": "string",
            "data": "number"
          }
        };
  
        /*eslint-enable*/
        request({
          url: 'https://api.uber.com/',
          json: true,
          qs: {
            accessToken: process.env.KEY
          },
          method: 'GET',
          headers: {
            'Content-Type': 'application/json'
          }
        },
        function(error, res, body) {
          if (error) return done(error);
  
          assert.equal(res.statusCode, 400);
  
          assert.true(validator.validate(body, schema));
          done();
        });
      });
  
      it('should respond with 500 SERVER ERROR', function(done) {
        /*eslint-disable*/
        var schema = {
          "properties": {
            "meta": "string",
            "data": "number",
            "UserObj": {
              "schema": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "integer"
                  },
                  "username": {
                    "type": "string"
                  }
                }
              }
            }
          }
        };
  
        /*eslint-enable*/
        request({
          url: 'https://api.uber.com/',
          json: true,
          qs: {
            accessToken: process.env.KEY
          },
          method: 'GET',
          headers: {
            'Content-Type': 'application/json'
          }
        },
        function(error, res, body) {
          if (error) return done(error);
  
          assert.equal(res.statusCode, 500);
  
          assert.true(validator.validate(body, schema));
          done();
        });
      });
  
    });
  
    describe('post', function() {
      it('should respond with 200 OK', function(done) {
        /*eslint-disable*/
        var schema = {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "integer"
              },
              "username": {
                "type": "string"
              }
            }
          }
        };
  
        /*eslint-enable*/
        request({
          url: 'https://api.uber.com/',
          json: true,
          qs: {
            longitude: 'DATA GOES HERE'
          },
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
            'X-latitude': 'DATA GOES HERE',
            Authorization: 'Bearer ' + process.env.OAUTH
          },
          body: {
          }
        },
        function(error, res, body) {
          if (error) return done(error);
  
          assert.equal(res.statusCode, 200);
  
          assert.true(validator.validate(body, schema));
          done();
        });
      });
  
      it('should respond with 400 NOT OK', function(done) {
        /*eslint-disable*/
        var schema = {
          "type": "number"
        };
  
        /*eslint-enable*/
        request({
          url: 'https://api.uber.com/',
          json: true,
          qs: {
            longitude: 'DATA GOES HERE'
          },
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
            'X-latitude': 'DATA GOES HERE',
            Authorization: 'Bearer ' + process.env.OAUTH
          },
          body: {
          }
        },
        function(error, res, body) {
          if (error) return done(error);
  
          assert.equal(res.statusCode, 400);
  
          assert.true(validator.validate(body, schema));
          done();
        });
      });
  
      it('should respond with 500 SERVER ERROR', function(done) {
        /*eslint-disable*/
        var schema = {
          "type": "string"
        };
  
        /*eslint-enable*/
        request({
          url: 'https://api.uber.com/',
          json: true,
          qs: {
            longitude: 'DATA GOES HERE'
          },
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
            'X-latitude': 'DATA GOES HERE',
            Authorization: 'Bearer ' + process.env.OAUTH
          },
          body: {
          }
        },
        function(error, res, body) {
          if (error) return done(error);
  
          assert.equal(res.statusCode, 500);
  
          assert.true(validator.validate(body, schema));
          done();
        });
      });
  
    });
  
  });
  