fix: add missing tests
This commit is contained in:
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm tests && tsc",
|
"build": "npm tests && tsc",
|
||||||
"tests": "mocha -r ts-node/register ./tests/**/*.spec.ts",
|
"tests": "mocha -R progress -r ts-node/register ./tests/**/*.spec.ts",
|
||||||
"test": "mocha -r ts-node/register",
|
"test": "mocha -r ts-node/register",
|
||||||
"test-coverage": "nyc npm run tests"
|
"test-coverage": "nyc npm run tests"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export class OnspringClient {
|
|||||||
/**
|
/**
|
||||||
* @readonly {AxiosInstance} client - The axios instance that will be used to make requests to the Onspring API.
|
* @readonly {AxiosInstance} client - The axios instance that will be used to make requests to the Onspring API.
|
||||||
*/
|
*/
|
||||||
protected readonly client: AxiosInstance;
|
private readonly _client: AxiosInstance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor - Creates a new instance of the OnspringClient class.
|
* @constructor - Creates a new instance of the OnspringClient class.
|
||||||
@@ -31,7 +31,7 @@ export class OnspringClient {
|
|||||||
throw new Error('apiKey cannot be null/empty/whitespace.');
|
throw new Error('apiKey cannot be null/empty/whitespace.');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.client = axios.create({
|
this._client = axios.create({
|
||||||
baseURL: baseUrl,
|
baseURL: baseUrl,
|
||||||
headers: {
|
headers: {
|
||||||
'x-apikey': apiKey,
|
'x-apikey': apiKey,
|
||||||
|
|||||||
+14
-1
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* @class App - Model for the App object
|
* @class App - Model for the App object
|
||||||
*/
|
*/
|
||||||
class App {
|
export class App {
|
||||||
/**
|
/**
|
||||||
* @property {string} href - The URL to the app
|
* @property {string} href - The URL to the app
|
||||||
*/
|
*/
|
||||||
@@ -16,4 +16,17 @@ class App {
|
|||||||
* @property {string} name - The name of the app
|
* @property {string} name - The name of the app
|
||||||
*/
|
*/
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of the App class.
|
||||||
|
* @param {string} href - The URL to the app
|
||||||
|
* @param {number} id - The id of the app
|
||||||
|
* @param {string} name - The name of the app
|
||||||
|
* @returns {App} - A new instance of the App class.
|
||||||
|
*/
|
||||||
|
constructor(href: string, id: number, name: string) {
|
||||||
|
this.href = href;
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import { ApiResponse } from '../src/models/ApiResponse';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('ApiResponse', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(ApiResponse).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(ApiResponse).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have 3 parameters', function () {
|
||||||
|
expect(ApiResponse).to.have.lengthOf(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a new instance of the ApiResponse class', function () {
|
||||||
|
expect(() => new ApiResponse(200, 'a message', 'some data')).to.not.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a property named statusCode', function () {
|
||||||
|
expect(new ApiResponse(200, 'a message', 'some data')).to.have.property('statusCode');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a property named isSuccessful', function () {
|
||||||
|
expect(new ApiResponse(200, 'a message', 'some data')).to.have.property('isSuccessful');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a property named message', function () {
|
||||||
|
expect(new ApiResponse(200, 'a message', 'some data')).to.have.property('message');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a property named data', function () {
|
||||||
|
expect(new ApiResponse(200, 'a message', 'some data')).to.have.property('data');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set the statusCode property to the value passed to the constructor', function () {
|
||||||
|
expect(new ApiResponse(200, 'a message', 'some data').statusCode).to.equal(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set the isSuccessful property to true when the statusCode is less than 400', function () {
|
||||||
|
expect(new ApiResponse(200, 'a message', 'some data').isSuccessful).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set the isSuccessful property to false when the statusCode is greater than or equal to 400', function () {
|
||||||
|
expect(new ApiResponse(400, 'a message', 'some data').isSuccessful).to.be.false;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set the message property to the value passed to the constructor', function () {
|
||||||
|
expect(new ApiResponse(200, 'a message', 'some data').message).to.equal('a message');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set the data property to the value passed to the constructor', function () {
|
||||||
|
expect(new ApiResponse(200, 'a message', 'some data').data).to.equal('some data');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { App } from '../src/models/App';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('App', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(App).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(App).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have 3 parameters', function () {
|
||||||
|
expect(App).to.have.lengthOf(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a new instance of the App class', function () {
|
||||||
|
expect(() => new App('href', 1, 'name')).to.not.throw();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
import { OnspringClient } from '../src/OnspringClient';
|
import { OnspringClient } from '../src/OnspringClient';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
|
|
||||||
describe('OnspringClient Tests', function () {
|
describe('OnspringClient', function () {
|
||||||
|
const baseUrl = 'https://api.onspring.com';
|
||||||
|
const apiKey = 'apiKey';
|
||||||
|
|
||||||
it('should be defined', function () {
|
it('should be defined', function () {
|
||||||
expect(OnspringClient).to.not.be.undefined;
|
expect(OnspringClient).to.not.be.undefined;
|
||||||
});
|
});
|
||||||
@@ -15,73 +18,72 @@ describe('OnspringClient Tests', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error when the baseUrl is null', function () {
|
it('should throw an error when the baseUrl is null', function () {
|
||||||
expect(() => new OnspringClient(null, 'apiKey')).to.throw(
|
expect(() => new OnspringClient(null, apiKey)).to.throw(
|
||||||
'baseUrl must be an absolute and well-formed URI.'
|
'baseUrl must be an absolute and well-formed URI.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error when the baseUrl is undefined', function () {
|
it('should throw an error when the baseUrl is undefined', function () {
|
||||||
expect(() => new OnspringClient(undefined, 'apiKey')).to.throw(
|
expect(() => new OnspringClient(undefined, apiKey)).to.throw(
|
||||||
'baseUrl must be an absolute and well-formed URI.'
|
'baseUrl must be an absolute and well-formed URI.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error when the baseUrl is an empty string', function () {
|
it('should throw an error when the baseUrl is an empty string', function () {
|
||||||
expect(() => new OnspringClient('', 'apiKey')).to.throw(
|
expect(() => new OnspringClient('', apiKey)).to.throw(
|
||||||
'baseUrl must be an absolute and well-formed URI.'
|
'baseUrl must be an absolute and well-formed URI.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error when the baseUrl is a string with only spaces', function () {
|
it('should throw an error when the baseUrl is a string with only spaces', function () {
|
||||||
expect(() => new OnspringClient(' ', 'apiKey')).to.throw(
|
expect(() => new OnspringClient(' ', apiKey)).to.throw(
|
||||||
'baseUrl must be an absolute and well-formed URI.'
|
'baseUrl must be an absolute and well-formed URI.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error when the baseUrl is not a valid url', function () {
|
it('should throw an error when the baseUrl is not a valid url', function () {
|
||||||
expect(() => new OnspringClient('api.onspring.com', 'apiKey')).to.throw(
|
expect(() => new OnspringClient('api.onspring.com', apiKey)).to.throw(
|
||||||
'baseUrl must be an absolute and well-formed URI.'
|
'baseUrl must be an absolute and well-formed URI.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error when the apiKey is null', function () {
|
it('should throw an error when the apiKey is null', function () {
|
||||||
expect(() => new OnspringClient('https://api.onspring.com', null)).to.throw(
|
expect(() => new OnspringClient(baseUrl, null)).to.throw(
|
||||||
'apiKey cannot be null/empty/whitespace.'
|
'apiKey cannot be null/empty/whitespace.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error when the apiKey is undefined', function () {
|
it('should throw an error when the apiKey is undefined', function () {
|
||||||
expect(() => new OnspringClient('https://api.onspring.com', undefined)).to.throw(
|
expect(() => new OnspringClient(baseUrl, undefined)).to.throw(
|
||||||
'apiKey cannot be null/empty/whitespace.'
|
'apiKey cannot be null/empty/whitespace.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error when the apiKey is an empty string', function () {
|
it('should throw an error when the apiKey is an empty string', function () {
|
||||||
expect(() => new OnspringClient('https://api.onspring.com', '')).to.throw(
|
expect(() => new OnspringClient(baseUrl, '')).to.throw(
|
||||||
'apiKey cannot be null/empty/whitespace.'
|
'apiKey cannot be null/empty/whitespace.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error when the apiKey is a string with only spaces', function () {
|
it('should throw an error when the apiKey is a string with only spaces', function () {
|
||||||
expect(() => new OnspringClient('https://api.onspring.com', ' ')).to.throw(
|
expect(() => new OnspringClient(baseUrl, ' ')).to.throw(
|
||||||
'apiKey cannot be null/empty/whitespace.'
|
'apiKey cannot be null/empty/whitespace.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not throw an error when the baseUrl is a valid url', function () {
|
it('should not throw an error when the baseUrl is a valid url', function () {
|
||||||
expect(() => new OnspringClient('https://api.onspring.com', 'apiKey')).to.not.throw();
|
expect(() => new OnspringClient(baseUrl, apiKey)).to.not.throw();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not throw an error when the baseUrl is a valid url', function () {
|
it('should not throw an error when the baseUrl is a valid url', function () {
|
||||||
expect(() => new OnspringClient('http://api.onspring.com', 'apiKey')).to.not.throw();
|
expect(() => new OnspringClient('http://api.onspring.com', apiKey)).to.not.throw();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not throw an error when the apiKey is a valid string', function () {
|
it('should not throw an error when the apiKey is a valid string', function () {
|
||||||
expect(() => new OnspringClient('https://api.onspring.com', 'apiKey')).to.not.throw();
|
expect(() => new OnspringClient(baseUrl, apiKey)).to.not.throw();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have a client property', function () {
|
it('should have a client property', function () {
|
||||||
const client = new OnspringClient('https://api.onspring.com', 'apiKey');
|
expect(new OnspringClient(baseUrl, apiKey)).to.have.property('_client');
|
||||||
expect(client).to.have.property('client');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { PagingRequest } from '../src/models/PagingRequest';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('PagingRequest', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(PagingRequest).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(PagingRequest).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have 2 parameters', function () {
|
||||||
|
expect(PagingRequest).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error when the pageNumber is less than 1', function () {
|
||||||
|
expect(() => new PagingRequest(0, 1)).to.throw('pageNumber must be greater than 0.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error when the pageSize is less than 1', function () {
|
||||||
|
expect(() => new PagingRequest(1, 0)).to.throw('pageSize must be greater than 0 and less than 1001.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error when the pageSize is greater than 1000', function () {
|
||||||
|
expect(() => new PagingRequest(1, 1001)).to.throw('pageSize must be greater than 0 and less than 1001.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a new instance of the PagingRequest class when the pageNumber is greater than 0 and the pageSize is between 1 and 1000', function () {
|
||||||
|
expect(() => new PagingRequest(1, 1)).to.not.throw();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user