feat: add integration tests for getFileInfoById method. fix: add example.env that is used in integration tests
This commit is contained in:
@@ -3,11 +3,191 @@ import { expect } from 'chai';
|
||||
import { baseURL, apiKey } from '../mochaRootHooks';
|
||||
|
||||
describe('getFileInfoById', function () {
|
||||
this.timeout(30000);
|
||||
this.retries(3);
|
||||
|
||||
it('should return information about a file in an attachment field', async function () {
|
||||
expect.fail('Not implemented');
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
|
||||
if (process.env.TEST_RECORD === undefined) {
|
||||
expect.fail('TEST_RECORD is not defined');
|
||||
}
|
||||
|
||||
if (process.env.TEST_ATTACHMENT_FIELD === undefined) {
|
||||
expect.fail('TEST_ATTACHMENT_FIELD is not defined');
|
||||
}
|
||||
|
||||
if (process.env.TEST_ATTACHMENT === undefined) {
|
||||
expect.fail('TEST_ATTACHMENT is not defined');
|
||||
}
|
||||
|
||||
const recordId = parseInt(process.env.TEST_RECORD);
|
||||
const fieldId = parseInt(process.env.TEST_ATTACHMENT_FIELD);
|
||||
const fileId = parseInt(process.env.TEST_ATTACHMENT);
|
||||
|
||||
const response = await client.getFileInfoById(recordId, fieldId, fileId);
|
||||
|
||||
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.createdDate).to.not.be.null;
|
||||
expect(response.data.contentType).to.not.be.null;
|
||||
expect(response.data.notes).to.not.be.null;
|
||||
expect(response.data.fileHref).to.not.be.null;
|
||||
expect(response.data.name).to.not.be.null;
|
||||
expect(response.data.modifiedDate).to.not.be.null;
|
||||
expect(response.data.type).to.not.be.null;
|
||||
expect(response.data.owner).to.not.be.null;
|
||||
}
|
||||
});
|
||||
|
||||
it('should return information about a file in an image field', async function () {
|
||||
expect.fail('Not implemented');
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
|
||||
if (process.env.TEST_RECORD === undefined) {
|
||||
expect.fail('TEST_RECORD is not defined');
|
||||
}
|
||||
|
||||
if (process.env.TEST_IMAGE_FIELD === undefined) {
|
||||
expect.fail('TEST_IMAGE_FIELD is not defined');
|
||||
}
|
||||
|
||||
if (process.env.TEST_IMAGE === undefined) {
|
||||
expect.fail('TEST_IMAGE is not defined');
|
||||
}
|
||||
|
||||
const recordId = parseInt(process.env.TEST_RECORD);
|
||||
const fieldId = parseInt(process.env.TEST_IMAGE_FIELD);
|
||||
const fileId = parseInt(process.env.TEST_IMAGE);
|
||||
const response = await client.getFileInfoById(recordId, fieldId, fileId);
|
||||
|
||||
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.createdDate).to.not.be.null;
|
||||
expect(response.data.contentType).to.not.be.null;
|
||||
expect(response.data.notes).to.be.undefined;
|
||||
expect(response.data.fileHref).to.not.be.null;
|
||||
expect(response.data.name).to.not.be.null;
|
||||
expect(response.data.modifiedDate).to.not.be.null;
|
||||
expect(response.data.type).to.not.be.null;
|
||||
expect(response.data.owner).to.not.be.null;
|
||||
}
|
||||
});
|
||||
|
||||
it('should return a 400 response when fieldId is not for a file field', async function () {
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
|
||||
if (process.env.TEST_RECORD === undefined) {
|
||||
expect.fail('TEST_RECORD is not defined');
|
||||
}
|
||||
|
||||
if (process.env.TEST_TEXT_FIELD === undefined) {
|
||||
expect.fail('TEST_TEXT_FIELD is not defined');
|
||||
}
|
||||
|
||||
if (process.env.TEST_ATTACHMENT === undefined) {
|
||||
expect.fail('TEST_ATTACHMENT is not defined');
|
||||
}
|
||||
|
||||
const recordId = parseInt(process.env.TEST_RECORD);
|
||||
const fieldId = parseInt(process.env.TEST_TEXT_FIELD);
|
||||
const fileId = parseInt(process.env.TEST_ATTACHMENT);
|
||||
const response = await client.getFileInfoById(recordId, fieldId, fileId);
|
||||
|
||||
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 response when the api key is invalid', async function () {
|
||||
const client = new OnspringClient(baseURL, 'invalid');
|
||||
|
||||
if (process.env.TEST_RECORD === undefined) {
|
||||
expect.fail('TEST_RECORD is not defined');
|
||||
}
|
||||
|
||||
if (process.env.TEST_ATTACHMENT_FIELD === undefined) {
|
||||
expect.fail('TEST_ATTACHMENT_FIELD is not defined');
|
||||
}
|
||||
|
||||
if (process.env.TEST_ATTACHMENT === undefined) {
|
||||
expect.fail('TEST_ATTACHMENT is not defined');
|
||||
}
|
||||
|
||||
const recordId = parseInt(process.env.TEST_RECORD);
|
||||
const fieldId = parseInt(process.env.TEST_ATTACHMENT_FIELD);
|
||||
const fileId = parseInt(process.env.TEST_ATTACHMENT);
|
||||
const response = await client.getFileInfoById(recordId, fieldId, fileId);
|
||||
|
||||
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 the file field', async function () {
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
|
||||
if (process.env.TEST_ATTACHMENT_FIELD_NO_ACCESS_FIELD === undefined) {
|
||||
expect.fail('TEST_ATTACHMENT_FIELD_NO_ACCESS_FIELD is not defined');
|
||||
}
|
||||
|
||||
const fieldId = parseInt(process.env.TEST_ATTACHMENT_FIELD_NO_ACCESS_FIELD);
|
||||
const response = await client.getFileInfoById(1, fieldId, 1);
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
it('should return a 403 response when the api key does not have access to the app where the file is held', async function () {
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
|
||||
if (process.env.TEST_ATTACHMENT_FIELD_NO_ACCESS_APP === undefined) {
|
||||
expect.fail('EST_ATTACHMENT_FIELD_NO_ACCESS_APP is not defined');
|
||||
}
|
||||
|
||||
const fieldId = parseInt(process.env.TEST_ATTACHMENT_FIELD_NO_ACCESS_APP);
|
||||
const response = await client.getFileInfoById(1, fieldId, 1);
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
it('should return a 404 response when the file field cannot be found', async function () {
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
const response = await client.getFileInfoById(1, 0, 1);
|
||||
|
||||
expect(response.statusCode).to.equal(404);
|
||||
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 404 response when the file record cannot be found', async function () {
|
||||
const client = new OnspringClient(baseURL, apiKey);
|
||||
|
||||
if (process.env.TEST_ATTACHMENT_FIELD === undefined) {
|
||||
expect.fail('TEST_ATTACHMENT_FIELD is not defined');
|
||||
}
|
||||
|
||||
const fieldId = parseInt(process.env.TEST_ATTACHMENT_FIELD);
|
||||
const response = await client.getFileInfoById(0, fieldId, 1);
|
||||
|
||||
expect(response.statusCode).to.equal(404);
|
||||
expect(response.isSuccessful).to.be.false;
|
||||
expect(response.message).to.not.be.null.and.to.not.be.undefined;
|
||||
expect(response.data).to.be.null;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
API_BASE_URL=https://api.onspring.com
|
||||
SANDBOX_API_KEY=NEEDS_TO_BE_SET
|
||||
TEST_APP_ID=NEEDS_TO_BE_SET
|
||||
TEST_SURVEY_ID=NEEDS_TO_BE_SET
|
||||
TEST_APP_ID_NO_ACCESS=NEEDS_TO_BE_SET
|
||||
TEST_APP_IDS=NEEDS_TO_BE_SET
|
||||
TEST_APP_IDS_NO_ACCESS=NEEDS_TO_BE_SET
|
||||
TEST_FIELD_ID=NEEDS_TO_BE_SET
|
||||
TEST_FIELD_ID_NO_ACCESS=NEEDS_TO_BE_SET
|
||||
TEST_FIELD_IDS=NEEDS_TO_BE_SET
|
||||
TEST_FIELD_IDS_NO_ACCESS=NEEDS_TO_BE_SET
|
||||
TEST_RECORD=NEEDS_TO_BE_SET
|
||||
TEST_ATTACHMENT_FIELD=NEEDS_TO_BE_SET
|
||||
TEST_ATTACHMENT_FIELD_NO_ACCESS_FIELD=NEEDS_TO_BE_SET
|
||||
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
|
||||
Reference in New Issue
Block a user