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:
@@ -1,20 +1,8 @@
|
|||||||
import { OnspringClient } from '../src/index';
|
import { OnspringClient } from '../src/index';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import * as dotenv from 'dotenv';
|
import { baseURL, apiKey } from './mochaRootHooks';
|
||||||
import path from 'path';
|
|
||||||
const envPath = path.resolve(__dirname, '.env');
|
|
||||||
dotenv.config({ path: envPath });
|
|
||||||
|
|
||||||
describe('getAppById', function () {
|
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 () {
|
it('should return an app', async function () {
|
||||||
const client = new OnspringClient(baseURL, apiKey);
|
const client = new OnspringClient(baseURL, apiKey);
|
||||||
|
|
||||||
@@ -69,7 +57,7 @@ describe('getAppById', function () {
|
|||||||
|
|
||||||
expect(response.statusCode).to.equal(404);
|
expect(response.statusCode).to.equal(404);
|
||||||
expect(response.isSuccessful).to.be.false;
|
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;
|
expect(response.data).to.be.null;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,20 +1,8 @@
|
|||||||
import { OnspringClient, PagingRequest } from '../src/index';
|
import { OnspringClient, PagingRequest } from '../src/index';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import * as dotenv from 'dotenv';
|
import { baseURL, apiKey } from './mochaRootHooks';
|
||||||
import path from 'path';
|
|
||||||
const envPath = path.resolve(__dirname, '.env');
|
|
||||||
dotenv.config({ path: envPath });
|
|
||||||
|
|
||||||
describe('getApps', function () {
|
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 () {
|
it('should return a paged list of apps', async function () {
|
||||||
const client = new OnspringClient(baseURL, apiKey);
|
const client = new OnspringClient(baseURL, apiKey);
|
||||||
const response = await client.getApps();
|
const response = await client.getApps();
|
||||||
|
|||||||
@@ -1,20 +1,8 @@
|
|||||||
import { OnspringClient } from '../src/index';
|
import { OnspringClient } from '../src/index';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import * as dotenv from 'dotenv';
|
import { baseURL, apiKey } from './mochaRootHooks';
|
||||||
import path from 'path';
|
|
||||||
const envPath = path.resolve(__dirname, '.env');
|
|
||||||
dotenv.config({ path: envPath });
|
|
||||||
|
|
||||||
describe('getAppsByIds', function () {
|
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 () {
|
it('should return a collection of apps', async function () {
|
||||||
const client = new OnspringClient(baseURL, apiKey);
|
const client = new OnspringClient(baseURL, apiKey);
|
||||||
const appIds = process.env.TEST_APP_IDS;
|
const appIds = process.env.TEST_APP_IDS;
|
||||||
|
|||||||
@@ -1,20 +1,8 @@
|
|||||||
import { OnspringClient } from '../src/index';
|
import { OnspringClient } from '../src/index';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import * as dotenv from 'dotenv';
|
import { baseURL, apiKey } from './mochaRootHooks';
|
||||||
import path from 'path';
|
|
||||||
const envPath = path.resolve(__dirname, '.env');
|
|
||||||
dotenv.config({ path: envPath });
|
|
||||||
|
|
||||||
describe('getAppById', function () {
|
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 () {
|
it('should return a field', async function () {
|
||||||
const client = new OnspringClient(baseURL, apiKey);
|
const client = new OnspringClient(baseURL, apiKey);
|
||||||
|
|
||||||
@@ -73,7 +61,7 @@ describe('getAppById', function () {
|
|||||||
|
|
||||||
expect(response.statusCode).to.equal(404);
|
expect(response.statusCode).to.equal(404);
|
||||||
expect(response.isSuccessful).to.be.false;
|
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;
|
expect(response.data).to.be.null;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,20 +1,8 @@
|
|||||||
import { OnspringClient, PagingRequest } from '../src/index';
|
import { OnspringClient, PagingRequest } from '../src/index';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import * as dotenv from 'dotenv';
|
import { baseURL, apiKey } from './mochaRootHooks';
|
||||||
import path from 'path';
|
|
||||||
const envPath = path.resolve(__dirname, '.env');
|
|
||||||
dotenv.config({ path: envPath });
|
|
||||||
|
|
||||||
describe('getFieldsByAppId', function () {
|
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 () {
|
it('should return a paged list of fields', async function () {
|
||||||
const client = new OnspringClient(baseURL, apiKey);
|
const client = new OnspringClient(baseURL, apiKey);
|
||||||
|
|
||||||
|
|||||||
@@ -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
@@ -40,10 +40,11 @@
|
|||||||
"format-staged": "pretty-quick --staged",
|
"format-staged": "pretty-quick --staged",
|
||||||
"format": "pretty-quick",
|
"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",
|
"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:unit": "mocha -R progress -r ts-node/register ./tests/**/*.spec.ts",
|
||||||
"tests:integration": "mocha -R progress -r ts-node/register ./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 ./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": "nyc npm run tests:unit",
|
||||||
"test-coverage:ci": "nyc npm run tests",
|
"test-coverage:ci": "nyc npm run tests",
|
||||||
"prepare": "husky install"
|
"prepare": "husky install"
|
||||||
|
|||||||
Reference in New Issue
Block a user