HEX
Server: Apache
System: Linux srv4.garantili.com.tr 4.18.0-477.21.1.lve.1.el8.x86_64 #1 SMP Tue Sep 5 23:08:35 UTC 2023 x86_64
User: yenicep (1023)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home2/yenicep/garantili-kasko/node_modules/rest-facade/tests/exceptions.tests.js
var expect = require('chai').expect;
var exceptions = require('../src/exceptions');

var ArgumentError = exceptions.ArgumentError;
var APIError = exceptions.APIError;

module.exports = {
  'AgrumentError': {
    '#constructor': {
      beforeEach: function() {
        this.error = new ArgumentError('Missing data object');
      },

      'should be an instance of the builtin Error':
        function () {
          expect(this.error).to.be.an.instanceof(Error);
        },

      'should be an instance of its class':
        function () {
          expect(this.error).to.be.an.instanceof(ArgumentError);
        },

      'should have a name':
        function () {
          expect(this.error.name).to.eql('ArgumentError');
        },

      'should have a message':
        function () {
          expect(this.error.message).to.eql('Missing data object');
        },

      'should have a stack with the message and location the error was created':
        function () {
          expect(this.error.stack).to.exist;
          var stackLines = this.error.stack.split('\n');
          expect(stackLines[0]).to.eql('ArgumentError: Missing data object');
          expect(stackLines[1]).to.include('tests/exceptions.tests.js:11');
        }
    }
  },

  'APIError': {
    '#constructor': {
      beforeEach: function() {
        this.origError = new Error();
        this.reqinfo = { method : 'post', url : '/some/endpoint' };
        this.error = new APIError('Unauthorized', 'Invalid token', 401, this.reqinfo, this.origError);
      },

      'should be an instance of the builtin Error':
        function () {
          expect(this.error).to.be.an.instanceof(Error);
        },

      'should be an instance of its class':
        function () {
          expect(this.error).to.be.an.instanceof(APIError);
        },

      'should have a name':
        function () {
          expect(this.error.name).to.eql('Unauthorized');
        },

      'should have a message':
        function () {
          expect(this.error.message).to.eql('Invalid token');
        },

      'should have a statusCode':
        function () {
          expect(this.error.statusCode).to.eql(401);
        },

      'should have request info':
        function () {
          expect((this.error.requestInfo || {}).method).to.eql(this.reqinfo.method);
          expect((this.error.requestInfo || {}).url).to.eql(this.reqinfo.url);
        },

      'should have an original error':
        function () {
          expect(this.error.originalError).to.eql(this.origError);
        },

      'should have a stack with the message and location the error was created':
        function () {
          expect(this.error.stack).to.exist;
          var stackLines = this.error.stack.split('\n');
          expect(stackLines[0]).to.eql('Unauthorized: Invalid token');
          expect(stackLines[1]).to.include(__filename);
        }
    }
  }
};