From 6c8127ffc698e797b262b7a1d35bbb82d2d46f2f Mon Sep 17 00:00:00 2001 From: StevanFreeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Fri, 17 Feb 2023 22:35:11 -0600 Subject: [PATCH 1/3] feat: stub out integration tests for reports --- .../Reports/getReportsByAppId.spec.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/integrationTests/Reports/getReportsByAppId.spec.ts b/integrationTests/Reports/getReportsByAppId.spec.ts index e69de29..26ab88e 100644 --- a/integrationTests/Reports/getReportsByAppId.spec.ts +++ b/integrationTests/Reports/getReportsByAppId.spec.ts @@ -0,0 +1,16 @@ +import { OnspringClient } from '../../src'; +import { expect } from 'chai'; +import { baseURL, apiKey } from '../mochaRootHooks'; + +describe('getReportsByAppId', function () { + this.timeout(30000); + this.retries(3); + + it('should return a list of reports', async function () {}); + + it('should return a 400 error if page size is invalid', async function () {}); + + it('should return a 401 error if the api key is invalid', async function () {}); + + it('should return a 403 error if the api key does not have access to one of the reports', async function () {}); +}); From 4001fb407d12d97fb27dd8fe7906aefce9c7ce05 Mon Sep 17 00:00:00 2001 From: StevanFreeborn <=> Date: Sat, 18 Feb 2023 17:04:47 -0600 Subject: [PATCH 2/3] feat: add integration tests for getReportById and getReportsByAppId methods --- .../Reports/getReportById.spec.ts | 146 +++++++++++++++++- .../Reports/getReportsByAppId.spec.ts | 78 +++++++++- integrationTests/example.env | 5 +- 3 files changed, 216 insertions(+), 13 deletions(-) diff --git a/integrationTests/Reports/getReportById.spec.ts b/integrationTests/Reports/getReportById.spec.ts index 95b2dcd..4880555 100644 --- a/integrationTests/Reports/getReportById.spec.ts +++ b/integrationTests/Reports/getReportById.spec.ts @@ -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; + }); }); diff --git a/integrationTests/Reports/getReportsByAppId.spec.ts b/integrationTests/Reports/getReportsByAppId.spec.ts index 26ab88e..449edd3 100644 --- a/integrationTests/Reports/getReportsByAppId.spec.ts +++ b/integrationTests/Reports/getReportsByAppId.spec.ts @@ -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; + }); }); diff --git a/integrationTests/example.env b/integrationTests/example.env index 53991ea..51ce265 100644 --- a/integrationTests/example.env +++ b/integrationTests/example.env @@ -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 \ No newline at end of file +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 \ No newline at end of file From 818bd0dd194c6e616ae4419b44a187d169b87b3d Mon Sep 17 00:00:00 2001 From: StevanFreeborn <=> Date: Sat, 18 Feb 2023 17:16:53 -0600 Subject: [PATCH 3/3] feat: stub out integration tests for record methods --- integrationTests/Records/deleteRecordById.spec.ts | 5 +++++ integrationTests/Records/getRecordById.spec.ts | 5 +++++ integrationTests/Records/getRecordsByAppId.spec.ts | 5 +++++ integrationTests/Records/getRecordsByIds.spec.ts | 5 +++++ integrationTests/Records/queryRecords.spec.ts | 5 +++++ integrationTests/Records/saveRecord.spec.ts | 5 +++++ 6 files changed, 30 insertions(+) create mode 100644 integrationTests/Records/deleteRecordById.spec.ts create mode 100644 integrationTests/Records/getRecordById.spec.ts create mode 100644 integrationTests/Records/getRecordsByAppId.spec.ts create mode 100644 integrationTests/Records/getRecordsByIds.spec.ts create mode 100644 integrationTests/Records/queryRecords.spec.ts create mode 100644 integrationTests/Records/saveRecord.spec.ts diff --git a/integrationTests/Records/deleteRecordById.spec.ts b/integrationTests/Records/deleteRecordById.spec.ts new file mode 100644 index 0000000..a537f06 --- /dev/null +++ b/integrationTests/Records/deleteRecordById.spec.ts @@ -0,0 +1,5 @@ +import { OnspringClient } from './../../src'; +import { expect } from 'chai'; +import { baseURL, apiKey } from '../mochaRootHooks'; + +describe('deleteRecordById', function () {}); diff --git a/integrationTests/Records/getRecordById.spec.ts b/integrationTests/Records/getRecordById.spec.ts new file mode 100644 index 0000000..0c88518 --- /dev/null +++ b/integrationTests/Records/getRecordById.spec.ts @@ -0,0 +1,5 @@ +import { OnspringClient } from './../../src'; +import { expect } from 'chai'; +import { baseURL, apiKey } from '../mochaRootHooks'; + +describe('getRecordById', function () {}); diff --git a/integrationTests/Records/getRecordsByAppId.spec.ts b/integrationTests/Records/getRecordsByAppId.spec.ts new file mode 100644 index 0000000..7abef44 --- /dev/null +++ b/integrationTests/Records/getRecordsByAppId.spec.ts @@ -0,0 +1,5 @@ +import { OnspringClient } from './../../src'; +import { expect } from 'chai'; +import { baseURL, apiKey } from '../mochaRootHooks'; + +describe('getRecordsByAppId', function () {}); diff --git a/integrationTests/Records/getRecordsByIds.spec.ts b/integrationTests/Records/getRecordsByIds.spec.ts new file mode 100644 index 0000000..7d38c5c --- /dev/null +++ b/integrationTests/Records/getRecordsByIds.spec.ts @@ -0,0 +1,5 @@ +import { OnspringClient } from './../../src'; +import { expect } from 'chai'; +import { baseURL, apiKey } from '../mochaRootHooks'; + +describe('getRecordsByIds', function () {}); diff --git a/integrationTests/Records/queryRecords.spec.ts b/integrationTests/Records/queryRecords.spec.ts new file mode 100644 index 0000000..8595d66 --- /dev/null +++ b/integrationTests/Records/queryRecords.spec.ts @@ -0,0 +1,5 @@ +import { OnspringClient } from './../../src'; +import { expect } from 'chai'; +import { baseURL, apiKey } from '../mochaRootHooks'; + +describe('queryRecords', function () {}); diff --git a/integrationTests/Records/saveRecord.spec.ts b/integrationTests/Records/saveRecord.spec.ts new file mode 100644 index 0000000..84db01d --- /dev/null +++ b/integrationTests/Records/saveRecord.spec.ts @@ -0,0 +1,5 @@ +import { OnspringClient } from './../../src'; +import { expect } from 'chai'; +import { baseURL, apiKey } from '../mochaRootHooks'; + +describe('saveRecord', function () {});