fix: update integration tests to use a root beforeAll hook that loads the environment variables and assigns values to the api key and base url to be used when constructing the onspring client used in the integration tests

This commit is contained in:
StevanFreeborn
2023-02-14 22:47:16 -06:00
parent 4fe1d7c4a7
commit 8e1d9051ae
7 changed files with 41 additions and 70 deletions
+2 -14
View File
@@ -1,20 +1,8 @@
import { OnspringClient } 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 });
import { baseURL, apiKey } from './mochaRootHooks';
describe('getAppById', 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 an app', async function () {
const client = new OnspringClient(baseURL, apiKey);
@@ -69,7 +57,7 @@ describe('getAppById', function () {
expect(response.statusCode).to.equal(404);
expect(response.isSuccessful).to.be.false;
expect(response.message).to.not.be.undefined.and.not.be.null;
expect(response.message).to.be.undefined;
expect(response.data).to.be.null;
});
});
+1 -13
View File
@@ -1,20 +1,8 @@
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 });
import { baseURL, apiKey } from './mochaRootHooks';
describe('getApps', 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 apps', async function () {
const client = new OnspringClient(baseURL, apiKey);
const response = await client.getApps();
+1 -13
View File
@@ -1,20 +1,8 @@
import { OnspringClient } 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 });
import { baseURL, apiKey } from './mochaRootHooks';
describe('getAppsByIds', 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 collection of apps', async function () {
const client = new OnspringClient(baseURL, apiKey);
const appIds = process.env.TEST_APP_IDS;
+2 -14
View File
@@ -1,20 +1,8 @@
import { OnspringClient } 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 });
import { baseURL, apiKey } from './mochaRootHooks';
describe('getAppById', 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 field', async function () {
const client = new OnspringClient(baseURL, apiKey);
@@ -73,7 +61,7 @@ describe('getAppById', function () {
expect(response.statusCode).to.equal(404);
expect(response.isSuccessful).to.be.false;
expect(response.message).to.not.be.undefined.and.not.be.null;
expect(response.message).to.be.undefined;
expect(response.data).to.be.null;
});
});
+1 -13
View File
@@ -1,20 +1,8 @@
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 });
import { baseURL, apiKey } from './mochaRootHooks';
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);
+30
View File
@@ -0,0 +1,30 @@
import { type Context } from 'mocha';
import { expect } from 'chai';
import * as dotenv from 'dotenv';
import path from 'path';
const envPath = path.resolve(__dirname, '.env');
dotenv.config({ path: envPath });
let baseURL: string | undefined;
let apiKey: string | undefined;
export const mochaHooks = (): Mocha.RootHookObject => {
return {
beforeAll(this: Context) {
this.timeout('30s');
baseURL = process.env.API_BASE_URL;
apiKey = process.env.SANDBOX_API_KEY;
if (baseURL === undefined) {
return expect.fail('API_BASE_URL is not defined');
}
if (apiKey === undefined) {
return expect.fail('SANDBOX_API_KEY is not defined');
}
},
};
};
export { baseURL, apiKey };
+4 -3
View File
@@ -40,10 +40,11 @@
"format-staged": "pretty-quick --staged",
"format": "pretty-quick",
"build": "npm run lint-fix && npm run tests && npm run format && npm run clean && tsc --project tsconfig.cjs.json & tsc --project tsconfig.esm.json",
"test": "mocha -r ts-node/register",
"test:unit": "mocha -r ts-node/register",
"test:integration": "mocha -r ts-node/register -r integrationTests/mochaRootHooks.ts",
"tests:unit": "mocha -R progress -r ts-node/register ./tests/**/*.spec.ts",
"tests:integration": "mocha -R progress -r ts-node/register ./integrationTests/**/*.spec.ts",
"tests": "mocha -R progress -r ts-node/register ./tests/**/*.spec.ts ./integrationTests/**/*.spec.ts",
"tests:integration": "mocha -R progress -r ts-node/register -r integrationTests/mochaRootHooks.ts ./integrationTests/**/*.spec.ts",
"tests": "mocha -R progress -r ts-node/register ./tests/**/*.spec.ts -r ts-node/register -r integrationTests/mochaRootHooks.ts ./integrationTests/**/*.spec.ts",
"test-coverage": "nyc npm run tests:unit",
"test-coverage:ci": "nyc npm run tests",
"prepare": "husky install"