feat: add integration tests for getReportById and getReportsByAppId methods

This commit is contained in:
StevanFreeborn
2023-02-18 17:04:47 -06:00
parent 6c8127ffc6
commit 4001fb407d
3 changed files with 216 additions and 13 deletions
+138 -8
View File
@@ -1,4 +1,4 @@
import { OnspringClient } from './../../src';
import { DataFormat, OnspringClient, ReportDataType } from './../../src';
import { expect } from 'chai';
import { baseURL, apiKey } from '../mochaRootHooks';
@@ -6,17 +6,147 @@ describe('getReportById', function () {
this.timeout(30000);
this.retries(3);
it('should return a report', async function () {});
it('should return a report', async function () {
const client = new OnspringClient(baseURL, apiKey);
it('should return report data for a report with chart data when report data is requested', async function () {});
if (process.env.TEST_REPORT === undefined) {
expect.fail('TEST_REPORT is not defined');
}
it('should return chart data for a report with a chart when chart data is requested', async function () {});
const response = await client.getReportById(
parseInt(process.env.TEST_REPORT)
);
it('should return a 400 error if chart data is requested for a report without chart data', async function () {});
expect(response.statusCode).to.equal(200);
expect(response.isSuccessful).to.be.true;
expect(response.message).to.equal('');
expect(response.data).to.not.be.null;
it('should return a 401 error if the api key is invalid', async function () {});
if (response.data != null) {
expect(response.data.columns).to.not.be.null;
expect(response.data.columns).to.be.an('array');
expect(response.data.rows).to.not.be.null;
expect(response.data.rows).to.be.an('array');
it('should return a 403 error if the api key does not have access to the report', async function () {});
response.data.rows.forEach((row) => {
expect(row).to.not.be.null;
expect(row.recordId).to.not.be.null;
expect(row.cells).to.not.be.null;
expect(row.cells).to.be.an('array');
});
}
});
it('should return a 404 error if the report does not exist', async function () {});
it('should return report data for a report with chart data when report data is requested', async function () {
const client = new OnspringClient(baseURL, apiKey);
if (process.env.TEST_REPORT_WITH_CHART_DATA === undefined) {
expect.fail('TEST_REPORT_WITH_CHART_DATA is not defined');
}
const response = await client.getReportById(
parseInt(process.env.TEST_REPORT_WITH_CHART_DATA)
);
expect(response.statusCode).to.equal(200);
expect(response.isSuccessful).to.be.true;
expect(response.message).to.equal('');
expect(response.data).to.not.be.null;
if (response.data != null) {
expect(response.data.columns).to.not.be.null;
expect(response.data.columns).to.be.an('array');
expect(response.data.rows).to.not.be.null;
expect(response.data.rows).to.be.an('array');
response.data.rows.forEach((row) => {
expect(row).to.not.be.null;
expect(row.recordId).to.not.be.null;
expect(row.cells).to.not.be.null;
expect(row.cells).to.be.an('array');
});
}
});
it('should return chart data for a report with a chart when chart data is requested', async function () {
const client = new OnspringClient(baseURL, apiKey);
if (process.env.TEST_REPORT_WITH_CHART_DATA === undefined) {
expect.fail('TEST_REPORT_WITH_CHART_DATA is not defined');
}
const response = await client.getReportById(
parseInt(process.env.TEST_REPORT_WITH_CHART_DATA),
DataFormat.Raw,
ReportDataType.ChartData
);
expect(response.statusCode).to.equal(200);
expect(response.isSuccessful).to.be.true;
expect(response.message).to.equal('');
expect(response.data).to.not.be.null;
if (response.data != null) {
expect(response.data.columns).to.not.be.null;
expect(response.data.columns).to.be.an('array');
expect(response.data.rows).to.not.be.null;
expect(response.data.rows).to.be.an('array');
response.data.rows.forEach((row) => {
expect(row).to.not.be.null;
expect(row.recordId).to.not.be.null;
expect(row.cells).to.not.be.null;
expect(row.cells).to.be.an('array');
});
}
});
it('should return a 400 error if chart data is requested for a report without chart data', async function () {
const client = new OnspringClient(baseURL, apiKey);
if (process.env.TEST_REPORT === undefined) {
expect.fail('TEST_REPORT is not defined');
}
const response = await client.getReportById(
parseInt(process.env.TEST_REPORT),
DataFormat.Raw,
ReportDataType.ChartData
);
expect(response.statusCode).to.equal(400);
expect(response.isSuccessful).to.be.false;
expect(response.message).to.not.be.null.and.not.be.undefined;
expect(response.data).to.be.null;
});
it('should return a 401 error if the api key is invalid', async function () {
const client = new OnspringClient(baseURL, 'invalid');
const response = await client.getReportById(1);
expect(response.statusCode).to.equal(401);
expect(response.isSuccessful).to.be.false;
expect(response.message).to.be.undefined;
expect(response.data).to.be.null;
});
it('should return a 403 error if the api key does not have access to the report', async function () {
const client = new OnspringClient(baseURL, apiKey);
const response = await client.getReportById(1);
expect(response.statusCode).to.equal(403);
expect(response.isSuccessful).to.be.false;
expect(response.message).to.not.be.null.and.not.be.undefined;
expect(response.data).to.be.null;
});
it('should return a 404 error if the report does not exist', async function () {
const client = new OnspringClient(baseURL, apiKey);
const response = await client.getReportById(0);
expect(response.statusCode).to.equal(404);
expect(response.isSuccessful).to.be.false;
expect(response.message).to.be.undefined;
expect(response.data).to.be.null;
});
});