fix: organize integration tests according to method targets. fix: set timeouts and retries for integration tests
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { OnspringClient } from '../../src/index';
|
||||
import { expect } from 'chai';
|
||||
import { baseURL, apiKey } from '../mochaRootHooks';
|
||||
|
||||
describe('getAppById', function () {
|
||||
this.timeout(30000);
|
||||
this.retries(3);
|
||||
|
||||
it('should return a field', async function () {
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
|
||||
if (process.env.TEST_FIELD_ID === undefined) {
|
||||
return expect.fail('TEST_FIELD_ID is not defined');
|
||||
}
|
||||
|
||||
const fieldId = parseInt(process.env.TEST_FIELD_ID);
|
||||
const response = await client.getFieldById(fieldId);
|
||||
|
||||
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.id).to.equal(fieldId);
|
||||
expect(response.data.name).to.not.be.null;
|
||||
expect(response.data.appId).to.not.be.null;
|
||||
expect(response.data.type).to.not.be.null;
|
||||
expect(response.data.status).to.not.be.null;
|
||||
expect(response.data.isRequired).to.not.be.null;
|
||||
expect(response.data.isUnique).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.getFieldById(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 when api key does not have access to the requested field', async function () {
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
|
||||
if (process.env.TEST_FIELD_ID_NO_ACCESS === undefined) {
|
||||
return expect.fail('TEST_FIELD_ID_NO_ACCESS is not defined');
|
||||
}
|
||||
|
||||
const fieldId = parseInt(process.env.TEST_FIELD_ID_NO_ACCESS);
|
||||
const response = await client.getFieldById(fieldId);
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
it('should return a 404 error when the requested field does not exist', async function () {
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
const response = await client.getFieldById(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;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,130 @@
|
||||
import { OnspringClient, PagingRequest } from '../../src/index';
|
||||
import { expect } from 'chai';
|
||||
import { baseURL, apiKey } from '../mochaRootHooks';
|
||||
|
||||
describe('getFieldsByAppId', function () {
|
||||
this.timeout(30000);
|
||||
this.retries(3);
|
||||
|
||||
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;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
import { OnspringClient } from '../../src/index';
|
||||
import { expect } from 'chai';
|
||||
import { baseURL, apiKey } from '../mochaRootHooks';
|
||||
|
||||
describe('getFieldsByIds', function () {
|
||||
this.timeout(30000);
|
||||
this.retries(3);
|
||||
|
||||
it('should return a collection of fields', async function () {
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
|
||||
if (process.env.TEST_FIELD_IDS === undefined) {
|
||||
return expect.fail('TEST_FIELD_IDS is not defined');
|
||||
}
|
||||
|
||||
const fieldIds = process.env.TEST_FIELD_IDS.split(',').map((id) => {
|
||||
return parseInt(id);
|
||||
});
|
||||
|
||||
const response = await client.getFieldsByIds(fieldIds);
|
||||
|
||||
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.equal(fieldIds.length);
|
||||
expect(response.data.items.length).to.equal(fieldIds.length);
|
||||
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 401 response when an invalid api key is used', async function () {
|
||||
const client = new OnspringClient(baseURL, 'invalid');
|
||||
const response = await client.getFieldsByIds([1, 2, 3]);
|
||||
|
||||
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 the api key does not have access to any of the requested fields', async function () {
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
|
||||
if (process.env.TEST_FIELD_IDS_NO_ACCESS === undefined) {
|
||||
return expect.fail('TEST_FIELD_IDS_NO_ACCESS is not defined');
|
||||
}
|
||||
|
||||
const fieldIds = process.env.TEST_FIELD_IDS_NO_ACCESS.split(',').map(
|
||||
(id) => {
|
||||
return parseInt(id);
|
||||
}
|
||||
);
|
||||
|
||||
const response = await client.getFieldsByIds(fieldIds);
|
||||
|
||||
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;
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user