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:
+28
-19
@@ -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'
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user