feat: implement getReportById method

This commit is contained in:
StevanFreeborn
2023-02-09 18:23:49 -06:00
parent 61cb4d2929
commit 3b3e210920
10 changed files with 393 additions and 4 deletions
+52
View File
@@ -21,6 +21,8 @@ import path from 'path';
import { ListItemResponse } from '../src/models/ListItemResponse';
import { GetPagedReportsResponse } from '../src/models/GetPagedReportsResponse';
import { Report } from '../src/models/Report';
import { ReportData } from '../src/models/ReportData';
import { Row } from '../src/models/Row';
describe('ApiResponse', function () {
it('should be defined', function () {
@@ -1014,4 +1016,54 @@ describe('ApiResponse', function () {
}
});
});
describe('asReportDataType', function () {
it('should be defined', function () {
expect(ApiResponse.prototype.asReportDataType).to.not.be.undefined;
});
it('should be a function', function () {
expect(ApiResponse.prototype.asReportDataType).to.be.a('function');
});
it('should have no parameters', function () {
expect(ApiResponse.prototype.asReportDataType).to.have.lengthOf(0);
});
it('should return an ApiResponse<ReportData>', function () {
const mockResponseData = {
columns: ['field 1', 'field 2'],
rows: [
{
recordId: 1,
cells: ['field value 1', 'field value 2'],
},
{
recordId: 2,
cells: ['field value 1', 'field value 2'],
},
],
};
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
const reportData = apiResponse.asReportDataType();
expect(reportData).to.be.an.instanceof(ApiResponse<ReportData>);
expect(reportData.data).to.be.an.instanceof(ReportData);
expect(reportData.data).to.have.property('columns').that.is.an('array');
expect(reportData.data).to.have.property('rows').that.is.an('array');
expect(reportData.data).to.not.be.null;
if (reportData.data != null) {
expect(reportData.data.columns).to.have.lengthOf(2);
reportData.data.columns.forEach((column) => {
expect(column).to.be.a('string');
});
expect(reportData.data.rows).to.have.lengthOf(2);
reportData.data.rows.forEach((row) => {
expect(row).to.be.an.instanceOf(Row);
});
}
});
});
});