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:
+4
-12
@@ -29,7 +29,7 @@ export class OnspringClient {
|
|||||||
baseUrl: string | undefined | null,
|
baseUrl: string | undefined | null,
|
||||||
apiKey: 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.');
|
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.
|
* @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> {
|
public async canConnect(): Promise<boolean> {
|
||||||
const endpoint = EndpointFactory.getPingEndpoint(
|
const endpoint = EndpointFactory.getPingEndpoint();
|
||||||
this._client.defaults.baseURL
|
|
||||||
);
|
|
||||||
|
|
||||||
const response = await this.get<any>(endpoint);
|
const response = await this.get<any>(endpoint);
|
||||||
return response.isSuccessful;
|
return response.isSuccessful;
|
||||||
@@ -64,10 +62,7 @@ export class OnspringClient {
|
|||||||
public async getApps(
|
public async getApps(
|
||||||
pagingRequest: PagingRequest = new PagingRequest(1, 50)
|
pagingRequest: PagingRequest = new PagingRequest(1, 50)
|
||||||
): Promise<ApiResponse<GetPagedAppsResponse>> {
|
): Promise<ApiResponse<GetPagedAppsResponse>> {
|
||||||
const endpoint = EndpointFactory.getAppsEndpoint(
|
const endpoint = EndpointFactory.getAppsEndpoint(pagingRequest);
|
||||||
this._client.defaults.baseURL,
|
|
||||||
pagingRequest
|
|
||||||
);
|
|
||||||
|
|
||||||
var apiResponse = await this.get<any>(endpoint);
|
var apiResponse = await this.get<any>(endpoint);
|
||||||
|
|
||||||
@@ -79,10 +74,7 @@ export class OnspringClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getAppById(appId: number): Promise<ApiResponse<App>> {
|
public async getAppById(appId: number): Promise<ApiResponse<App>> {
|
||||||
const endpoint = EndpointFactory.getAppByIdEndpoint(
|
const endpoint = EndpointFactory.getAppByIdEndpoint(appId);
|
||||||
this._client.defaults.baseURL,
|
|
||||||
appId
|
|
||||||
);
|
|
||||||
|
|
||||||
var apiResponse = await this.get<any>(endpoint);
|
var apiResponse = await this.get<any>(endpoint);
|
||||||
|
|
||||||
|
|||||||
@@ -23,16 +23,16 @@ export class ApiResponse<T> {
|
|||||||
/**
|
/**
|
||||||
* @property {T} data - The data of the response.
|
* @property {T} data - The data of the response.
|
||||||
*/
|
*/
|
||||||
public data: T;
|
public data: T | null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor - Creates a new instance of the ApiResponse class.
|
* @constructor - Creates a new instance of the ApiResponse class.
|
||||||
* @param {number} statusCode - The status code of the response.
|
* @param {number} statusCode - The status code of the response.
|
||||||
* @param {string} message - The message 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.
|
* @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.statusCode = statusCode;
|
||||||
this.isSuccessful = statusCode < 400;
|
this.isSuccessful = statusCode < 400;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ export class ArgumentValidator {
|
|||||||
public static isValidUrl(value: string | null | undefined): boolean {
|
public static isValidUrl(value: string | null | undefined): boolean {
|
||||||
let url: URL;
|
let url: URL;
|
||||||
|
|
||||||
|
if (value === null || value === undefined) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
url = new URL(value);
|
url = new URL(value);
|
||||||
} catch (error) {
|
} 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.
|
* @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 {
|
public static isValidPageSize(value: number | null | undefined): boolean {
|
||||||
|
if (value === null || value === undefined) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return value > 0 && value <= 1000;
|
return value > 0 && value <= 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +49,10 @@ export class ArgumentValidator {
|
|||||||
* @remarks - A valid page number is a number greater than 0.
|
* @remarks - A valid page number is a number greater than 0.
|
||||||
*/
|
*/
|
||||||
public static isValidPageNumber(value: number | null | undefined): boolean {
|
public static isValidPageNumber(value: number | null | undefined): boolean {
|
||||||
|
if (value === null || value === undefined) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return value > 0;
|
return value > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,242 +5,197 @@ import { PagingRequest } from './PagingRequest';
|
|||||||
*/
|
*/
|
||||||
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.
|
* @returns {string} - The ping endpoint.
|
||||||
*/
|
*/
|
||||||
public static getPingEndpoint(baseUrl: string): string {
|
public static getPingEndpoint(): string {
|
||||||
return `${baseUrl}/Ping`;
|
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.
|
* @returns {string} - The apps endpoint.
|
||||||
*/
|
*/
|
||||||
public static getAppsEndpoint(
|
public static getAppsEndpoint(pagingRequest: PagingRequest): string {
|
||||||
baseUrl: string,
|
return `/Apps?pageSize=${pagingRequest.pageSize}&pageNumber=${pagingRequest.pageNumber}`;
|
||||||
pagingRequest: PagingRequest
|
|
||||||
): string {
|
|
||||||
return `${baseUrl}/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.
|
* @param {number} id - The id of the app.
|
||||||
* @returns {string} - The app by id endpoint.
|
* @returns {string} - The app by id endpoint.
|
||||||
*/
|
*/
|
||||||
public static getAppByIdEndpoint(baseUrl: string, id: number): string {
|
public static getAppByIdEndpoint(id: number): string {
|
||||||
return `${baseUrl}/Apps/id/${id}`;
|
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.
|
* @returns {string} - The apps by ids endpoint.
|
||||||
*/
|
*/
|
||||||
public static getAppsByIdsEndpoint(baseUrl: string): string {
|
public static getAppsByIdsEndpoint(): string {
|
||||||
return `${baseUrl}/Apps/batch-get`;
|
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.
|
* @param {number} id - The id of the field.
|
||||||
* @returns {string} - The field by id endpoint.
|
* @returns {string} - The field by id endpoint.
|
||||||
*/
|
*/
|
||||||
public static getFieldByIdEndpoint(baseUrl: string, id: number): string {
|
public static getFieldByIdEndpoint(id: number): string {
|
||||||
return `${baseUrl}/Fields/id/${id}`;
|
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.
|
* @returns {string} - The fields by ids endpoint.
|
||||||
*/
|
*/
|
||||||
public static getFieldsByIdsEndpoint(baseUrl: string): string {
|
public static getFieldsByIdsEndpoint(): string {
|
||||||
return `${baseUrl}/Fields/batch-get`;
|
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.
|
* @param {number} id - The id of the app.
|
||||||
* @returns {string} - The fields by app id endpoint.
|
* @returns {string} - The fields by app id endpoint.
|
||||||
*/
|
*/
|
||||||
public static getFieldsByAppIdEndpoint(baseUrl: string, id: number): string {
|
public static getFieldsByAppIdEndpoint(id: number): string {
|
||||||
return `${baseUrl}/Fields/appId/${id}`;
|
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} recordId - The id of the record.
|
||||||
* @param {number} fieldId - The id of the field.
|
* @param {number} fieldId - The id of the field.
|
||||||
* @param {number} fileId - The id of the file.
|
* @param {number} fileId - The id of the file.
|
||||||
* @returns {string} - The file info by id endpoint.
|
* @returns {string} - The file info by id endpoint.
|
||||||
*/
|
*/
|
||||||
public static getFileInfoByIdEndpoint(
|
public static getFileInfoByIdEndpoint(
|
||||||
baseUrl: string,
|
|
||||||
recordId: number,
|
recordId: number,
|
||||||
fieldId: number,
|
fieldId: number,
|
||||||
fileId: number
|
fileId: number
|
||||||
): string {
|
): 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} recordId - The id of the record.
|
||||||
* @param {number} fieldId - The id of the field.
|
* @param {number} fieldId - The id of the field.
|
||||||
* @param {number} fileId - The id of the file.
|
* @param {number} fileId - The id of the file.
|
||||||
* @returns {string} - The delete file by id endpoint.
|
* @returns {string} - The delete file by id endpoint.
|
||||||
*/
|
*/
|
||||||
public static getDeleteFileByIdEndpoint(
|
public static getDeleteFileByIdEndpoint(
|
||||||
baseUrl: string,
|
|
||||||
recordId: number,
|
recordId: number,
|
||||||
fieldId: number,
|
fieldId: number,
|
||||||
fileId: number
|
fileId: number
|
||||||
): string {
|
): 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} recordId - The id of the record.
|
||||||
* @param {number} fieldId - The id of the field.
|
* @param {number} fieldId - The id of the field.
|
||||||
* @param {number} fileId - The id of the file.
|
* @param {number} fileId - The id of the file.
|
||||||
* @returns {string} - The file by id endpoint.
|
* @returns {string} - The file by id endpoint.
|
||||||
*/
|
*/
|
||||||
public static getFileByIdEndpoint(
|
public static getFileByIdEndpoint(
|
||||||
baseUrl: string,
|
|
||||||
recordId: number,
|
recordId: number,
|
||||||
fieldId: number,
|
fieldId: number,
|
||||||
fileId: number
|
fileId: number
|
||||||
): string {
|
): 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.
|
* @returns {string} - The save file endpoint.
|
||||||
*/
|
*/
|
||||||
public static getSaveFileEndpoint(baseUrl: string): string {
|
public static getSaveFileEndpoint(): string {
|
||||||
return `${baseUrl}/Files`;
|
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.
|
* @param {number} listId - The id of the list.
|
||||||
* @returns {string} - The add or update list item endpoint.
|
* @returns {string} - The add or update list item endpoint.
|
||||||
*/
|
*/
|
||||||
public static getAddOrUpdateListItemEndpoint(
|
public static getAddOrUpdateListItemEndpoint(listId: number): string {
|
||||||
baseUrl: string,
|
return `/Lists/id/${listId}/items`;
|
||||||
listId: number
|
|
||||||
): string {
|
|
||||||
return `${baseUrl}/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 {number} listId - The id of the list.
|
||||||
* @param {string} itemId - The id of the list item.
|
* @param {string} itemId - The id of the list item.
|
||||||
* @returns {string} - The delete list item endpoint.
|
* @returns {string} - The delete list item endpoint.
|
||||||
*/
|
*/
|
||||||
public static getDeleteListItemEndpoint(
|
public static getDeleteListItemEndpoint(
|
||||||
baseUrl: string,
|
|
||||||
listId: number,
|
listId: number,
|
||||||
itemId: string
|
itemId: string
|
||||||
): 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.
|
* @param {number} appId - The id of the app.
|
||||||
* @returns {string} - The get records by app id endpoint.
|
* @returns {string} - The get records by app id endpoint.
|
||||||
*/
|
*/
|
||||||
public static getRecordsByAppIdEndpoint(
|
public static getRecordsByAppIdEndpoint(appId: number): string {
|
||||||
baseUrl: string,
|
return `/Records/appId/${appId}`;
|
||||||
appId: number
|
|
||||||
): string {
|
|
||||||
return `${baseUrl}/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} appId - The id of the app.
|
||||||
* @param {number} recordId - The id of the record.
|
* @param {number} recordId - The id of the record.
|
||||||
* @returns {string} - The get record by id endpoint.
|
* @returns {string} - The get record by id endpoint.
|
||||||
*/
|
*/
|
||||||
public static getRecordByIdEndpoint(
|
public static getRecordByIdEndpoint(appId: number, recordId: number): string {
|
||||||
baseUrl: string,
|
return `/Records/appId/${appId}/recordId/${recordId}`;
|
||||||
appId: number,
|
|
||||||
recordId: number
|
|
||||||
): string {
|
|
||||||
return `${baseUrl}/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} appId - The id of the app.
|
||||||
* @param {number} recordId - The id of the record.
|
* @param {number} recordId - The id of the record.
|
||||||
* @returns {string} - The delete record by id endpoint.
|
* @returns {string} - The delete record by id endpoint.
|
||||||
*/
|
*/
|
||||||
public static getDeleteRecordByIdEndpoint(
|
public static getDeleteRecordByIdEndpoint(
|
||||||
baseUrl: string,
|
|
||||||
appId: number,
|
appId: number,
|
||||||
recordId: number
|
recordId: number
|
||||||
): string {
|
): 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.
|
* @returns {string} - The get records by ids endpoint.
|
||||||
*/
|
*/
|
||||||
public static getRecordsByIdsEndpoint(baseUrl: string): string {
|
public static getRecordsByIdsEndpoint(): string {
|
||||||
return `${baseUrl}/Records/batch-get`;
|
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.
|
* @returns {string} - The query records endpoint.
|
||||||
*/
|
*/
|
||||||
public static getQueryRecordsEndpoint(baseUrl: string): string {
|
public static getQueryRecordsEndpoint(): string {
|
||||||
return `${baseUrl}/Records/query`;
|
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.
|
* @returns {string} - The add or update record endpoint.
|
||||||
*/
|
*/
|
||||||
public static getAddOrUpdateRecordEndpoint(baseUrl: string): string {
|
public static getAddOrUpdateRecordEndpoint(): string {
|
||||||
return `${baseUrl}/Records`;
|
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.
|
* @returns {string} - The delete records by ids endpoint.
|
||||||
*/
|
*/
|
||||||
public static getDeleteRecordsByIdsEndpoint(baseUrl: string): string {
|
public static getDeleteRecordsByIdsEndpoint(): string {
|
||||||
return `${baseUrl}/Records/batch-delete`;
|
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.
|
* @param {number} reportId - The id of the report.
|
||||||
* @returns {string} - The get report by id endpoint.
|
* @returns {string} - The get report by id endpoint.
|
||||||
*/
|
*/
|
||||||
public static getReportByIdEndpoint(
|
public static getReportByIdEndpoint(reportId: number): string {
|
||||||
baseUrl: string,
|
return `/Reports/id/${reportId}`;
|
||||||
reportId: number
|
|
||||||
): string {
|
|
||||||
return `${baseUrl}/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.
|
* @param {number} appId - The id of the app.
|
||||||
* @returns {string} - The get reports by app id endpoint.
|
* @returns {string} - The get reports by app id endpoint.
|
||||||
*/
|
*/
|
||||||
public static getReportsByAppIdEndpoint(
|
public static getReportsByAppIdEndpoint(appId: number): string {
|
||||||
baseUrl: string,
|
return `/Reports/appId/${appId}`;
|
||||||
appId: number
|
|
||||||
): string {
|
|
||||||
return `${baseUrl}/Reports/appId/${appId}`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,6 +109,8 @@ describe('ApiResponse', function () {
|
|||||||
|
|
||||||
expect(appsPagedResponse).to.be.instanceOf(ApiResponse);
|
expect(appsPagedResponse).to.be.instanceOf(ApiResponse);
|
||||||
expect(appsPagedResponse.data).to.be.instanceOf(GetPagedAppsResponse);
|
expect(appsPagedResponse.data).to.be.instanceOf(GetPagedAppsResponse);
|
||||||
|
expect(appsPagedResponse.data).to.not.be.null;
|
||||||
|
if (appsPagedResponse.data != null) {
|
||||||
expect(appsPagedResponse.data.totalPages).to.equal(1);
|
expect(appsPagedResponse.data.totalPages).to.equal(1);
|
||||||
expect(appsPagedResponse.data.totalRecords).to.equal(2);
|
expect(appsPagedResponse.data.totalRecords).to.equal(2);
|
||||||
expect(appsPagedResponse.data.pageNumber).to.equal(1);
|
expect(appsPagedResponse.data.pageNumber).to.equal(1);
|
||||||
@@ -117,6 +119,7 @@ describe('ApiResponse', function () {
|
|||||||
expect(appsPagedResponse.data.items).to.have.lengthOf(2);
|
expect(appsPagedResponse.data.items).to.have.lengthOf(2);
|
||||||
expect(appsPagedResponse.data.items[0]).to.be.instanceOf(App);
|
expect(appsPagedResponse.data.items[0]).to.be.instanceOf(App);
|
||||||
expect(appsPagedResponse.data.items[1]).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 () {
|
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).to.be.instanceOf(ApiResponse);
|
||||||
expect(appsPagedResponse.data).to.be.instanceOf(GetPagedAppsResponse);
|
expect(appsPagedResponse.data).to.be.instanceOf(GetPagedAppsResponse);
|
||||||
|
expect(appsPagedResponse.data).to.not.be.null;
|
||||||
|
if (appsPagedResponse.data != null) {
|
||||||
expect(appsPagedResponse.data.totalPages).to.equal(0);
|
expect(appsPagedResponse.data.totalPages).to.equal(0);
|
||||||
expect(appsPagedResponse.data.totalRecords).to.equal(0);
|
expect(appsPagedResponse.data.totalRecords).to.equal(0);
|
||||||
expect(appsPagedResponse.data.pageNumber).to.equal(0);
|
expect(appsPagedResponse.data.pageNumber).to.equal(0);
|
||||||
expect(appsPagedResponse.data.pageSize).to.equal(0);
|
expect(appsPagedResponse.data.pageSize).to.equal(0);
|
||||||
expect(appsPagedResponse.data.items).to.be.instanceOf(Array);
|
expect(appsPagedResponse.data.items).to.be.instanceOf(Array);
|
||||||
expect(appsPagedResponse.data.items).to.have.lengthOf(0);
|
expect(appsPagedResponse.data.items).to.have.lengthOf(0);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -163,11 +169,14 @@ describe('ApiResponse', function () {
|
|||||||
|
|
||||||
expect(appResponse).to.be.instanceOf(ApiResponse);
|
expect(appResponse).to.be.instanceOf(ApiResponse);
|
||||||
expect(appResponse.data).to.be.instanceOf(App);
|
expect(appResponse.data).to.be.instanceOf(App);
|
||||||
|
expect(appResponse.data).to.not.be.null;
|
||||||
|
if (appResponse.data != null) {
|
||||||
expect(appResponse.data.id).to.equal(1);
|
expect(appResponse.data.id).to.equal(1);
|
||||||
expect(appResponse.data.name).to.equal('Test App');
|
expect(appResponse.data.name).to.equal('Test App');
|
||||||
expect(appResponse.data.href).to.equal(
|
expect(appResponse.data.href).to.equal(
|
||||||
'https://api.onspring.dev/apps/id/1'
|
'https://api.onspring.dev/apps/id/1'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,177 +3,164 @@ import { expect } from 'chai';
|
|||||||
import { PagingRequest } from '../src/models/PagingRequest';
|
import { PagingRequest } from '../src/models/PagingRequest';
|
||||||
|
|
||||||
describe('EndpointFactory', function () {
|
describe('EndpointFactory', function () {
|
||||||
const baseUrl = 'https://api.onspring.com';
|
|
||||||
|
|
||||||
describe('getPingEndpoint', function () {
|
describe('getPingEndpoint', function () {
|
||||||
it('should return the correct ping endpoint', function () {
|
it('should return the correct ping endpoint', function () {
|
||||||
const result = EndpointFactory.getPingEndpoint(baseUrl);
|
const result = EndpointFactory.getPingEndpoint();
|
||||||
expect(result).to.equal(`${baseUrl}/Ping`);
|
expect(result).to.equal('/Ping');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getAppsEndpoint', function () {
|
describe('getAppsEndpoint', function () {
|
||||||
it('should return the correct apps endpoint with paging params based on paging request parameter passed', function () {
|
it('should return the correct apps endpoint with paging params based on paging request parameter passed', function () {
|
||||||
const result = EndpointFactory.getAppsEndpoint(
|
const result = EndpointFactory.getAppsEndpoint(
|
||||||
baseUrl,
|
|
||||||
new PagingRequest(2, 1000)
|
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 () {
|
describe('getAppByIdEndpoint', function () {
|
||||||
it('should return the correct app by id endpoint', function () {
|
it('should return the correct app by id endpoint', function () {
|
||||||
const result = EndpointFactory.getAppByIdEndpoint(baseUrl, 1);
|
const result = EndpointFactory.getAppByIdEndpoint(1);
|
||||||
expect(result).to.equal(`${baseUrl}/Apps/id/1`);
|
expect(result).to.equal('/Apps/id/1');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getAppsByIdsEndpoint', function () {
|
describe('getAppsByIdsEndpoint', function () {
|
||||||
it('should return the correct apps by ids endpoint', function () {
|
it('should return the correct apps by ids endpoint', function () {
|
||||||
const result = EndpointFactory.getAppsByIdsEndpoint(baseUrl);
|
const result = EndpointFactory.getAppsByIdsEndpoint();
|
||||||
expect(result).to.equal(`${baseUrl}/Apps/batch-get`);
|
expect(result).to.equal('/Apps/batch-get');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getFieldByIdEndpoint', function () {
|
describe('getFieldByIdEndpoint', function () {
|
||||||
it('should return the correct field by id endpoint', function () {
|
it('should return the correct field by id endpoint', function () {
|
||||||
const result = EndpointFactory.getFieldByIdEndpoint(baseUrl, 1);
|
const result = EndpointFactory.getFieldByIdEndpoint(1);
|
||||||
expect(result).to.equal(`${baseUrl}/Fields/id/1`);
|
expect(result).to.equal('/Fields/id/1');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getFieldsByIdsEndpoint', function () {
|
describe('getFieldsByIdsEndpoint', function () {
|
||||||
it('should return the correct fields by ids endpoint', function () {
|
it('should return the correct fields by ids endpoint', function () {
|
||||||
const result = EndpointFactory.getFieldsByIdsEndpoint(baseUrl);
|
const result = EndpointFactory.getFieldsByIdsEndpoint();
|
||||||
expect(result).to.equal(`${baseUrl}/Fields/batch-get`);
|
expect(result).to.equal('/Fields/batch-get');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getFieldsByAppIdEndpoint', function () {
|
describe('getFieldsByAppIdEndpoint', function () {
|
||||||
it('should return the correct fields by app id endpoint', function () {
|
it('should return the correct fields by app id endpoint', function () {
|
||||||
const result = EndpointFactory.getFieldsByAppIdEndpoint(baseUrl, 1);
|
const result = EndpointFactory.getFieldsByAppIdEndpoint(1);
|
||||||
expect(result).to.equal(`${baseUrl}/Fields/appId/1`);
|
expect(result).to.equal('/Fields/appId/1');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getFileInfoByIdEndpoint', function () {
|
describe('getFileInfoByIdEndpoint', function () {
|
||||||
it('should return the correct get file info endpoint', function () {
|
it('should return the correct get file info endpoint', function () {
|
||||||
const result = EndpointFactory.getFileInfoByIdEndpoint(baseUrl, 1, 2, 3);
|
const result = EndpointFactory.getFileInfoByIdEndpoint(1, 2, 3);
|
||||||
expect(result).to.equal(`${baseUrl}/Files/recordId/1/fieldId/2/fileId/3`);
|
expect(result).to.equal('/Files/recordId/1/fieldId/2/fileId/3');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getDeleteFileByIdEndpoint', function () {
|
describe('getDeleteFileByIdEndpoint', function () {
|
||||||
it('should return the correct delete file endpoint', function () {
|
it('should return the correct delete file endpoint', function () {
|
||||||
const result = EndpointFactory.getDeleteFileByIdEndpoint(
|
const result = EndpointFactory.getDeleteFileByIdEndpoint(1, 2, 3);
|
||||||
baseUrl,
|
expect(result).to.equal('/Files/recordId/1/fieldId/2/fileId/3/file');
|
||||||
1,
|
|
||||||
2,
|
|
||||||
3
|
|
||||||
);
|
|
||||||
expect(result).to.equal(
|
|
||||||
`${baseUrl}/Files/recordId/1/fieldId/2/fileId/3/file`
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getFileByIdEndpoint', function () {
|
describe('getFileByIdEndpoint', function () {
|
||||||
it('should return the correct get file endpoint', function () {
|
it('should return the correct get file endpoint', function () {
|
||||||
const result = EndpointFactory.getFileByIdEndpoint(baseUrl, 1, 2, 3);
|
const result = EndpointFactory.getFileByIdEndpoint(1, 2, 3);
|
||||||
expect(result).to.equal(
|
expect(result).to.equal('/Files/recordId/1/fieldId/2/fileId/3/file');
|
||||||
`${baseUrl}/Files/recordId/1/fieldId/2/fileId/3/file`
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getSaveFileEndpoint', function () {
|
describe('getSaveFileEndpoint', function () {
|
||||||
it('should return the correct save file endpoint', function () {
|
it('should return the correct save file endpoint', function () {
|
||||||
const result = EndpointFactory.getSaveFileEndpoint(baseUrl);
|
const result = EndpointFactory.getSaveFileEndpoint();
|
||||||
expect(result).to.equal(`${baseUrl}/Files`);
|
expect(result).to.equal('/Files');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getAddOrUpdateListItemEndpoint', function () {
|
describe('getAddOrUpdateListItemEndpoint', function () {
|
||||||
it('should return the correct add or update list item endpoint', function () {
|
it('should return the correct add or update list item endpoint', function () {
|
||||||
const result = EndpointFactory.getAddOrUpdateListItemEndpoint(baseUrl, 1);
|
const result = EndpointFactory.getAddOrUpdateListItemEndpoint(1);
|
||||||
expect(result).to.equal(`${baseUrl}/Lists/id/1/items`);
|
expect(result).to.equal('/Lists/id/1/items');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getDeleteListItemEndpoint', function () {
|
describe('getDeleteListItemEndpoint', function () {
|
||||||
it('should return the correct delete list item endpoint', function () {
|
it('should return the correct delete list item endpoint', function () {
|
||||||
const result = EndpointFactory.getDeleteListItemEndpoint(
|
const result = EndpointFactory.getDeleteListItemEndpoint(
|
||||||
baseUrl,
|
|
||||||
1,
|
1,
|
||||||
'612ac495-8aad-44fd-b57d-1ae798dcf1a5'
|
'612ac495-8aad-44fd-b57d-1ae798dcf1a5'
|
||||||
);
|
);
|
||||||
expect(result).to.equal(
|
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 () {
|
describe('getRecordsByAppIdEndpoint', function () {
|
||||||
it('should return the correct records by app id endpoint', function () {
|
it('should return the correct records by app id endpoint', function () {
|
||||||
const result = EndpointFactory.getRecordsByAppIdEndpoint(baseUrl, 1);
|
const result = EndpointFactory.getRecordsByAppIdEndpoint(1);
|
||||||
expect(result).to.equal(`${baseUrl}/Records/appId/1`);
|
expect(result).to.equal('/Records/appId/1');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getRecordByIdEndpoint', function () {
|
describe('getRecordByIdEndpoint', function () {
|
||||||
it('should return the correct record by id endpoint', function () {
|
it('should return the correct record by id endpoint', function () {
|
||||||
const result = EndpointFactory.getRecordByIdEndpoint(baseUrl, 1, 2);
|
const result = EndpointFactory.getRecordByIdEndpoint(1, 2);
|
||||||
expect(result).to.equal(`${baseUrl}/Records/appId/1/recordId/2`);
|
expect(result).to.equal('/Records/appId/1/recordId/2');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getDeleteRecordByIdEndpoint', function () {
|
describe('getDeleteRecordByIdEndpoint', function () {
|
||||||
it('should return the correct delete record by id endpoint', function () {
|
it('should return the correct delete record by id endpoint', function () {
|
||||||
const result = EndpointFactory.getDeleteRecordByIdEndpoint(baseUrl, 1, 2);
|
const result = EndpointFactory.getDeleteRecordByIdEndpoint(1, 2);
|
||||||
expect(result).to.equal(`${baseUrl}/Records/appId/1/recordId/2`);
|
expect(result).to.equal('/Records/appId/1/recordId/2');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getRecordsByIdsEndpoint', function () {
|
describe('getRecordsByIdsEndpoint', function () {
|
||||||
it('should return the correct records by ids endpoint', function () {
|
it('should return the correct records by ids endpoint', function () {
|
||||||
const result = EndpointFactory.getRecordsByIdsEndpoint(baseUrl);
|
const result = EndpointFactory.getRecordsByIdsEndpoint();
|
||||||
expect(result).to.equal(`${baseUrl}/Records/batch-get`);
|
expect(result).to.equal('/Records/batch-get');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getQueryRecordsEndpoint', function () {
|
describe('getQueryRecordsEndpoint', function () {
|
||||||
it('should return the correct query records endpoint', function () {
|
it('should return the correct query records endpoint', function () {
|
||||||
const result = EndpointFactory.getQueryRecordsEndpoint(baseUrl);
|
const result = EndpointFactory.getQueryRecordsEndpoint();
|
||||||
expect(result).to.equal(`${baseUrl}/Records/query`);
|
expect(result).to.equal('/Records/query');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getAddOrUpdateRecordEndpoint', function () {
|
describe('getAddOrUpdateRecordEndpoint', function () {
|
||||||
it('should return the correct add or update record endpoint', function () {
|
it('should return the correct add or update record endpoint', function () {
|
||||||
const result = EndpointFactory.getAddOrUpdateRecordEndpoint(baseUrl);
|
const result = EndpointFactory.getAddOrUpdateRecordEndpoint();
|
||||||
expect(result).to.equal(`${baseUrl}/Records`);
|
expect(result).to.equal('/Records');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getDeleteRecordsByIdsEndpoint', function () {
|
describe('getDeleteRecordsByIdsEndpoint', function () {
|
||||||
it('should return the correct delete records by ids endpoint', function () {
|
it('should return the correct delete records by ids endpoint', function () {
|
||||||
const result = EndpointFactory.getDeleteRecordsByIdsEndpoint(baseUrl);
|
const result = EndpointFactory.getDeleteRecordsByIdsEndpoint();
|
||||||
expect(result).to.equal(`${baseUrl}/Records/batch-delete`);
|
expect(result).to.equal('/Records/batch-delete');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getReportByIdEndpoint', function () {
|
describe('getReportByIdEndpoint', function () {
|
||||||
it('should return the correct report by id endpoint', function () {
|
it('should return the correct report by id endpoint', function () {
|
||||||
const result = EndpointFactory.getReportByIdEndpoint(baseUrl, 1);
|
const result = EndpointFactory.getReportByIdEndpoint(1);
|
||||||
expect(result).to.equal(`${baseUrl}/Reports/id/1`);
|
expect(result).to.equal('/Reports/id/1');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getReportsByAppIdEndpoint', function () {
|
describe('getReportsByAppIdEndpoint', function () {
|
||||||
it('should return the correct reports by app id endpoint', function () {
|
it('should return the correct reports by app id endpoint', function () {
|
||||||
const result = EndpointFactory.getReportsByAppIdEndpoint(baseUrl, 1);
|
const result = EndpointFactory.getReportsByAppIdEndpoint(1);
|
||||||
expect(result).to.equal(`${baseUrl}/Reports/appId/1`);
|
expect(result).to.equal('/Reports/appId/1');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -269,10 +269,13 @@ describe('OnspringClient', function () {
|
|||||||
expect(result.data).to.have.property('totalPages', 1);
|
expect(result.data).to.have.property('totalPages', 1);
|
||||||
expect(result.data).to.have.property('totalRecords', 2);
|
expect(result.data).to.have.property('totalRecords', 2);
|
||||||
expect(result.data).to.have.property('items');
|
expect(result.data).to.have.property('items');
|
||||||
|
expect(result.data).to.not.be.null;
|
||||||
|
if (result.data != null) {
|
||||||
expect(result.data.items).to.be.instanceOf(Array);
|
expect(result.data.items).to.be.instanceOf(Array);
|
||||||
expect(result.data.items).to.have.lengthOf(2);
|
expect(result.data.items).to.have.lengthOf(2);
|
||||||
expect(result.data.items[0]).to.be.instanceOf(App);
|
expect(result.data.items[0]).to.be.instanceOf(App);
|
||||||
expect(result.data.items[1]).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 () {
|
it('should return a promise that resolves to an api response when request returns a 400 status code', async function () {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"strictNullChecks": true,
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"target": "es2015",
|
"target": "es2015",
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user