feat: added nyc for test coverage reporting. fix: add jsdoc comments
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"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"
|
||||||
|
],
|
||||||
|
"report-dir": "coverage"
|
||||||
|
}
|
||||||
Generated
+2801
File diff suppressed because it is too large
Load Diff
+4
-1
@@ -7,15 +7,18 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm tests && tsc",
|
"build": "npm tests && tsc",
|
||||||
"tests": "mocha -r ts-node/register ./tests/**/*.spec.ts",
|
"tests": "mocha -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"
|
||||||
},
|
},
|
||||||
"author": "Stevan Freeborn",
|
"author": "Stevan Freeborn",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
||||||
"@types/chai": "^4.3.4",
|
"@types/chai": "^4.3.4",
|
||||||
"@types/mocha": "^10.0.1",
|
"@types/mocha": "^10.0.1",
|
||||||
"chai": "^4.3.7",
|
"chai": "^4.3.7",
|
||||||
"mocha": "^10.2.0",
|
"mocha": "^10.2.0",
|
||||||
|
"nyc": "^15.1.0",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^4.9.4"
|
"typescript": "^4.9.4"
|
||||||
},
|
},
|
||||||
|
|||||||
+27
-10
@@ -1,25 +1,42 @@
|
|||||||
import { AxiosInstance } from "axios";
|
import { AxiosInstance } from 'axios';
|
||||||
import axios from "axios";
|
import axios from 'axios';
|
||||||
import { ArgumentValidator } from "./models/ArgumentValidator";
|
import { ArgumentValidator } from './models/ArgumentValidator';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class OnspringClient - A client that can communicate with the Onspring API.
|
||||||
|
*/
|
||||||
export class OnspringClient {
|
export class OnspringClient {
|
||||||
|
/**
|
||||||
|
* @property {AxiosInstance} client - The axios instance that will be used to make requests to the Onspring API.
|
||||||
|
*/
|
||||||
protected readonly client: AxiosInstance;
|
protected readonly client: AxiosInstance;
|
||||||
|
|
||||||
constructor(baseUrl: string | undefined | null, apiKey: string | undefined | null) {
|
/**
|
||||||
|
* @constructor - Creates a new instance of the OnspringClient class.
|
||||||
|
* @param {string} baseUrl - The base url that will be used to make requests to the Onspring API.
|
||||||
|
* @param {string} apiKey - The api key that will be used to authorize requests made by this client.
|
||||||
|
* @throws {Error} - Thrown when the baseUrl is not a valid url.
|
||||||
|
* @throws {Error} - Thrown when the apiKey is null/undefined/empty/whitespace.
|
||||||
|
* @returns {OnspringClient} - A new instance of the OnspringClient class.
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
baseUrl: string | undefined | null,
|
||||||
|
apiKey: string | undefined | null
|
||||||
|
) {
|
||||||
if (ArgumentValidator.isValidUrl(baseUrl) === false) {
|
if (ArgumentValidator.isValidUrl(baseUrl) === false) {
|
||||||
throw new Error("baseUrl must be an absolute and well-formed URI.");
|
throw new Error('baseUrl must be an absolute and well-formed URI.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ArgumentValidator.isNullOrWhiteSpace(apiKey)) {
|
if (ArgumentValidator.isNullOrWhiteSpace(apiKey)) {
|
||||||
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,
|
||||||
"x-api-version": "2",
|
'x-api-version': '2',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* @class ApiResponse - A generic response object for API requests.
|
||||||
|
*/
|
||||||
export class ApiResponse<T> {
|
export class ApiResponse<T> {
|
||||||
|
/**
|
||||||
|
* @property {number} statusCode - The status code of the response.
|
||||||
|
*/
|
||||||
readonly statusCode: number;
|
readonly statusCode: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {boolean} isSuccessful - True if the status code is less than 400; otherwise, false.
|
||||||
|
*/
|
||||||
readonly isSuccessful: boolean;
|
readonly isSuccessful: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {string} message - The message of the response.
|
||||||
|
*/
|
||||||
readonly message: string;
|
readonly message: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {T} data - The data of the response.
|
||||||
|
*/
|
||||||
readonly data: T;
|
readonly data: T;
|
||||||
|
|
||||||
constructor(statusCode: number, isSuccessful: boolean, message: string, data: T) {
|
/**
|
||||||
|
* @constructor - Creates a new instance of the ApiResponse class.
|
||||||
|
* @param {number} statusCode - The status code of the response.
|
||||||
|
* @param {string} message - The message of the response.
|
||||||
|
* @param {T} data - The data of the response.
|
||||||
|
* @returns {ApiResponse<T>} - A new instance of the ApiResponse class.
|
||||||
|
*/
|
||||||
|
constructor(statusCode: number, message: string, data: T) {
|
||||||
this.statusCode = statusCode;
|
this.statusCode = statusCode;
|
||||||
this.isSuccessful = statusCode < 400;
|
this.isSuccessful = statusCode < 400;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-1
@@ -1,5 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* @class App - Model for the App object
|
||||||
|
*/
|
||||||
class App {
|
class App {
|
||||||
|
/**
|
||||||
|
* @property {string} href - The URL to the app
|
||||||
|
*/
|
||||||
href: string;
|
href: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {number} id - The id of the app
|
||||||
|
*/
|
||||||
id: number;
|
id: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {string} name - The name of the app
|
||||||
|
*/
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* @class ArgumentValidator - A class that validates arguments.
|
||||||
|
*/
|
||||||
export class ArgumentValidator {
|
export class ArgumentValidator {
|
||||||
public static isNullOrWhiteSpace(value: string | null | undefined): boolean {
|
/**
|
||||||
return value === null || value === undefined || (/^\s*$/).test(value);
|
* @param {string} value - The value to validate.
|
||||||
|
* @returns {boolean} - True if the value is null, undefined, or a string that contains only whitespace characters; otherwise, false.
|
||||||
|
*/
|
||||||
|
public static isNullOrWhiteSpace(value: string | null | undefined): boolean {
|
||||||
|
return value === null || value === undefined || /^\s*$/.test(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} value - The value to validate.
|
||||||
|
* @returns {boolean} - True if the value is a valid URL; otherwise, false.
|
||||||
|
*/
|
||||||
|
public static isValidUrl(value: string | null | undefined): boolean {
|
||||||
|
let url: URL;
|
||||||
|
|
||||||
|
try {
|
||||||
|
url = new URL(value);
|
||||||
|
} catch (error) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static isValidUrl(value: string | null | undefined): boolean {
|
return url.protocol === 'http:' || url.protocol === 'https:';
|
||||||
let url: URL;
|
}
|
||||||
|
|
||||||
try {
|
/**
|
||||||
url = new URL(value);
|
* @param {number} value - The value to validate.
|
||||||
} catch (error) {
|
* @returns {boolean} - True if the value is a valid page size; otherwise, false.
|
||||||
return false;
|
* @remarks - A valid page size is a number greater than 0 and less than or equal to 1000.
|
||||||
}
|
*/
|
||||||
|
public static isValidPageSize(value: number): boolean {
|
||||||
|
return value > 0 && value <= 1000;
|
||||||
|
}
|
||||||
|
|
||||||
return url.protocol === 'http:' || url.protocol === 'https:';
|
/**
|
||||||
}
|
* @param {number} value - The value to validate.
|
||||||
}
|
* @returns {boolean} - True if the value is a valid page number; otherwise, false.
|
||||||
|
* @remarks - A valid page number is a number greater than 0.
|
||||||
|
*/
|
||||||
|
public static isValidPageNumber(value: number): boolean {
|
||||||
|
return value > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,24 +1,53 @@
|
|||||||
|
/**
|
||||||
|
* @class EndpointFactory - A factory class for creating endpoints.
|
||||||
|
*/
|
||||||
export class EndpointFactory {
|
export class EndpointFactory {
|
||||||
|
/**
|
||||||
|
* @param {string} baseUrl - The base url that will be used to create the ping endpoint.
|
||||||
|
* @returns {string} - The ping endpoint.
|
||||||
|
*/
|
||||||
public static getPingEndpoint(baseUrl: string): string {
|
public static getPingEndpoint(baseUrl: string): string {
|
||||||
return `${baseUrl}/Ping`;
|
return `${baseUrl}/Ping`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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): string {
|
public static getAppsEndpoint(baseUrl: string): string {
|
||||||
return `${baseUrl}/Apps`;
|
return `${baseUrl}/Apps`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} baseUrl - The base url that will be used to create the app by id endpoint.
|
||||||
|
* @param {number} id - The id of the app.
|
||||||
|
* @returns {string} - The app by id endpoint.
|
||||||
|
*/
|
||||||
public static getAppByIdEndpoint(baseUrl: string, id: number): string {
|
public static getAppByIdEndpoint(baseUrl: string, id: number): string {
|
||||||
return `${baseUrl}/Apps/id/${id}`;
|
return `${baseUrl}/Apps/id/${id}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} baseUrl - The base url that will be used to create the apps by ids endpoint.
|
||||||
|
* @returns {string} - The apps by ids endpoint.
|
||||||
|
*/
|
||||||
public static getAppsByIdsEndpoint(baseUrl: string): string {
|
public static getAppsByIdsEndpoint(baseUrl: string): string {
|
||||||
return `${baseUrl}/Apps/batch-get`;
|
return `${baseUrl}/Apps/batch-get`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} baseUrl - The base url that will be used to create the field by id endpoint.
|
||||||
|
* @param {number} id - The id of the field.
|
||||||
|
* @returns {string} - The field by id endpoint.
|
||||||
|
*/
|
||||||
public static getFieldByIdEndpoint(baseUrl: string, id: number): string {
|
public static getFieldByIdEndpoint(baseUrl: string, id: number): string {
|
||||||
return `${baseUrl}/Fields/id/${id}`;
|
return `${baseUrl}/Fields/id/${id}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} baseUrl - The base url that will be used to create the fields by ids endpoint.
|
||||||
|
* @returns {string} - The fields by ids endpoint.
|
||||||
|
*/
|
||||||
public static getFieldsByIdsEndpoint(baseUrl: string): string {
|
public static getFieldsByIdsEndpoint(baseUrl: string): string {
|
||||||
return `${baseUrl}/Fields/batch-get`;
|
return `${baseUrl}/Fields/batch-get`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,37 @@
|
|||||||
|
import { ArgumentValidator } from "./ArgumentValidator";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class PagingRequest - Paging request model
|
||||||
|
*/
|
||||||
export class PagingRequest {
|
export class PagingRequest {
|
||||||
|
/**
|
||||||
|
* @property {number} pageNumber - The page number of the request.
|
||||||
|
*/
|
||||||
pageNumber: number;
|
pageNumber: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {number} pageSize - The page size of the request.
|
||||||
|
*/
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of the PagingRequest class.
|
||||||
|
* @param {number} pageNumber - The page number of the request. Must be greater than 0.
|
||||||
|
* @param {number} pageSize - The page size of the request. Must be greater than 0 and less than 1001.
|
||||||
|
* @returns {PagingRequest} - A new instance of the PagingRequest class.
|
||||||
|
* @throws {Error} - Thrown when the pageNumber is less than 1.
|
||||||
|
* @throws {Error} - Thrown when the pageSize is less than 1.
|
||||||
|
* @throws {Error} - Thrown when the pageSize is greater than 1000.
|
||||||
|
*/
|
||||||
constructor(pageNumber: number, pageSize: number) {
|
constructor(pageNumber: number, pageSize: number) {
|
||||||
|
if (ArgumentValidator.isValidPageNumber(pageNumber) === false) {
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
|
||||||
this.pageNumber = pageNumber;
|
this.pageNumber = pageNumber;
|
||||||
this.pageSize = pageSize;
|
this.pageSize = pageSize;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { EndpointFactory } from '../src/Models/EndpointFactory';
|
import { EndpointFactory } from '../src/models/EndpointFactory';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
|
|
||||||
describe('EndpointFactory', function () {
|
describe('EndpointFactory', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user