feat: add integration tests for getRecordById method

This commit is contained in:
StevanFreeborn
2023-02-19 16:14:50 -06:00
parent 99c7e7f9f1
commit 06dda79e44
3 changed files with 122 additions and 4 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
{
"dotenv.enableAutocloaking": true
"dotenv.enableAutocloaking": false
}
+119 -2
View File
@@ -1,5 +1,122 @@
import { OnspringClient } from './../../src';
import { OnspringClient, GetRecordRequest, DataFormat } from './../../src';
import { expect } from 'chai';
import { baseURL, apiKey } from '../mochaRootHooks';
describe('getRecordById', function () {});
describe('getRecordById', function () {
this.timeout(30000);
this.retries(3);
it('should get a record', async function () {
const client = new OnspringClient(baseURL, apiKey);
if (process.env.TEST_SURVEY_ID === undefined) {
expect.fail('TEST_SURVEY_ID is not defined');
}
if (process.env.TEST_SURVEY_RECORD_ID === undefined) {
expect.fail('TEST_SURVEY_RECORD_ID is not defined');
}
const appId = parseInt(process.env.TEST_SURVEY_ID);
const recordId = parseInt(process.env.TEST_SURVEY_RECORD_ID);
const request = new GetRecordRequest(appId, recordId);
const response = await client.getRecordById(request);
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.appId).to.equal(appId);
expect(response.data.recordId).to.equal(recordId);
expect(response.data.fieldData).to.not.be.null;
if (response.data.fieldData != null) {
expect(response.data.fieldData.length).to.be.greaterThan(0);
response.data.fieldData.forEach((field) => {
expect(field.fieldId).to.not.be.null;
expect(field).to.not.be.null;
expect(field.type).to.not.be.null;
});
}
}
});
it('should get a record when fieldIds and data format are passed as parameters', async function () {
const client = new OnspringClient(baseURL, apiKey);
if (process.env.TEST_SURVEY_ID === undefined) {
expect.fail('TEST_SURVEY_ID is not defined');
}
if (process.env.TEST_SURVEY_RECORD_ID === undefined) {
expect.fail('TEST_SURVEY_RECORD_ID is not defined');
}
if (process.env.TEST_FIELD_ID === undefined) {
expect.fail('TEST_FIELD_ID is not defined');
}
const appId = parseInt(process.env.TEST_SURVEY_ID);
const recordId = parseInt(process.env.TEST_SURVEY_RECORD_ID);
const fieldId = parseInt(process.env.TEST_FIELD_ID);
const request = new GetRecordRequest(
appId,
recordId,
[fieldId],
DataFormat.Formatted
);
const response = await client.getRecordById(request);
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.appId).to.equal(appId);
expect(response.data.recordId).to.equal(recordId);
expect(response.data.fieldData).to.not.be.null;
if (response.data.fieldData != null) {
expect(response.data.fieldData.length).to.be.greaterThan(0);
response.data.fieldData.forEach((field) => {
expect(field.fieldId).to.not.be.null;
expect(field).to.not.be.null;
expect(field.type).to.not.be.null;
});
}
}
});
it('should return a 401 error when an invalid API key is used', async function () {
const client = new OnspringClient(baseURL, 'invalid');
const response = await client.getRecordById(new GetRecordRequest(1, 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 404 error when an invalid record id is used', 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.getRecordById(
new GetRecordRequest(parseInt(process.env.TEST_SURVEY_ID), 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;
});
});
+2 -1
View File
@@ -24,4 +24,5 @@ TEST_LIST_ID_NO_ACCESS=NEEDS_TO_BE_SET
TEST_LIST_ITEM_ID_NO_ACCESS=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
TEST_REPORT_WITH_CHART_DATA=NEEDS_TO_BE_SET
TEST_SURVEY_RECORD_ID=NEEDS_TO_BE_SET