fix: enabled strict null checks and made changes to deal with this compiler change. fix: modified endpoint factory methods to not need baseURL to be passed in. instead just return endpoint because the axios client with already have a default url set as part of constructing a new onspring client instance

This commit is contained in:
StevanFreeborn
2023-02-02 13:53:02 -06:00
parent 88bf080847
commit d453f19c97
8 changed files with 137 additions and 178 deletions
+4 -12
View File
@@ -29,7 +29,7 @@ export class OnspringClient {
baseUrl: string | undefined | null,
apiKey: string | undefined | null
) {
if (ArgumentValidator.isValidUrl(baseUrl) === false) {
if (ArgumentValidator.isValidUrl(baseUrl) === false || baseUrl === null) {
throw new Error('baseUrl must be an absolute and well-formed URI.');
}
@@ -48,9 +48,7 @@ export class OnspringClient {
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating if the client can connect to the Onspring API.
*/
public async canConnect(): Promise<boolean> {
const endpoint = EndpointFactory.getPingEndpoint(
this._client.defaults.baseURL
);
const endpoint = EndpointFactory.getPingEndpoint();
const response = await this.get<any>(endpoint);
return response.isSuccessful;
@@ -64,10 +62,7 @@ export class OnspringClient {
public async getApps(
pagingRequest: PagingRequest = new PagingRequest(1, 50)
): Promise<ApiResponse<GetPagedAppsResponse>> {
const endpoint = EndpointFactory.getAppsEndpoint(
this._client.defaults.baseURL,
pagingRequest
);
const endpoint = EndpointFactory.getAppsEndpoint(pagingRequest);
var apiResponse = await this.get<any>(endpoint);
@@ -79,10 +74,7 @@ export class OnspringClient {
}
public async getAppById(appId: number): Promise<ApiResponse<App>> {
const endpoint = EndpointFactory.getAppByIdEndpoint(
this._client.defaults.baseURL,
appId
);
const endpoint = EndpointFactory.getAppByIdEndpoint(appId);
var apiResponse = await this.get<any>(endpoint);
+3 -3
View File
@@ -23,16 +23,16 @@ export class ApiResponse<T> {
/**
* @property {T} data - The data of the response.
*/
public data: T;
public data: T | null;
/**
* @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.
* @param {T | null} data - The data of the response.
* @returns {ApiResponse<T>} - A new instance of the ApiResponse class.
*/
constructor(statusCode: number, message: string, data: T) {
constructor(statusCode: number, message: string, data: T | null) {
this.statusCode = statusCode;
this.isSuccessful = statusCode < 400;
this.message = message;
+12
View File
@@ -17,6 +17,10 @@ export class ArgumentValidator {
public static isValidUrl(value: string | null | undefined): boolean {
let url: URL;
if (value === null || value === undefined) {
return false;
}
try {
url = new URL(value);
} catch (error) {
@@ -32,6 +36,10 @@ export class ArgumentValidator {
* @remarks - A valid page size is a number greater than 0 and less than or equal to 1000.
*/
public static isValidPageSize(value: number | null | undefined): boolean {
if (value === null || value === undefined) {
return false;
}
return value > 0 && value <= 1000;
}
@@ -41,6 +49,10 @@ export class ArgumentValidator {
* @remarks - A valid page number is a number greater than 0.
*/
public static isValidPageNumber(value: number | null | undefined): boolean {
if (value === null || value === undefined) {
return false;
}
return value > 0;
}
}
+40 -85
View File
@@ -5,242 +5,197 @@ import { PagingRequest } from './PagingRequest';
*/
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 {
return `${baseUrl}/Ping`;
public static getPingEndpoint(): string {
return '/Ping';
}
/**
* @param {string} baseUrl - The base url that will be used to create the apps endpoint.
* @param {PagingRequest} pagingRequest - Pagination information to use as query params in the endpoint string.
* @returns {string} - The apps endpoint.
*/
public static getAppsEndpoint(
baseUrl: string,
pagingRequest: PagingRequest
): string {
return `${baseUrl}/Apps?pageSize=${pagingRequest.pageSize}&pageNumber=${pagingRequest.pageNumber}`;
public static getAppsEndpoint(pagingRequest: PagingRequest): string {
return `/Apps?pageSize=${pagingRequest.pageSize}&pageNumber=${pagingRequest.pageNumber}`;
}
/**
* @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 {
return `${baseUrl}/Apps/id/${id}`;
public static getAppByIdEndpoint(id: number): string {
return `/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 {
return `${baseUrl}/Apps/batch-get`;
public static getAppsByIdsEndpoint(): string {
return '/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 {
return `${baseUrl}/Fields/id/${id}`;
public static getFieldByIdEndpoint(id: number): string {
return `/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 {
return `${baseUrl}/Fields/batch-get`;
public static getFieldsByIdsEndpoint(): string {
return '/Fields/batch-get';
}
/**
* @param {string} baseUrl - The base url that will be used to create the fields by app id endpoint.
* @param {number} id - The id of the app.
* @returns {string} - The fields by app id endpoint.
*/
public static getFieldsByAppIdEndpoint(baseUrl: string, id: number): string {
return `${baseUrl}/Fields/appId/${id}`;
public static getFieldsByAppIdEndpoint(id: number): string {
return `/Fields/appId/${id}`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the file info by id endpoint.
* @param {number} recordId - The id of the record.
* @param {number} fieldId - The id of the field.
* @param {number} fileId - The id of the file.
* @returns {string} - The file info by id endpoint.
*/
public static getFileInfoByIdEndpoint(
baseUrl: string,
recordId: number,
fieldId: number,
fileId: number
): string {
return `${baseUrl}/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}`;
return `/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the delete file by id endpoint.
* @param {number} recordId - The id of the record.
* @param {number} fieldId - The id of the field.
* @param {number} fileId - The id of the file.
* @returns {string} - The delete file by id endpoint.
*/
public static getDeleteFileByIdEndpoint(
baseUrl: string,
recordId: number,
fieldId: number,
fileId: number
): string {
return `${baseUrl}/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}/file`;
return `/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}/file`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the get file by id endpoint.
* @param {number} recordId - The id of the record.
* @param {number} fieldId - The id of the field.
* @param {number} fileId - The id of the file.
* @returns {string} - The file by id endpoint.
*/
public static getFileByIdEndpoint(
baseUrl: string,
recordId: number,
fieldId: number,
fileId: number
): string {
return `${baseUrl}/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}/file`;
return `/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}/file`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the save file endpoint.
* @returns {string} - The save file endpoint.
*/
public static getSaveFileEndpoint(baseUrl: string): string {
return `${baseUrl}/Files`;
public static getSaveFileEndpoint(): string {
return '/Files';
}
/**
* @param {string} baseUrl - The base url that will be used to create the add or update list item endpoint.
* @param {number} listId - The id of the list.
* @returns {string} - The add or update list item endpoint.
*/
public static getAddOrUpdateListItemEndpoint(
baseUrl: string,
listId: number
): string {
return `${baseUrl}/Lists/id/${listId}/items`;
public static getAddOrUpdateListItemEndpoint(listId: number): string {
return `/Lists/id/${listId}/items`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the delete list item endpoint.
* @param {number} listId - The id of the list.
* @param {string} itemId - The id of the list item.
* @returns {string} - The delete list item endpoint.
*/
public static getDeleteListItemEndpoint(
baseUrl: string,
listId: number,
itemId: string
): string {
return `${baseUrl}/Lists/id/${listId}/itemId/${itemId}`;
return `/Lists/id/${listId}/itemId/${itemId}`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the get records by app id endpoint.
* @param {number} appId - The id of the app.
* @returns {string} - The get records by app id endpoint.
*/
public static getRecordsByAppIdEndpoint(
baseUrl: string,
appId: number
): string {
return `${baseUrl}/Records/appId/${appId}`;
public static getRecordsByAppIdEndpoint(appId: number): string {
return `/Records/appId/${appId}`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the get record by id endpoint.
* @param {number} appId - The id of the app.
* @param {number} recordId - The id of the record.
* @returns {string} - The get record by id endpoint.
*/
public static getRecordByIdEndpoint(
baseUrl: string,
appId: number,
recordId: number
): string {
return `${baseUrl}/Records/appId/${appId}/recordId/${recordId}`;
public static getRecordByIdEndpoint(appId: number, recordId: number): string {
return `/Records/appId/${appId}/recordId/${recordId}`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the delete record by id endpoint.
* @param {number} appId - The id of the app.
* @param {number} recordId - The id of the record.
* @returns {string} - The delete record by id endpoint.
*/
public static getDeleteRecordByIdEndpoint(
baseUrl: string,
appId: number,
recordId: number
): string {
return `${baseUrl}/Records/appId/${appId}/recordId/${recordId}`;
return `/Records/appId/${appId}/recordId/${recordId}`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the get records by ids endpoint.
* @returns {string} - The get records by ids endpoint.
*/
public static getRecordsByIdsEndpoint(baseUrl: string): string {
return `${baseUrl}/Records/batch-get`;
public static getRecordsByIdsEndpoint(): string {
return '/Records/batch-get';
}
/**
* @param {string} baseUrl - The base url that will be used to create the query records endpoint.
* @returns {string} - The query records endpoint.
*/
public static getQueryRecordsEndpoint(baseUrl: string): string {
return `${baseUrl}/Records/query`;
public static getQueryRecordsEndpoint(): string {
return '/Records/query';
}
/**
* @param {string} baseUrl - The base url that will be used to create the add or update record endpoint.
* @returns {string} - The add or update record endpoint.
*/
public static getAddOrUpdateRecordEndpoint(baseUrl: string): string {
return `${baseUrl}/Records`;
public static getAddOrUpdateRecordEndpoint(): string {
return '/Records';
}
/**
* @param {string} baseUrl - The base url that will be used to create the delete records by ids endpoint.
* @returns {string} - The delete records by ids endpoint.
*/
public static getDeleteRecordsByIdsEndpoint(baseUrl: string): string {
return `${baseUrl}/Records/batch-delete`;
public static getDeleteRecordsByIdsEndpoint(): string {
return '/Records/batch-delete';
}
/**
* @param {string} baseUrl - The base url that will be used to create the get report by id endpoint.
* @param {number} reportId - The id of the report.
* @returns {string} - The get report by id endpoint.
*/
public static getReportByIdEndpoint(
baseUrl: string,
reportId: number
): string {
return `${baseUrl}/Reports/id/${reportId}`;
public static getReportByIdEndpoint(reportId: number): string {
return `/Reports/id/${reportId}`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the get reports by app id endpoint.
* @param {number} appId - The id of the app.
* @returns {string} - The get reports by app id endpoint.
*/
public static getReportsByAppIdEndpoint(
baseUrl: string,
appId: number
): string {
return `${baseUrl}/Reports/appId/${appId}`;
public static getReportsByAppIdEndpoint(appId: number): string {
return `/Reports/appId/${appId}`;
}
}
+28 -19
View File
@@ -109,14 +109,17 @@ describe('ApiResponse', function () {
expect(appsPagedResponse).to.be.instanceOf(ApiResponse);
expect(appsPagedResponse.data).to.be.instanceOf(GetPagedAppsResponse);
expect(appsPagedResponse.data.totalPages).to.equal(1);
expect(appsPagedResponse.data.totalRecords).to.equal(2);
expect(appsPagedResponse.data.pageNumber).to.equal(1);
expect(appsPagedResponse.data.pageSize).to.equal(2);
expect(appsPagedResponse.data.items).to.be.instanceOf(Array);
expect(appsPagedResponse.data.items).to.have.lengthOf(2);
expect(appsPagedResponse.data.items[0]).to.be.instanceOf(App);
expect(appsPagedResponse.data.items[1]).to.be.instanceOf(App);
expect(appsPagedResponse.data).to.not.be.null;
if (appsPagedResponse.data != null) {
expect(appsPagedResponse.data.totalPages).to.equal(1);
expect(appsPagedResponse.data.totalRecords).to.equal(2);
expect(appsPagedResponse.data.pageNumber).to.equal(1);
expect(appsPagedResponse.data.pageSize).to.equal(2);
expect(appsPagedResponse.data.items).to.be.instanceOf(Array);
expect(appsPagedResponse.data.items).to.have.lengthOf(2);
expect(appsPagedResponse.data.items[0]).to.be.instanceOf(App);
expect(appsPagedResponse.data.items[1]).to.be.instanceOf(App);
}
});
it('should return an ApiResponse<GetPagedAppsResponse> when data contains app items', function () {
@@ -133,12 +136,15 @@ describe('ApiResponse', function () {
expect(appsPagedResponse).to.be.instanceOf(ApiResponse);
expect(appsPagedResponse.data).to.be.instanceOf(GetPagedAppsResponse);
expect(appsPagedResponse.data.totalPages).to.equal(0);
expect(appsPagedResponse.data.totalRecords).to.equal(0);
expect(appsPagedResponse.data.pageNumber).to.equal(0);
expect(appsPagedResponse.data.pageSize).to.equal(0);
expect(appsPagedResponse.data.items).to.be.instanceOf(Array);
expect(appsPagedResponse.data.items).to.have.lengthOf(0);
expect(appsPagedResponse.data).to.not.be.null;
if (appsPagedResponse.data != null) {
expect(appsPagedResponse.data.totalPages).to.equal(0);
expect(appsPagedResponse.data.totalRecords).to.equal(0);
expect(appsPagedResponse.data.pageNumber).to.equal(0);
expect(appsPagedResponse.data.pageSize).to.equal(0);
expect(appsPagedResponse.data.items).to.be.instanceOf(Array);
expect(appsPagedResponse.data.items).to.have.lengthOf(0);
}
});
});
@@ -163,11 +169,14 @@ describe('ApiResponse', function () {
expect(appResponse).to.be.instanceOf(ApiResponse);
expect(appResponse.data).to.be.instanceOf(App);
expect(appResponse.data.id).to.equal(1);
expect(appResponse.data.name).to.equal('Test App');
expect(appResponse.data.href).to.equal(
'https://api.onspring.dev/apps/id/1'
);
expect(appResponse.data).to.not.be.null;
if (appResponse.data != null) {
expect(appResponse.data.id).to.equal(1);
expect(appResponse.data.name).to.equal('Test App');
expect(appResponse.data.href).to.equal(
'https://api.onspring.dev/apps/id/1'
);
}
});
});
});
+42 -55
View File
@@ -3,177 +3,164 @@ import { expect } from 'chai';
import { PagingRequest } from '../src/models/PagingRequest';
describe('EndpointFactory', function () {
const baseUrl = 'https://api.onspring.com';
describe('getPingEndpoint', function () {
it('should return the correct ping endpoint', function () {
const result = EndpointFactory.getPingEndpoint(baseUrl);
expect(result).to.equal(`${baseUrl}/Ping`);
const result = EndpointFactory.getPingEndpoint();
expect(result).to.equal('/Ping');
});
});
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)
);
expect(result).to.equal(`${baseUrl}/Apps?pageSize=1000&pageNumber=2`);
expect(result).to.equal('/Apps?pageSize=1000&pageNumber=2');
});
});
describe('getAppByIdEndpoint', function () {
it('should return the correct app by id endpoint', function () {
const result = EndpointFactory.getAppByIdEndpoint(baseUrl, 1);
expect(result).to.equal(`${baseUrl}/Apps/id/1`);
const result = EndpointFactory.getAppByIdEndpoint(1);
expect(result).to.equal('/Apps/id/1');
});
});
describe('getAppsByIdsEndpoint', function () {
it('should return the correct apps by ids endpoint', function () {
const result = EndpointFactory.getAppsByIdsEndpoint(baseUrl);
expect(result).to.equal(`${baseUrl}/Apps/batch-get`);
const result = EndpointFactory.getAppsByIdsEndpoint();
expect(result).to.equal('/Apps/batch-get');
});
});
describe('getFieldByIdEndpoint', function () {
it('should return the correct field by id endpoint', function () {
const result = EndpointFactory.getFieldByIdEndpoint(baseUrl, 1);
expect(result).to.equal(`${baseUrl}/Fields/id/1`);
const result = EndpointFactory.getFieldByIdEndpoint(1);
expect(result).to.equal('/Fields/id/1');
});
});
describe('getFieldsByIdsEndpoint', function () {
it('should return the correct fields by ids endpoint', function () {
const result = EndpointFactory.getFieldsByIdsEndpoint(baseUrl);
expect(result).to.equal(`${baseUrl}/Fields/batch-get`);
const result = EndpointFactory.getFieldsByIdsEndpoint();
expect(result).to.equal('/Fields/batch-get');
});
});
describe('getFieldsByAppIdEndpoint', function () {
it('should return the correct fields by app id endpoint', function () {
const result = EndpointFactory.getFieldsByAppIdEndpoint(baseUrl, 1);
expect(result).to.equal(`${baseUrl}/Fields/appId/1`);
const result = EndpointFactory.getFieldsByAppIdEndpoint(1);
expect(result).to.equal('/Fields/appId/1');
});
});
describe('getFileInfoByIdEndpoint', function () {
it('should return the correct get file info endpoint', function () {
const result = EndpointFactory.getFileInfoByIdEndpoint(baseUrl, 1, 2, 3);
expect(result).to.equal(`${baseUrl}/Files/recordId/1/fieldId/2/fileId/3`);
const result = EndpointFactory.getFileInfoByIdEndpoint(1, 2, 3);
expect(result).to.equal('/Files/recordId/1/fieldId/2/fileId/3');
});
});
describe('getDeleteFileByIdEndpoint', function () {
it('should return the correct delete file endpoint', function () {
const result = EndpointFactory.getDeleteFileByIdEndpoint(
baseUrl,
1,
2,
3
);
expect(result).to.equal(
`${baseUrl}/Files/recordId/1/fieldId/2/fileId/3/file`
);
const result = EndpointFactory.getDeleteFileByIdEndpoint(1, 2, 3);
expect(result).to.equal('/Files/recordId/1/fieldId/2/fileId/3/file');
});
});
describe('getFileByIdEndpoint', function () {
it('should return the correct get file endpoint', function () {
const result = EndpointFactory.getFileByIdEndpoint(baseUrl, 1, 2, 3);
expect(result).to.equal(
`${baseUrl}/Files/recordId/1/fieldId/2/fileId/3/file`
);
const result = EndpointFactory.getFileByIdEndpoint(1, 2, 3);
expect(result).to.equal('/Files/recordId/1/fieldId/2/fileId/3/file');
});
});
describe('getSaveFileEndpoint', function () {
it('should return the correct save file endpoint', function () {
const result = EndpointFactory.getSaveFileEndpoint(baseUrl);
expect(result).to.equal(`${baseUrl}/Files`);
const result = EndpointFactory.getSaveFileEndpoint();
expect(result).to.equal('/Files');
});
});
describe('getAddOrUpdateListItemEndpoint', function () {
it('should return the correct add or update list item endpoint', function () {
const result = EndpointFactory.getAddOrUpdateListItemEndpoint(baseUrl, 1);
expect(result).to.equal(`${baseUrl}/Lists/id/1/items`);
const result = EndpointFactory.getAddOrUpdateListItemEndpoint(1);
expect(result).to.equal('/Lists/id/1/items');
});
});
describe('getDeleteListItemEndpoint', function () {
it('should return the correct delete list item endpoint', function () {
const result = EndpointFactory.getDeleteListItemEndpoint(
baseUrl,
1,
'612ac495-8aad-44fd-b57d-1ae798dcf1a5'
);
expect(result).to.equal(
`${baseUrl}/Lists/id/1/itemId/612ac495-8aad-44fd-b57d-1ae798dcf1a5`
'/Lists/id/1/itemId/612ac495-8aad-44fd-b57d-1ae798dcf1a5'
);
});
});
describe('getRecordsByAppIdEndpoint', function () {
it('should return the correct records by app id endpoint', function () {
const result = EndpointFactory.getRecordsByAppIdEndpoint(baseUrl, 1);
expect(result).to.equal(`${baseUrl}/Records/appId/1`);
const result = EndpointFactory.getRecordsByAppIdEndpoint(1);
expect(result).to.equal('/Records/appId/1');
});
});
describe('getRecordByIdEndpoint', function () {
it('should return the correct record by id endpoint', function () {
const result = EndpointFactory.getRecordByIdEndpoint(baseUrl, 1, 2);
expect(result).to.equal(`${baseUrl}/Records/appId/1/recordId/2`);
const result = EndpointFactory.getRecordByIdEndpoint(1, 2);
expect(result).to.equal('/Records/appId/1/recordId/2');
});
});
describe('getDeleteRecordByIdEndpoint', function () {
it('should return the correct delete record by id endpoint', function () {
const result = EndpointFactory.getDeleteRecordByIdEndpoint(baseUrl, 1, 2);
expect(result).to.equal(`${baseUrl}/Records/appId/1/recordId/2`);
const result = EndpointFactory.getDeleteRecordByIdEndpoint(1, 2);
expect(result).to.equal('/Records/appId/1/recordId/2');
});
});
describe('getRecordsByIdsEndpoint', function () {
it('should return the correct records by ids endpoint', function () {
const result = EndpointFactory.getRecordsByIdsEndpoint(baseUrl);
expect(result).to.equal(`${baseUrl}/Records/batch-get`);
const result = EndpointFactory.getRecordsByIdsEndpoint();
expect(result).to.equal('/Records/batch-get');
});
});
describe('getQueryRecordsEndpoint', function () {
it('should return the correct query records endpoint', function () {
const result = EndpointFactory.getQueryRecordsEndpoint(baseUrl);
expect(result).to.equal(`${baseUrl}/Records/query`);
const result = EndpointFactory.getQueryRecordsEndpoint();
expect(result).to.equal('/Records/query');
});
});
describe('getAddOrUpdateRecordEndpoint', function () {
it('should return the correct add or update record endpoint', function () {
const result = EndpointFactory.getAddOrUpdateRecordEndpoint(baseUrl);
expect(result).to.equal(`${baseUrl}/Records`);
const result = EndpointFactory.getAddOrUpdateRecordEndpoint();
expect(result).to.equal('/Records');
});
});
describe('getDeleteRecordsByIdsEndpoint', function () {
it('should return the correct delete records by ids endpoint', function () {
const result = EndpointFactory.getDeleteRecordsByIdsEndpoint(baseUrl);
expect(result).to.equal(`${baseUrl}/Records/batch-delete`);
const result = EndpointFactory.getDeleteRecordsByIdsEndpoint();
expect(result).to.equal('/Records/batch-delete');
});
});
describe('getReportByIdEndpoint', function () {
it('should return the correct report by id endpoint', function () {
const result = EndpointFactory.getReportByIdEndpoint(baseUrl, 1);
expect(result).to.equal(`${baseUrl}/Reports/id/1`);
const result = EndpointFactory.getReportByIdEndpoint(1);
expect(result).to.equal('/Reports/id/1');
});
});
describe('getReportsByAppIdEndpoint', function () {
it('should return the correct reports by app id endpoint', function () {
const result = EndpointFactory.getReportsByAppIdEndpoint(baseUrl, 1);
expect(result).to.equal(`${baseUrl}/Reports/appId/1`);
const result = EndpointFactory.getReportsByAppIdEndpoint(1);
expect(result).to.equal('/Reports/appId/1');
});
});
});
+7 -4
View File
@@ -269,10 +269,13 @@ describe('OnspringClient', function () {
expect(result.data).to.have.property('totalPages', 1);
expect(result.data).to.have.property('totalRecords', 2);
expect(result.data).to.have.property('items');
expect(result.data.items).to.be.instanceOf(Array);
expect(result.data.items).to.have.lengthOf(2);
expect(result.data.items[0]).to.be.instanceOf(App);
expect(result.data.items[1]).to.be.instanceOf(App);
expect(result.data).to.not.be.null;
if (result.data != null) {
expect(result.data.items).to.be.instanceOf(Array);
expect(result.data.items).to.have.lengthOf(2);
expect(result.data.items[0]).to.be.instanceOf(App);
expect(result.data.items[1]).to.be.instanceOf(App);
}
});
it('should return a promise that resolves to an api response when request returns a 400 status code', async function () {
+1
View File
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"strictNullChecks": true,
"module": "commonjs",
"target": "es2015",
"declaration": true,