diff --git a/integrationTests/Records/deleteRecordById.spec.ts b/integrationTests/Records/deleteRecordById.spec.ts index a48346c..18270fa 100644 --- a/integrationTests/Records/deleteRecordById.spec.ts +++ b/integrationTests/Records/deleteRecordById.spec.ts @@ -10,13 +10,13 @@ describe('deleteRecordById', function () { it('should delete a record', async function () { const client = new OnspringClient(baseURL, apiKey); - if (process.env.TEST_APP_ID === undefined) { - expect.fail('TEST_APP_ID is not defined'); + if (process.env.TEST_SURVEY_ID === undefined) { + expect.fail('TEST_SURVEY_ID is not defined'); } const recordId = await addRecord(); const response = await client.deleteRecordById( - parseInt(process.env.TEST_APP_ID), + parseInt(process.env.TEST_SURVEY_ID), recordId ); @@ -76,15 +76,15 @@ describe('deleteRecordById', function () { async function addRecord(): Promise { const client = new OnspringClient(baseURL, apiKey); - if (process.env.TEST_APP_ID === undefined) { - expect.fail('TEST_APP_ID is not defined'); + if (process.env.TEST_SURVEY_ID === undefined) { + expect.fail('TEST_SURVEY_ID is not defined'); } if (process.env.TEST_TEXT_FIELD === undefined) { expect.fail('TEST_TEXT_FIELD is not defined'); } - const request = new Record(parseInt(process.env.TEST_APP_ID), null); + const request = new Record(parseInt(process.env.TEST_SURVEY_ID), null); request.addValue( new StringRecordValue(parseInt(process.env.TEST_TEXT_FIELD), 'test') diff --git a/integrationTests/Records/getRecordById.spec.ts b/integrationTests/Records/getRecordById.spec.ts index 930278c..909e39b 100644 --- a/integrationTests/Records/getRecordById.spec.ts +++ b/integrationTests/Records/getRecordById.spec.ts @@ -55,13 +55,13 @@ describe('getRecordById', function () { expect.fail('TEST_SURVEY_RECORD_ID is not defined'); } - if (process.env.TEST_FIELD_ID === undefined) { - expect.fail('TEST_FIELD_ID is not defined'); + if (process.env.TEST_TEXT_FIELD === undefined) { + expect.fail('TEST_TEXT_FIELD 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 fieldId = parseInt(process.env.TEST_TEXT_FIELD); const request = new GetRecordRequest( appId, recordId, diff --git a/integrationTests/Records/getRecordsByAppId.spec.ts b/integrationTests/Records/getRecordsByAppId.spec.ts index 9c55813..e3967c8 100644 --- a/integrationTests/Records/getRecordsByAppId.spec.ts +++ b/integrationTests/Records/getRecordsByAppId.spec.ts @@ -60,12 +60,12 @@ describe('getRecordsByAppId', function () { expect.fail('TEST_SURVEY_ID is not defined'); } - if (process.env.TEST_FIELD_ID === undefined) { - expect.fail('TEST_FIELD_ID is not defined'); + if (process.env.TEST_TEXT_FIELD === undefined) { + expect.fail('TEST_TEXT_FIELD is not defined'); } const appId = parseInt(process.env.TEST_SURVEY_ID); - const fieldId = parseInt(process.env.TEST_FIELD_ID); + const fieldId = parseInt(process.env.TEST_TEXT_FIELD); const request = new GetRecordsByAppIdRequest( appId, [fieldId], diff --git a/integrationTests/Records/getRecordsByIds.spec.ts b/integrationTests/Records/getRecordsByIds.spec.ts index 7d38c5c..df61c34 100644 --- a/integrationTests/Records/getRecordsByIds.spec.ts +++ b/integrationTests/Records/getRecordsByIds.spec.ts @@ -1,5 +1,104 @@ -import { OnspringClient } from './../../src'; +import { OnspringClient, GetRecordsRequest, DataFormat } from './../../src'; import { expect } from 'chai'; import { baseURL, apiKey } from '../mochaRootHooks'; -describe('getRecordsByIds', function () {}); +describe('getRecordsByIds', function () { + this.timeout(30000); + this.retries(3); + + it('should get records', 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 GetRecordsRequest(appId, [recordId]); + const response = await client.getRecordsByIds(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.count).to.not.be.null; + expect(response.data.items.length).to.be.greaterThan(0); + + response.data.items.forEach((record) => { + expect(record.appId).to.equal(appId); + expect(record.recordId).to.not.be.null; + expect(record.fieldData).to.not.be.null; + + if (record.fieldData != null) { + expect(record.fieldData.length).to.be.greaterThan(0); + + record.fieldData.forEach((field) => { + expect(field.fieldId).to.not.be.null; + expect(field.value).to.not.be.null; + expect(field.type).to.not.be.null; + }); + } + }); + } + }); + + it('should get records when field ids 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_TEXT_FIELD === undefined) { + expect.fail('TEST_TEXT_FIELD is not defined'); + } + + const appId = parseInt(process.env.TEST_SURVEY_ID); + const recordId = parseInt(process.env.TEST_SURVEY_RECORD_ID); + const textFieldId = parseInt(process.env.TEST_TEXT_FIELD); + const request = new GetRecordsRequest( + appId, + [recordId], + [textFieldId], + DataFormat.Formatted + ); + const response = await client.getRecordsByIds(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.count).to.not.be.null; + expect(response.data.items.length).to.be.greaterThan(0); + + response.data.items.forEach((record) => { + expect(record.appId).to.equal(appId); + expect(record.recordId).to.not.be.null; + expect(record.fieldData).to.not.be.null; + + if (record.fieldData != null) { + expect(record.fieldData.length).to.be.greaterThan(0); + + record.fieldData.forEach((field) => { + expect(field.fieldId).to.not.be.null; + expect(field.value).to.not.be.null; + expect(field.type).to.not.be.null; + }); + } + }); + } + }); +});