feat: add integration tests for getReportById and getReportsByAppId methods
This commit is contained in:
@@ -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;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,11 +6,81 @@ describe('getReportsByAppId', function () {
|
||||
this.timeout(30000);
|
||||
this.retries(3);
|
||||
|
||||
it('should return a list of reports', async function () {});
|
||||
it('should return a list of reports', async function () {
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
|
||||
it('should return a 400 error if page size is invalid', async function () {});
|
||||
if (process.env.TEST_SURVEY_ID === undefined) {
|
||||
expect.fail('TEST_SURVEY_ID is not defined');
|
||||
}
|
||||
|
||||
it('should return a 401 error if the api key is invalid', async function () {});
|
||||
const response = await client.getReportsByAppId(
|
||||
parseInt(process.env.TEST_SURVEY_ID)
|
||||
);
|
||||
|
||||
it('should return a 403 error if the api key does not have access to one of the reports', 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;
|
||||
|
||||
if (response.data != null) {
|
||||
expect(response.data.pageNumber).to.not.be.null;
|
||||
expect(response.data.pageSize).to.not.be.null;
|
||||
expect(response.data.totalRecords).to.not.be.null;
|
||||
expect(response.data.totalPages).to.not.be.null;
|
||||
expect(response.data.items).to.not.be.null;
|
||||
expect(response.data.items).to.be.an('array');
|
||||
|
||||
response.data.items.forEach((report) => {
|
||||
expect(report.appId).to.not.be.null;
|
||||
expect(report.id).to.not.be.null;
|
||||
expect(report.name).to.not.be.null;
|
||||
expect(report.description).to.not.be.null;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('should return a 400 error if page size is invalid', async function () {
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
|
||||
if (process.env.TEST_SURVEY_ID === undefined) {
|
||||
expect.fail('TEST_SURVEY_ID is not defined');
|
||||
}
|
||||
|
||||
const response = await client.getReportsByAppId(
|
||||
parseInt(process.env.TEST_SURVEY_ID),
|
||||
{ pageSize: 1001, pageNumber: 1 }
|
||||
);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
expect(response.isSuccessful).to.be.false;
|
||||
expect(response.message).to.not.be.null.and.to.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.getReportsByAppId(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 one of the reports', async function () {
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
|
||||
if (process.env.TEST_APP_ID_NO_ACCESS === undefined) {
|
||||
expect.fail('TEST_APP_ID_NO_ACCESS is not defined');
|
||||
}
|
||||
|
||||
const response = await client.getReportsByAppId(
|
||||
parseInt(process.env.TEST_APP_ID_NO_ACCESS)
|
||||
);
|
||||
|
||||
expect(response.statusCode).to.equal(403);
|
||||
expect(response.isSuccessful).to.be.false;
|
||||
expect(response.message).to.not.be.null.and.to.not.be.undefined;
|
||||
expect(response.data).to.be.null;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,4 +16,7 @@ TEST_ATTACHMENT_FIELD_NO_ACCESS_APP=NEEDS_TO_BE_SET
|
||||
TEST_TEXT_FIELD=NEEDS_TO_BE_SET
|
||||
TEST_ATTACHMENT=NEEDS_TO_BE_SET
|
||||
TEST_IMAGE_FIELD=NEEDS_TO_BE_SET
|
||||
TEST_IMAGE=NEEDS_TO_BE_SET
|
||||
TEST_IMAGE=NEEDS_TO_BE_SET
|
||||
TEST_REPORT=NEEDS_TO_BE_SET
|
||||
TEST_REPORT_NO_ACCESS=NEEDS_TO_BE_SET
|
||||
TEST_REPORT_WITH_CHART_DATA=NEEDS_TO_BE_SET
|
||||
Reference in New Issue
Block a user