fix: test formatting
This commit is contained in:
@@ -2,18 +2,8 @@
|
||||
"extends": "@istanbuljs/nyc-config-typescript",
|
||||
"check-coverage": true,
|
||||
"all": true,
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"src/index.ts",
|
||||
"**/*.spec.ts"
|
||||
],
|
||||
"reporter": [
|
||||
"html",
|
||||
"lcov",
|
||||
"text",
|
||||
"text-summary"
|
||||
],
|
||||
"include": ["src/**/*.ts"],
|
||||
"exclude": ["src/index.ts", "**/*.spec.ts"],
|
||||
"reporter": ["html", "lcov", "text", "text-summary"],
|
||||
"report-dir": "coverage"
|
||||
}
|
||||
}
|
||||
|
||||
+11
-5
@@ -37,7 +37,10 @@ export class OnspringClient {
|
||||
throw new Error('apiKey cannot be null/empty/whitespace.');
|
||||
}
|
||||
|
||||
this._client = axios.create({ baseURL: baseUrl, headers: { 'x-apikey': apiKey, 'x-api-version': '2',},});
|
||||
this._client = axios.create({
|
||||
baseURL: baseUrl,
|
||||
headers: { 'x-apikey': apiKey, 'x-api-version': '2' },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,9 +98,12 @@ export class OnspringClient {
|
||||
* @param {string} endpoint - The endpoint that will be used to make the request.
|
||||
* @returns {Promise<ApiResponse<T>>} - A promise that resolves to an ApiResponse of type T.
|
||||
*/
|
||||
private async get<T>(endpoint: string, config: AxiosRequestConfig = {}): Promise<ApiResponse<T>> {
|
||||
const response = await this._client.get(endpoint, config);
|
||||
const apiResponse = ApiResponseFactory.getApiResponse<T>(response);
|
||||
return apiResponse;
|
||||
private async get<T>(
|
||||
endpoint: string,
|
||||
config: AxiosRequestConfig = {}
|
||||
): Promise<ApiResponse<T>> {
|
||||
const response = await this._client.get(endpoint, config);
|
||||
const apiResponse = ApiResponseFactory.getApiResponse<T>(response);
|
||||
return apiResponse;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export enum FieldType {
|
||||
* @type {string}
|
||||
*/
|
||||
AutoNumber = 'AutoNumber',
|
||||
|
||||
|
||||
/**
|
||||
* @constant Date - The field is a date field.
|
||||
* @type {string}
|
||||
|
||||
@@ -13,7 +13,7 @@ export enum ResultValueType {
|
||||
* @type {string}
|
||||
*/
|
||||
Integer = 'Integer',
|
||||
|
||||
|
||||
/**
|
||||
* @constant Decimal - The result value is a decimal.
|
||||
* @type {string}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PagingRequest } from "./PagingRequest";
|
||||
import { PagingRequest } from './PagingRequest';
|
||||
|
||||
/**
|
||||
* @class EndpointFactory - A factory class for creating endpoints.
|
||||
@@ -16,7 +16,10 @@ export class EndpointFactory {
|
||||
* @param {string} baseUrl - The base url that will be used to create the apps endpoint.
|
||||
* @returns {string} - The apps endpoint.
|
||||
*/
|
||||
public static getAppsEndpoint(baseUrl: string, pagingRequest: PagingRequest): string {
|
||||
public static getAppsEndpoint(
|
||||
baseUrl: string,
|
||||
pagingRequest: PagingRequest
|
||||
): string {
|
||||
return `${baseUrl}/Apps?pageSize=${pagingRequest.pageSize}&pageNumber=${pagingRequest.pageNumber}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import { PagedResponse } from "./PagedResponse";
|
||||
import { App } from "./App";
|
||||
import { PagedResponse } from './PagedResponse';
|
||||
import { App } from './App';
|
||||
|
||||
export class GetPagedAppsResponse extends PagedResponse<App> {
|
||||
constructor(items: App[], pageNumber: number, pageSize: number, totalPages: number, totalRecords: number) {
|
||||
constructor(
|
||||
items: App[],
|
||||
pageNumber: number,
|
||||
pageSize: number,
|
||||
totalPages: number,
|
||||
totalRecords: number
|
||||
) {
|
||||
super(items, pageNumber, pageSize, totalPages, totalRecords);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,17 @@ export class PagedResponse<T> {
|
||||
public totalPages: number;
|
||||
public totalRecords: number;
|
||||
|
||||
constructor(items: T[], pageNumber: number, pageSize: number, totalPages: number, totalRecords: number) {
|
||||
constructor(
|
||||
items: T[],
|
||||
pageNumber: number,
|
||||
pageSize: number,
|
||||
totalPages: number,
|
||||
totalRecords: number
|
||||
) {
|
||||
this.items = items;
|
||||
this.pageNumber = pageNumber;
|
||||
this.pageSize = pageSize;
|
||||
this.totalPages = totalPages;
|
||||
this.totalRecords = totalRecords;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ArgumentValidator } from "./ArgumentValidator";
|
||||
import { ArgumentValidator } from './ArgumentValidator';
|
||||
|
||||
/**
|
||||
* @class PagingRequest - Paging request model
|
||||
@@ -24,11 +24,11 @@ export class PagingRequest {
|
||||
*/
|
||||
constructor(pageNumber: number, pageSize: number) {
|
||||
if (ArgumentValidator.isValidPageNumber(pageNumber) === false) {
|
||||
throw new Error("pageNumber must be greater than 0.");
|
||||
throw new Error('pageNumber must be greater than 0.');
|
||||
}
|
||||
|
||||
if (ArgumentValidator.isValidPageSize(pageSize) === false) {
|
||||
throw new Error("pageSize must be greater than 0 and less than 1001.");
|
||||
throw new Error('pageSize must be greater than 0 and less than 1001.');
|
||||
}
|
||||
|
||||
this.pageNumber = pageNumber;
|
||||
|
||||
@@ -59,7 +59,7 @@ describe('ApiResponseFactory', function () {
|
||||
it('should return an ApiResponse object when request is forbidden and the response contains a message property', function () {
|
||||
const response: AxiosResponse = {
|
||||
data: {
|
||||
message: 'Does not have permission to access this resource.'
|
||||
message: 'Does not have permission to access this resource.',
|
||||
},
|
||||
status: 403,
|
||||
statusText: 'Forbidden',
|
||||
@@ -74,7 +74,9 @@ describe('ApiResponseFactory', function () {
|
||||
expect(apiResponse).to.have.property('message');
|
||||
expect(apiResponse).to.have.property('data');
|
||||
expect(apiResponse.statusCode).to.equal(403);
|
||||
expect(apiResponse.message).to.equal('Does not have permission to access this resource.');
|
||||
expect(apiResponse.message).to.equal(
|
||||
'Does not have permission to access this resource.'
|
||||
);
|
||||
expect(apiResponse.data).to.equal(null);
|
||||
});
|
||||
|
||||
@@ -101,7 +103,7 @@ describe('ApiResponseFactory', function () {
|
||||
it('should return an ApiResponse object with a message value when request is not found and the response contains a message property', function () {
|
||||
const response: AxiosResponse = {
|
||||
data: {
|
||||
message: 'Resource not found.'
|
||||
message: 'Resource not found.',
|
||||
},
|
||||
status: 404,
|
||||
statusText: 'Not Found',
|
||||
@@ -143,7 +145,7 @@ describe('ApiResponseFactory', function () {
|
||||
it('should return an ApiResponse object with a message when request is unauthorized and the response contains a message property', function () {
|
||||
const response: AxiosResponse = {
|
||||
data: {
|
||||
message: 'Unauthorized.'
|
||||
message: 'Unauthorized.',
|
||||
},
|
||||
status: 401,
|
||||
statusText: 'Unauthorized',
|
||||
@@ -165,7 +167,7 @@ describe('ApiResponseFactory', function () {
|
||||
it('should return an ApiResponse object with a message when request is a bad request', function () {
|
||||
const response: AxiosResponse = {
|
||||
data: {
|
||||
field: 'Invalid input.'
|
||||
field: 'Invalid input.',
|
||||
},
|
||||
status: 400,
|
||||
statusText: 'Bad Request',
|
||||
@@ -184,4 +186,4 @@ describe('ApiResponseFactory', function () {
|
||||
expect(apiResponse.data).to.equal(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+1
-1
@@ -28,4 +28,4 @@ describe('App', function () {
|
||||
expect(app.id).to.equal(1);
|
||||
expect(app.name).to.equal('name');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -187,23 +187,23 @@ describe('ArgumentValidator', function () {
|
||||
expect(ArgumentValidator.isValidPageSize(undefined)).to.be.false;
|
||||
});
|
||||
|
||||
it('should return false when the value is greater than 1000', function (){
|
||||
it('should return false when the value is greater than 1000', function () {
|
||||
expect(ArgumentValidator.isValidPageSize(1001)).to.be.false;
|
||||
});
|
||||
|
||||
it('should return false when the value is less than 1', function (){
|
||||
it('should return false when the value is less than 1', function () {
|
||||
expect(ArgumentValidator.isValidPageSize(0)).to.be.false;
|
||||
});
|
||||
|
||||
it('should return true when the value is 1', function (){
|
||||
it('should return true when the value is 1', function () {
|
||||
expect(ArgumentValidator.isValidPageSize(1)).to.be.true;
|
||||
});
|
||||
|
||||
it('should return true when the value is 1000', function (){
|
||||
it('should return true when the value is 1000', function () {
|
||||
expect(ArgumentValidator.isValidPageSize(1000)).to.be.true;
|
||||
});
|
||||
|
||||
it('should return true when the value is 500', function (){
|
||||
it('should return true when the value is 500', function () {
|
||||
expect(ArgumentValidator.isValidPageSize(500)).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -225,11 +225,11 @@ describe('ArgumentValidator', function () {
|
||||
expect(ArgumentValidator.isValidPageNumber(undefined)).to.be.false;
|
||||
});
|
||||
|
||||
it('should return false when the value is less than 1', function (){
|
||||
it('should return false when the value is less than 1', function () {
|
||||
expect(ArgumentValidator.isValidPageNumber(0)).to.be.false;
|
||||
});
|
||||
|
||||
it('should return true when the value is 1', function (){
|
||||
it('should return true when the value is 1', function () {
|
||||
expect(ArgumentValidator.isValidPageNumber(1)).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,4 +15,4 @@ describe('DataFormat', function () {
|
||||
expect(result).to.equal('Formatted');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,7 +14,10 @@ describe('EndpointFactory', function () {
|
||||
|
||||
describe('getAppsEndpoint', function () {
|
||||
it('should return the correct apps endpoint with paging params based on paging request parameter passed', function () {
|
||||
const result = EndpointFactory.getAppsEndpoint(baseUrl, new PagingRequest(2, 1000));
|
||||
const result = EndpointFactory.getAppsEndpoint(
|
||||
baseUrl,
|
||||
new PagingRequest(2, 1000)
|
||||
);
|
||||
expect(result).to.equal(`${baseUrl}/Apps?pageSize=1000&pageNumber=2`);
|
||||
});
|
||||
});
|
||||
@@ -139,8 +142,8 @@ describe('EndpointFactory', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getQueryRecordsEndpoint', function(){
|
||||
it('should return the correct query records endpoint', function(){
|
||||
describe('getQueryRecordsEndpoint', function () {
|
||||
it('should return the correct query records endpoint', function () {
|
||||
const result = EndpointFactory.getQueryRecordsEndpoint(baseUrl);
|
||||
expect(result).to.equal(`${baseUrl}/Records/query`);
|
||||
});
|
||||
|
||||
@@ -22,4 +22,4 @@ describe('FieldStatus', function () {
|
||||
expect(result).to.equal('Invalid');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -85,4 +85,4 @@ describe('FieldType', function () {
|
||||
expect(result).to.equal('Attachment');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,4 +22,4 @@ describe('FileStorageSite', function () {
|
||||
expect(result).to.equal('Internal');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,4 +29,4 @@ describe('FormulaOutputType', function () {
|
||||
expect(result).to.equal('ListValue');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,14 +16,35 @@ describe('GetPagedAppsResponse', function () {
|
||||
});
|
||||
|
||||
it('should construct a new instance of GetPagedAppsResponse', function () {
|
||||
const getPagedAppsResponse = new GetPagedAppsResponse([new App('test', 1, 'test'), new App('test', 1, 'test')], 1, 10, 100, 100);
|
||||
const getPagedAppsResponse = new GetPagedAppsResponse(
|
||||
[new App('test', 1, 'test'), new App('test', 1, 'test')],
|
||||
1,
|
||||
10,
|
||||
100,
|
||||
100
|
||||
);
|
||||
|
||||
expect(getPagedAppsResponse).to.not.be.undefined;
|
||||
expect(getPagedAppsResponse).to.be.instanceOf(GetPagedAppsResponse);
|
||||
expect(getPagedAppsResponse).to.have.property('items').to.be.an('array').to.have.lengthOf(2);
|
||||
expect(getPagedAppsResponse).to.have.property('pageNumber').to.be.a('number').to.equal(1);
|
||||
expect(getPagedAppsResponse).to.have.property('pageSize').to.be.a('number').to.equal(10);
|
||||
expect(getPagedAppsResponse).to.have.property('totalPages').to.be.a('number').to.equal(100);
|
||||
expect(getPagedAppsResponse).to.have.property('totalRecords').to.be.a('number').to.equal(100);
|
||||
expect(getPagedAppsResponse)
|
||||
.to.have.property('items')
|
||||
.to.be.an('array')
|
||||
.to.have.lengthOf(2);
|
||||
expect(getPagedAppsResponse)
|
||||
.to.have.property('pageNumber')
|
||||
.to.be.a('number')
|
||||
.to.equal(1);
|
||||
expect(getPagedAppsResponse)
|
||||
.to.have.property('pageSize')
|
||||
.to.be.a('number')
|
||||
.to.equal(10);
|
||||
expect(getPagedAppsResponse)
|
||||
.to.have.property('totalPages')
|
||||
.to.be.a('number')
|
||||
.to.equal(100);
|
||||
expect(getPagedAppsResponse)
|
||||
.to.have.property('totalRecords')
|
||||
.to.be.a('number')
|
||||
.to.equal(100);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -106,4 +106,4 @@ describe('HttpStatusCode', () => {
|
||||
expect(result).to.equal(504);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,4 +15,4 @@ describe('Multiplicity', function () {
|
||||
expect(result).to.equal('MultiSelect');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -305,7 +305,10 @@ describe('OnspringClient', function () {
|
||||
expect(result).to.be.instanceOf(ApiResponse);
|
||||
expect(result).to.have.property('statusCode', 400);
|
||||
expect(result).to.have.property('isSuccessful', false);
|
||||
expect(result).to.have.property('message', '{"PageSize":["The field PageSize must be between 0 and 1000."]}');
|
||||
expect(result).to.have.property(
|
||||
'message',
|
||||
'{"PageSize":["The field PageSize must be between 0 and 1000."]}'
|
||||
);
|
||||
expect(result).to.have.property('data');
|
||||
expect(result.data).to.be.null;
|
||||
});
|
||||
@@ -344,19 +347,26 @@ describe('OnspringClient', function () {
|
||||
|
||||
describe('getAppById', function () {
|
||||
it('should be defined', function () {
|
||||
expect(new OnspringClient(baseUrl, apiKey).getAppById).to.not.be.undefined;
|
||||
expect(new OnspringClient(baseUrl, apiKey).getAppById).to.not.be
|
||||
.undefined;
|
||||
});
|
||||
|
||||
it('should be a function', function () {
|
||||
expect(new OnspringClient(baseUrl, apiKey).getAppById).to.be.a('function');
|
||||
expect(new OnspringClient(baseUrl, apiKey).getAppById).to.be.a(
|
||||
'function'
|
||||
);
|
||||
});
|
||||
|
||||
it('should have 1 parameter', function () {
|
||||
expect(new OnspringClient(baseUrl, apiKey).getAppById).to.have.lengthOf(1);
|
||||
expect(new OnspringClient(baseUrl, apiKey).getAppById).to.have.lengthOf(
|
||||
1
|
||||
);
|
||||
});
|
||||
|
||||
it('should return a promise', function () {
|
||||
expect(new OnspringClient(baseUrl, apiKey).getAppById(1)).to.be.a('promise');
|
||||
expect(new OnspringClient(baseUrl, apiKey).getAppById(1)).to.be.a(
|
||||
'promise'
|
||||
);
|
||||
});
|
||||
|
||||
it('should return a promise that resolves to an api response of an app when request is successful', async function () {
|
||||
|
||||
@@ -15,14 +15,35 @@ describe('PagedResponse', function () {
|
||||
});
|
||||
|
||||
it('should construct a new instance of PagedResponse', function () {
|
||||
const pagedResponse = new PagedResponse<number>([1, 2, 3, 4], 1, 10, 100, 100);
|
||||
const pagedResponse = new PagedResponse<number>(
|
||||
[1, 2, 3, 4],
|
||||
1,
|
||||
10,
|
||||
100,
|
||||
100
|
||||
);
|
||||
|
||||
expect(pagedResponse).to.not.be.undefined;
|
||||
expect(pagedResponse).to.be.instanceOf(PagedResponse);
|
||||
expect(pagedResponse).to.have.property('items').to.be.an('array').to.have.lengthOf(4);
|
||||
expect(pagedResponse).to.have.property('pageNumber').to.be.a('number').to.equal(1);
|
||||
expect(pagedResponse).to.have.property('pageSize').to.be.a('number').to.equal(10);
|
||||
expect(pagedResponse).to.have.property('totalPages').to.be.a('number').to.equal(100);
|
||||
expect(pagedResponse).to.have.property('totalRecords').to.be.a('number').to.equal(100);
|
||||
expect(pagedResponse)
|
||||
.to.have.property('items')
|
||||
.to.be.an('array')
|
||||
.to.have.lengthOf(4);
|
||||
expect(pagedResponse)
|
||||
.to.have.property('pageNumber')
|
||||
.to.be.a('number')
|
||||
.to.equal(1);
|
||||
expect(pagedResponse)
|
||||
.to.have.property('pageSize')
|
||||
.to.be.a('number')
|
||||
.to.equal(10);
|
||||
expect(pagedResponse)
|
||||
.to.have.property('totalPages')
|
||||
.to.be.a('number')
|
||||
.to.equal(100);
|
||||
expect(pagedResponse)
|
||||
.to.have.property('totalRecords')
|
||||
.to.be.a('number')
|
||||
.to.equal(100);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,15 +15,21 @@ describe('PagingRequest', function () {
|
||||
});
|
||||
|
||||
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.');
|
||||
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.');
|
||||
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.');
|
||||
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 () {
|
||||
@@ -38,4 +44,4 @@ describe('PagingRequest', function () {
|
||||
expect(pagingRequest.pageNumber).to.equal(1);
|
||||
expect(pagingRequest.pageSize).to.equal(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,4 +15,4 @@ describe('ReportDataType', function () {
|
||||
expect(result).to.equal('ChartData');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -85,4 +85,4 @@ describe('ResultValueType', function () {
|
||||
expect(result).to.equal('FileList');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,4 +50,4 @@ describe('TimeSpanIncrement', function () {
|
||||
expect(result).to.equal('Years');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,4 +22,4 @@ describe('TimeSpanRecurrenceType', function () {
|
||||
expect(result).to.equal('EndAfterOccurrences');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user