From 4fe1d7c4a78539cb9566700ab750d68b75191798 Mon Sep 17 00:00:00 2001 From: StevanFreeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Tue, 14 Feb 2023 22:14:45 -0600 Subject: [PATCH] feat: added getFieldsByAppId integration tests --- integrationTests/getAppById.spec.ts | 4 +- integrationTests/getApps.spec.ts | 4 +- integrationTests/getAppsByIds.spec.ts | 2 +- integrationTests/getFieldById.spec.ts | 4 +- integrationTests/getFieldsByAppId.spec.ts | 139 ++++++++++++++++++++++ 5 files changed, 146 insertions(+), 7 deletions(-) create mode 100644 integrationTests/getFieldsByAppId.spec.ts diff --git a/integrationTests/getAppById.spec.ts b/integrationTests/getAppById.spec.ts index 2127ce8..43d9214 100644 --- a/integrationTests/getAppById.spec.ts +++ b/integrationTests/getAppById.spec.ts @@ -59,7 +59,7 @@ describe('getAppById', function () { expect(response.statusCode).to.equal(403); expect(response.isSuccessful).to.be.false; - expect(response.message).to.not.be.null; + expect(response.message).to.not.be.undefined.and.not.be.null; expect(response.data).to.be.null; }); @@ -69,7 +69,7 @@ describe('getAppById', function () { expect(response.statusCode).to.equal(404); expect(response.isSuccessful).to.be.false; - expect(response.message).to.not.be.null; + expect(response.message).to.not.be.undefined.and.not.be.null; expect(response.data).to.be.null; }); }); diff --git a/integrationTests/getApps.spec.ts b/integrationTests/getApps.spec.ts index 5210ca7..c430fe0 100644 --- a/integrationTests/getApps.spec.ts +++ b/integrationTests/getApps.spec.ts @@ -59,7 +59,7 @@ describe('getApps', function () { expect(response.data.items).to.not.be.null; if (response.data.items != null) { - expect(response.data.items.length).to.be.greaterThan(0); + expect(response.data.items.length).to.equal(1); response.data.items.forEach((item) => { expect(item.id).to.not.be.null; expect(item.name).to.not.be.null; @@ -75,7 +75,7 @@ describe('getApps', function () { expect(response.statusCode).to.equal(400); expect(response.isSuccessful).to.be.false; - expect(response.message).to.not.be.null; + expect(response.message).to.not.be.undefined.and.not.be.null; expect(response.data).to.be.null; }); diff --git a/integrationTests/getAppsByIds.spec.ts b/integrationTests/getAppsByIds.spec.ts index 5806ef3..8a26738 100644 --- a/integrationTests/getAppsByIds.spec.ts +++ b/integrationTests/getAppsByIds.spec.ts @@ -68,7 +68,7 @@ describe('getAppsByIds', function () { expect(response.statusCode).to.equal(403); expect(response.isSuccessful).to.be.false; - expect(response.message).to.not.be.null; + expect(response.message).to.not.be.undefined.and.not.be.null; expect(response.data).to.be.null; }); }); diff --git a/integrationTests/getFieldById.spec.ts b/integrationTests/getFieldById.spec.ts index 21d8d3c..22400e7 100644 --- a/integrationTests/getFieldById.spec.ts +++ b/integrationTests/getFieldById.spec.ts @@ -63,7 +63,7 @@ describe('getAppById', function () { expect(response.statusCode).to.equal(403); expect(response.isSuccessful).to.be.false; - expect(response.message).to.not.be.null; + expect(response.message).to.not.be.undefined.and.not.be.null; expect(response.data).to.be.null; }); @@ -73,7 +73,7 @@ describe('getAppById', function () { expect(response.statusCode).to.equal(404); expect(response.isSuccessful).to.be.false; - expect(response.message).to.not.be.null; + expect(response.message).to.not.be.undefined.and.not.be.null; expect(response.data).to.be.null; }); }); diff --git a/integrationTests/getFieldsByAppId.spec.ts b/integrationTests/getFieldsByAppId.spec.ts new file mode 100644 index 0000000..1e9c69a --- /dev/null +++ b/integrationTests/getFieldsByAppId.spec.ts @@ -0,0 +1,139 @@ +import { OnspringClient, PagingRequest } from '../src/index'; +import { expect } from 'chai'; +import * as dotenv from 'dotenv'; +import path from 'path'; +const envPath = path.resolve(__dirname, '.env'); +dotenv.config({ path: envPath }); + +describe('getFieldsByAppId', function () { + this.timeout('30s'); + let baseURL; + let apiKey; + + before(function () { + baseURL = process.env.API_BASE_URL; + apiKey = process.env.SANDBOX_API_KEY; + }); + + it('should return a paged list of fields', async function () { + const client = new OnspringClient(baseURL, apiKey); + + if (process.env.TEST_SURVEY_ID === undefined) { + return expect.fail('TEST_SURVEY_ID is not defined'); + } + + const appId = parseInt(process.env.TEST_SURVEY_ID); + const response = await client.getFieldsByAppId(appId); + + 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.totalPages).to.not.be.null; + expect(response.data.totalRecords).to.not.be.null; + expect(response.data.items).to.not.be.null; + + if (response.data.items != null) { + expect(response.data.items.length).to.be.greaterThan(0); + response.data.items.forEach((item) => { + expect(item.id).to.not.be.null; + expect(item.name).to.not.be.null; + expect(item.appId).to.not.be.null; + expect(item.type).to.not.be.null; + expect(item.status).to.not.be.null; + expect(item.isRequired).to.not.be.null; + expect(item.isUnique).to.not.be.null; + }); + } + } + }); + + it('should return a paged list of fields with with correct page size and number when passed paging request', async function () { + const client = new OnspringClient(baseURL, apiKey); + + if (process.env.TEST_SURVEY_ID === undefined) { + return expect.fail('TEST_SURVEY_ID is not defined'); + } + + const appId = parseInt(process.env.TEST_SURVEY_ID); + const response = await client.getFieldsByAppId( + appId, + new PagingRequest(1, 1) + ); + + 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.equal(1); + expect(response.data.pageSize).to.equal(1); + expect(response.data.totalPages).to.not.be.null; + expect(response.data.totalRecords).to.not.be.null; + expect(response.data.items).to.not.be.null; + + if (response.data.items != null) { + expect(response.data.items.length).to.equal(1); + response.data.items.forEach((item) => { + expect(item.id).to.not.be.null; + expect(item.name).to.not.be.null; + expect(item.appId).to.not.be.null; + expect(item.type).to.not.be.null; + expect(item.status).to.not.be.null; + expect(item.isRequired).to.not.be.null; + expect(item.isUnique).to.not.be.null; + }); + } + } + }); + + it('should return a 400 response when an invalid page size is used', async function () { + const client = new OnspringClient(baseURL, apiKey); + + if (process.env.TEST_SURVEY_ID === undefined) { + return expect.fail('TEST_SURVEY_ID is not defined'); + } + + const appId = parseInt(process.env.TEST_SURVEY_ID); + const response = await client.getFieldsByAppId(appId, { + pageNumber: 1, + pageSize: 1001, + }); + + expect(response.statusCode).to.equal(400); + expect(response.isSuccessful).to.be.false; + expect(response.message).to.not.be.undefined.and.not.be.null; + expect(response.data).to.be.null; + }); + + it('should return a 401 response when an invalid api key is used', async function () { + const client = new OnspringClient(baseURL, 'invalid'); + const response = await client.getFieldsByAppId(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 response when api key does not have access to the app', async function () { + const client = new OnspringClient(baseURL, apiKey); + + if (process.env.TEST_APP_ID_NO_ACCESS === undefined) { + return expect.fail('TEST_APP_ID_NO_ACCESS is not defined'); + } + + const appId = parseInt(process.env.TEST_APP_ID_NO_ACCESS); + const response = await client.getFieldsByAppId(appId); + + expect(response.statusCode).to.equal(403); + expect(response.isSuccessful).to.be.false; + expect(response.message).to.not.be.undefined.and.not.be.null; + expect(response.data).to.be.null; + }); +});