From dc1b4b1e577979ebf67a798070c4685460d3ecba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andony=20N=C3=BA=C3=B1ez?= Date: Mon, 17 Apr 2023 19:09:15 -0600 Subject: [PATCH] [RND-496] Use global setup for jest (#233) * Global setTimeout * Fixing lint errors * Fixing dev mode message --- Meadowlark-js/.eslintignore | 3 ++- .../test/config/integration/jest.config.js | 4 +++- .../test/integration/Delete.test.ts | 2 -- .../test/integration/OwnershipSecurity.test.ts | 2 -- .../test/integration/Read.test.ts | 2 -- .../test/integration/SecurityMiddleware.test.ts | 2 -- .../test/integration/Update.test.ts | 2 -- .../test/integration/Upsert.test.ts | 2 -- .../authorization/CreateAuthorizationClient.test.ts | 2 -- .../authorization/GetAllAuthorizationClients.test.ts | 2 -- .../authorization/GetAuthorizationClient.test.ts | 2 -- .../ResetAuthorizationClientSecret.test.ts | 2 -- .../TryCreateBootstrapAuthorizationAdmin.test.ts | 2 -- .../authorization/UpdateAuthorizationClient.test.ts | 2 -- .../test/integration/locking/Delete.test.ts | 2 -- .../test/middleware/SecurityMiddleware.test.ts | 2 -- .../test/repository/Delete.test.ts | 2 -- .../test/repository/Update.test.ts | 2 -- .../test/repository/Upsert.test.ts | 2 -- .../test/config/integration/jest.config.js | 8 +++++--- .../test/config/integration/jest.config.js | 4 +++- .../test/integration/Connection.test.ts | 2 -- .../test/integration/Delete.test.ts | 2 -- .../test/integration/OwnershipSecurity.test.ts | 2 -- .../test/integration/Read.test.ts | 2 -- .../test/integration/SecurityMiddleware.test.ts | 2 -- .../test/integration/Update.test.ts | 2 -- .../test/integration/Upsert.test.ts | 2 -- .../test/integration/locking/Delete.test.ts | 2 -- .../test/middleware/AuthorizationMiddleware.test.ts | 2 -- .../services/meadowlark-fastify/test/Delete.test.ts | 2 -- .../services/meadowlark-fastify/test/Get.test.ts | 2 -- .../services/meadowlark-fastify/test/Post.test.ts | 2 -- .../services/meadowlark-fastify/test/Put.test.ts | 2 -- .../test/authorization/CreateClient.test.ts | 2 -- .../test/authorization/RequestToken.test.ts | 2 -- .../test/authorization/UpdateClient.test.ts | 2 -- .../test/authorization/VerifyToken.test.ts | 2 -- Meadowlark-js/tests/config/e2e/jest.config.js | 2 +- Meadowlark-js/tests/config/global-setup.js | 1 + Meadowlark-js/tests/config/jest.config.js | 1 + Meadowlark-js/tests/e2e/helpers/Credentials.ts | 12 +++++++----- .../MultipleEdorgTypesResourceAssociations.test.ts | 2 -- .../e2e/scenarios/QueryStringValidation.test.ts | 2 -- .../tests/e2e/scenarios/SchoolYearScenarios.test.ts | 2 -- 45 files changed, 23 insertions(+), 86 deletions(-) create mode 100644 Meadowlark-js/tests/config/global-setup.js diff --git a/Meadowlark-js/.eslintignore b/Meadowlark-js/.eslintignore index 0d5ac68c..5501c7bc 100644 --- a/Meadowlark-js/.eslintignore +++ b/Meadowlark-js/.eslintignore @@ -6,4 +6,5 @@ node_modules/ jest.ci-config.js jest.e2e-config.js jest-mongodb-config.js -jest.config.js \ No newline at end of file +jest.config.js +global-setup.js \ No newline at end of file diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/config/integration/jest.config.js b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/config/integration/jest.config.js index 04863ea3..2b4fccc0 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/config/integration/jest.config.js +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/config/integration/jest.config.js @@ -1,5 +1,6 @@ +const rootDir = '../../../../../'; // eslint-disable-next-line import/no-extraneous-dependencies -const defaultConfig = require('../../../../../tests/config/jest.config'); +const defaultConfig = require(`${rootDir}/tests/config/jest.config`); module.exports = { displayName: 'Integration Tests: Mongodb', @@ -15,5 +16,6 @@ module.exports = { statements: 60, }, }, + rootDir, workerIdleMemoryLimit: '200MB', }; diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Delete.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Delete.test.ts index 61b838e2..637e8bdc 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Delete.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Delete.test.ts @@ -29,8 +29,6 @@ import { deleteDocumentById } from '../../src/repository/Delete'; import { upsertDocument } from '../../src/repository/Upsert'; import { setupConfigForIntegration } from './Config'; -jest.setTimeout(40000); - const newUpsertRequest = (): UpsertRequest => ({ meadowlarkId: '' as MeadowlarkId, resourceInfo: NoResourceInfo, diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/OwnershipSecurity.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/OwnershipSecurity.test.ts index 03eae886..4081ff00 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/OwnershipSecurity.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/OwnershipSecurity.test.ts @@ -26,8 +26,6 @@ import { rejectByOwnershipSecurity } from '../../src/repository/OwnershipSecurit import { upsertDocument } from '../../src/repository/Upsert'; import { setupConfigForIntegration } from './Config'; -jest.setTimeout(40000); - describe('given the getById where resource info is a Descriptor', () => { let client; let result; diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Read.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Read.test.ts index c9a466f1..ac841155 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Read.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Read.test.ts @@ -25,8 +25,6 @@ import { getDocumentById } from '../../src/repository/Get'; import { upsertDocument } from '../../src/repository/Upsert'; import { setupConfigForIntegration } from './Config'; -jest.setTimeout(40000); - const newGetRequest = (): GetRequest => ({ documentUuid: '' as DocumentUuid, resourceInfo: NoResourceInfo, diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/SecurityMiddleware.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/SecurityMiddleware.test.ts index 5edffd1e..c8178786 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/SecurityMiddleware.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/SecurityMiddleware.test.ts @@ -26,8 +26,6 @@ import { securityMiddleware } from '../../src/security/SecurityMiddleware'; import { upsertDocument } from '../../src/repository/Upsert'; import { setupConfigForIntegration } from './Config'; -jest.setTimeout(40000); - describe('given the upsert where no document id is specified', () => { let client; let result; diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Update.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Update.test.ts index 2e8cef33..3becfd5f 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Update.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Update.test.ts @@ -30,8 +30,6 @@ import { updateDocumentById } from '../../src/repository/Update'; import { upsertDocument } from '../../src/repository/Upsert'; import { setupConfigForIntegration } from './Config'; -jest.setTimeout(40000); - const newUpdateRequest = (): UpdateRequest => ({ meadowlarkId: '' as MeadowlarkId, documentUuid: '' as DocumentUuid, diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Upsert.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Upsert.test.ts index 228461e8..229c7872 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Upsert.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Upsert.test.ts @@ -28,8 +28,6 @@ import { getDocumentCollection, getNewClient } from '../../src/repository/Db'; import { upsertDocument } from '../../src/repository/Upsert'; import { setupConfigForIntegration } from './Config'; -jest.setTimeout(40000); - const newUpsertRequest = (): UpsertRequest => ({ meadowlarkId: '' as MeadowlarkId, resourceInfo: NoResourceInfo, diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/CreateAuthorizationClient.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/CreateAuthorizationClient.test.ts index 82285b8e..a9001d52 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/CreateAuthorizationClient.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/CreateAuthorizationClient.test.ts @@ -10,8 +10,6 @@ import { getAuthorizationCollection, getNewClient } from '../../../src/repositor import { createAuthorizationClientDocument } from '../../../src/repository/authorization/CreateAuthorizationClient'; import { setupConfigForIntegration } from '../Config'; -jest.setTimeout(40000); - const clientId = 'clientId'; const newCreateAuthorizationClientRequest = (): CreateAuthorizationClientRequest => ({ diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/GetAllAuthorizationClients.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/GetAllAuthorizationClients.test.ts index ee1141b9..9ed4e63d 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/GetAllAuthorizationClients.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/GetAllAuthorizationClients.test.ts @@ -10,8 +10,6 @@ import { createAuthorizationClientDocument } from '../../../src/repository/autho import { getAllAuthorizationClientDocuments } from '../../../src/repository/authorization/GetAllAuthorizationClients'; import { setupConfigForIntegration } from '../Config'; -jest.setTimeout(40000); - const clientId = 'clientId'; const TRACE_ID = 'traceId'; diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/GetAuthorizationClient.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/GetAuthorizationClient.test.ts index e6ce25c6..4a2339f4 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/GetAuthorizationClient.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/GetAuthorizationClient.test.ts @@ -11,8 +11,6 @@ import { createAuthorizationClientDocument } from '../../../src/repository/autho import { getAuthorizationClientDocument } from '../../../src/repository/authorization/GetAuthorizationClient'; import { setupConfigForIntegration } from '../Config'; -jest.setTimeout(40000); - const clientId = 'clientId'; const newCreateAuthorizationClientRequest = (): CreateAuthorizationClientRequest => ({ diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/ResetAuthorizationClientSecret.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/ResetAuthorizationClientSecret.test.ts index 8cc22ce0..02a822db 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/ResetAuthorizationClientSecret.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/ResetAuthorizationClientSecret.test.ts @@ -11,8 +11,6 @@ import { createAuthorizationClientDocument } from '../../../src/repository/autho import { AuthorizationDocument } from '../../../src/model/AuthorizationDocument'; import { setupConfigForIntegration } from '../Config'; -jest.setTimeout(40000); - const clientId = 'clientId'; const clientIdDifferent = 'clientIdDifferent'; const clientIdSame = 'clientIdSame'; diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/TryCreateBootstrapAuthorizationAdmin.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/TryCreateBootstrapAuthorizationAdmin.test.ts index 2a141994..e426952c 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/TryCreateBootstrapAuthorizationAdmin.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/TryCreateBootstrapAuthorizationAdmin.test.ts @@ -10,8 +10,6 @@ import { getAuthorizationCollection, getNewClient } from '../../../src/repositor import { tryCreateBootstrapAuthorizationAdminDocument } from '../../../src/repository/authorization/TryCreateBootstrapAuthorizationAdmin'; import { setupConfigForIntegration } from '../Config'; -jest.setTimeout(40000); - const clientId = 'clientId'; const newCreateAuthorizationClientRequest = (): CreateAuthorizationClientRequest => ({ diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/UpdateAuthorizationClient.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/UpdateAuthorizationClient.test.ts index baaba220..78df448c 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/UpdateAuthorizationClient.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/authorization/UpdateAuthorizationClient.test.ts @@ -11,8 +11,6 @@ import { updateAuthorizationClientDocument } from '../../../src/repository/autho import { createAuthorizationClientDocument } from '../../../src/repository/authorization/CreateAuthorizationClient'; import { setupConfigForIntegration } from '../Config'; -jest.setTimeout(40000); - const clientIdSame = 'clientIdSame'; const clientIdDifferent = 'clientIdDifferent'; diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Delete.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Delete.test.ts index 05f57de7..1a3d9a03 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Delete.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Delete.test.ts @@ -35,8 +35,6 @@ import { import { upsertDocument } from '../../../src/repository/Upsert'; import { setupConfigForIntegration } from '../Config'; -jest.setTimeout(10000); - const documentUuid = '2edb604f-eab0-412c-a242-508d6529214d' as DocumentUuid; // A bunch of setup stuff diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/middleware/SecurityMiddleware.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/middleware/SecurityMiddleware.test.ts index 94d5f476..f49cb24f 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/middleware/SecurityMiddleware.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/middleware/SecurityMiddleware.test.ts @@ -9,8 +9,6 @@ import { newPathComponents } from '@edfi/meadowlark-core/src/model/PathComponent import { securityMiddleware } from '../../src/security/SecurityMiddleware'; import * as OwnershipSecurity from '../../src/repository/OwnershipSecurity'; -jest.setTimeout(40000); - describe('given the upsert where response already posted', () => { let result; const mongoClientMock = {}; diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/repository/Delete.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/repository/Delete.test.ts index c7b6a006..4c86feee 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/repository/Delete.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/repository/Delete.test.ts @@ -3,8 +3,6 @@ import * as utilities from '@edfi/meadowlark-utilities'; import { deleteDocumentById } from '../../src/repository/Delete'; import * as DB from '../../src/repository/Db'; -jest.setTimeout(40000); - describe('given a transaction on a resource', () => { const retryNumberOfTimes = 2; let mongoClientMock = {}; diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/repository/Update.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/repository/Update.test.ts index 8167a8b9..1388473a 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/repository/Update.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/repository/Update.test.ts @@ -11,8 +11,6 @@ import * as utilities from '@edfi/meadowlark-utilities'; import { updateDocumentById } from '../../src/repository/Update'; import * as DB from '../../src/repository/Db'; -jest.setTimeout(40000); - describe('given a transaction on a resource', () => { const retryNumberOfTimes = 2; let mongoClientMock = {}; diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/repository/Upsert.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/repository/Upsert.test.ts index 994de4d2..eae09e0c 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/repository/Upsert.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/repository/Upsert.test.ts @@ -3,8 +3,6 @@ import * as utilities from '@edfi/meadowlark-utilities'; import { upsertDocument } from '../../src/repository/Upsert'; import * as DB from '../../src/repository/Db'; -jest.setTimeout(40000); - describe('given a transaction on a resource', () => { const retryNumberOfTimes = 2; let mongoClientMock = {}; diff --git a/Meadowlark-js/backends/meadowlark-opensearch-backend/test/config/integration/jest.config.js b/Meadowlark-js/backends/meadowlark-opensearch-backend/test/config/integration/jest.config.js index 2442fd48..c894291d 100644 --- a/Meadowlark-js/backends/meadowlark-opensearch-backend/test/config/integration/jest.config.js +++ b/Meadowlark-js/backends/meadowlark-opensearch-backend/test/config/integration/jest.config.js @@ -1,10 +1,11 @@ +const rootDir = '../../../../../'; // eslint-disable-next-line import/no-extraneous-dependencies -const defaultConfig = require('../../../../../tests/config/jest.config'); +const defaultConfig = require(`${rootDir}/tests/config/jest.config`); module.exports = { displayName: 'Integration Tests: OpenSearch', - globalSetup: './test/setup/Setup.ts', - globalTeardown: './test/setup/Teardown.ts', + globalSetup: '/backends/meadowlark-opensearch-backend/test/setup/Setup.ts', + globalTeardown: '/backends/meadowlark-opensearch-backend/test/setup/Teardown.ts', ...defaultConfig, testMatch: ['**/meadowlark-opensearch-backend/test/integration/**/*.(spec|test).[jt]s?(x)'], coverageThreshold: { @@ -15,5 +16,6 @@ module.exports = { statements: 60, }, }, + rootDir, workerIdleMemoryLimit: '200MB', }; diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/config/integration/jest.config.js b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/config/integration/jest.config.js index 11943726..3eb4562c 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/config/integration/jest.config.js +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/config/integration/jest.config.js @@ -1,5 +1,6 @@ +const rootDir = '../../../../../'; // eslint-disable-next-line import/no-extraneous-dependencies -const defaultConfig = require('../../../../../tests/config/jest.config'); +const defaultConfig = require(`${rootDir}/tests/config/jest.config`); module.exports = { displayName: 'Integration Tests: Postgresql', @@ -13,5 +14,6 @@ module.exports = { statements: 60, }, }, + rootDir, workerIdleMemoryLimit: '200MB', }; diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Connection.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Connection.test.ts index f90a5e63..210fe5ec 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Connection.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Connection.test.ts @@ -7,8 +7,6 @@ import type { PoolClient, QueryResult } from 'pg'; import { resetSharedClient, getSharedClient } from '../../src/repository/Db'; import { setupConfigForIntegration } from './Config'; -jest.setTimeout(40000); - describe('Test Connection to Postgres Successful', () => { let client: PoolClient; diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Delete.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Delete.test.ts index 386dc992..7233b7db 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Delete.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Delete.test.ts @@ -31,8 +31,6 @@ import { upsertDocument } from '../../src/repository/Upsert'; import { findDocumentByIdSql } from '../../src/repository/SqlHelper'; import { setupConfigForIntegration } from './Config'; -jest.setTimeout(40000); - const newUpsertRequest = (): UpsertRequest => ({ meadowlarkId: '' as MeadowlarkId, resourceInfo: NoResourceInfo, diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/OwnershipSecurity.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/OwnershipSecurity.test.ts index 0a8a7611..ba6e0542 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/OwnershipSecurity.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/OwnershipSecurity.test.ts @@ -27,8 +27,6 @@ import { upsertDocument } from '../../src/repository/Upsert'; import { SecurityResult } from '../../src/security/SecurityResult'; import { setupConfigForIntegration } from './Config'; -jest.setTimeout(40000); - describe('given the upsert where no document id is specified', () => { let client: PoolClient; let result: SecurityResult; diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Read.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Read.test.ts index 20cdddb0..2a21d43e 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Read.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Read.test.ts @@ -27,8 +27,6 @@ import { findDocumentByIdSql } from '../../src/repository/SqlHelper'; import { upsertDocument } from '../../src/repository/Upsert'; import { setupConfigForIntegration } from './Config'; -jest.setTimeout(40000); - const newGetRequest = (): GetRequest => ({ documentUuid: 'deb6ea15-fa93-4389-89a8-1428fb617490' as DocumentUuid, resourceInfo: NoResourceInfo, diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/SecurityMiddleware.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/SecurityMiddleware.test.ts index ef0fa484..a83375ce 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/SecurityMiddleware.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/SecurityMiddleware.test.ts @@ -28,8 +28,6 @@ import { upsertDocument } from '../../src/repository/Upsert'; import { deleteAll } from './TestHelper'; import { setupConfigForIntegration } from './Config'; -jest.setTimeout(40000); - describe('given the upsert where no document id is specified', () => { let client: PoolClient; let result: MiddlewareModel; diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Update.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Update.test.ts index 6e1f2941..79ddc665 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Update.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Update.test.ts @@ -33,8 +33,6 @@ import { getDocumentById } from '../../src/repository/Get'; import { findDocumentByIdSql } from '../../src/repository/SqlHelper'; import { setupConfigForIntegration } from './Config'; -jest.setTimeout(40000); - const newUpsertRequest = (): UpsertRequest => ({ meadowlarkId: '' as MeadowlarkId, resourceInfo: NoResourceInfo, diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Upsert.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Upsert.test.ts index ba7bcf8d..6cae3c3b 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Upsert.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Upsert.test.ts @@ -28,8 +28,6 @@ import { upsertDocument } from '../../src/repository/Upsert'; import { setupConfigForIntegration } from './Config'; import { deleteAll, retrieveReferencesByDocumentIdSql, verifyAliasId } from './TestHelper'; -jest.setTimeout(40000); - const newUpsertRequest = (): UpsertRequest => ({ meadowlarkId: '' as MeadowlarkId, resourceInfo: NoResourceInfo, diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/locking/Delete.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/locking/Delete.test.ts index b4ba9a53..bcf8dc28 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/locking/Delete.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/locking/Delete.test.ts @@ -35,8 +35,6 @@ import { upsertDocument } from '../../../src/repository/Upsert'; import { deleteAll } from '../TestHelper'; import { setupConfigForIntegration } from '../Config'; -jest.setTimeout(10000); - // A bunch of setup stuff const newUpsertRequest = (): UpsertRequest => ({ meadowlarkId: '' as MeadowlarkId, diff --git a/Meadowlark-js/packages/meadowlark-core/test/middleware/AuthorizationMiddleware.test.ts b/Meadowlark-js/packages/meadowlark-core/test/middleware/AuthorizationMiddleware.test.ts index 2032d81c..b00cf8e3 100644 --- a/Meadowlark-js/packages/meadowlark-core/test/middleware/AuthorizationMiddleware.test.ts +++ b/Meadowlark-js/packages/meadowlark-core/test/middleware/AuthorizationMiddleware.test.ts @@ -10,8 +10,6 @@ import { FrontendRequest, newFrontendRequest, newFrontendRequestMiddleware } fro import { MiddlewareModel } from '../../src/middleware/MiddlewareModel'; import { setupMockConfiguration } from '../ConfigHelper'; -jest.setTimeout(40000); - const newAxiosResponse = () => ({ status: 0, data: {}, headers: {}, config: {}, statusText: '' }); describe('given a previous middleware has created a response', () => { diff --git a/Meadowlark-js/services/meadowlark-fastify/test/Delete.test.ts b/Meadowlark-js/services/meadowlark-fastify/test/Delete.test.ts index de266f89..141b9f70 100644 --- a/Meadowlark-js/services/meadowlark-fastify/test/Delete.test.ts +++ b/Meadowlark-js/services/meadowlark-fastify/test/Delete.test.ts @@ -11,8 +11,6 @@ import * as MeadowlarkConnection from '../src/handler/MeadowlarkConnection'; import { buildService } from '../src/Service'; import { setupMockConfiguration } from './ConfigHelper'; -jest.setTimeout(40000); - describe('given a DELETE of a school by id', () => { const schoolDeleteByIdRequest: InjectOptions = { method: 'DELETE', diff --git a/Meadowlark-js/services/meadowlark-fastify/test/Get.test.ts b/Meadowlark-js/services/meadowlark-fastify/test/Get.test.ts index 122b2bd8..2929f102 100644 --- a/Meadowlark-js/services/meadowlark-fastify/test/Get.test.ts +++ b/Meadowlark-js/services/meadowlark-fastify/test/Get.test.ts @@ -11,8 +11,6 @@ import * as MeadowlarkConnection from '../src/handler/MeadowlarkConnection'; import { buildService } from '../src/Service'; import { setupMockConfiguration } from './ConfigHelper'; -jest.setTimeout(40000); - describe('given a GET', () => { let mockGet: any; let service: FastifyInstance; diff --git a/Meadowlark-js/services/meadowlark-fastify/test/Post.test.ts b/Meadowlark-js/services/meadowlark-fastify/test/Post.test.ts index e01c1c2e..3ee52ab7 100644 --- a/Meadowlark-js/services/meadowlark-fastify/test/Post.test.ts +++ b/Meadowlark-js/services/meadowlark-fastify/test/Post.test.ts @@ -11,8 +11,6 @@ import * as MeadowlarkConnection from '../src/handler/MeadowlarkConnection'; import { buildService } from '../src/Service'; import { setupMockConfiguration } from './ConfigHelper'; -jest.setTimeout(40000); - const schoolPostRequest: InjectOptions = { method: 'POST', url: '/local/v3.3b/ed-fi/schools', diff --git a/Meadowlark-js/services/meadowlark-fastify/test/Put.test.ts b/Meadowlark-js/services/meadowlark-fastify/test/Put.test.ts index 8e9ad920..5083676a 100644 --- a/Meadowlark-js/services/meadowlark-fastify/test/Put.test.ts +++ b/Meadowlark-js/services/meadowlark-fastify/test/Put.test.ts @@ -11,8 +11,6 @@ import { buildService } from '../src/Service'; import { setupMockConfiguration } from './ConfigHelper'; import * as MeadowlarkConnection from '../src/handler/MeadowlarkConnection'; -jest.setTimeout(40000); - const schoolPutRequest: InjectOptions = { method: 'PUT', url: '/local/v3.3b/ed-fi/schools', diff --git a/Meadowlark-js/services/meadowlark-fastify/test/authorization/CreateClient.test.ts b/Meadowlark-js/services/meadowlark-fastify/test/authorization/CreateClient.test.ts index e31e091a..647384ce 100644 --- a/Meadowlark-js/services/meadowlark-fastify/test/authorization/CreateClient.test.ts +++ b/Meadowlark-js/services/meadowlark-fastify/test/authorization/CreateClient.test.ts @@ -9,8 +9,6 @@ import * as MeadowlarkConnection from '../../src/handler/MeadowlarkConnection'; import { buildService } from '../../src/Service'; import { setupMockConfiguration } from '../ConfigHelper'; -jest.setTimeout(40000); - const createClientRequest: InjectOptions = { method: 'POST', url: '/local/oauth/clients', diff --git a/Meadowlark-js/services/meadowlark-fastify/test/authorization/RequestToken.test.ts b/Meadowlark-js/services/meadowlark-fastify/test/authorization/RequestToken.test.ts index f50ef3b0..9cd055ee 100644 --- a/Meadowlark-js/services/meadowlark-fastify/test/authorization/RequestToken.test.ts +++ b/Meadowlark-js/services/meadowlark-fastify/test/authorization/RequestToken.test.ts @@ -9,8 +9,6 @@ import * as MeadowlarkConnection from '../../src/handler/MeadowlarkConnection'; import { buildService } from '../../src/Service'; import { setupMockConfiguration } from '../ConfigHelper'; -jest.setTimeout(40000); - const requestTokenRequest: InjectOptions = { method: 'POST', url: '/local/oauth/token', diff --git a/Meadowlark-js/services/meadowlark-fastify/test/authorization/UpdateClient.test.ts b/Meadowlark-js/services/meadowlark-fastify/test/authorization/UpdateClient.test.ts index e738da9a..a94f47f3 100644 --- a/Meadowlark-js/services/meadowlark-fastify/test/authorization/UpdateClient.test.ts +++ b/Meadowlark-js/services/meadowlark-fastify/test/authorization/UpdateClient.test.ts @@ -9,8 +9,6 @@ import * as MeadowlarkConnection from '../../src/handler/MeadowlarkConnection'; import { buildService } from '../../src/Service'; import { setupMockConfiguration } from '../ConfigHelper'; -jest.setTimeout(40000); - const updateClientRequest: InjectOptions = { method: 'PUT', url: '/local/oauth/clients/890', diff --git a/Meadowlark-js/services/meadowlark-fastify/test/authorization/VerifyToken.test.ts b/Meadowlark-js/services/meadowlark-fastify/test/authorization/VerifyToken.test.ts index 87cb3421..cb0ccfbc 100644 --- a/Meadowlark-js/services/meadowlark-fastify/test/authorization/VerifyToken.test.ts +++ b/Meadowlark-js/services/meadowlark-fastify/test/authorization/VerifyToken.test.ts @@ -9,8 +9,6 @@ import * as MeadowlarkConnection from '../../src/handler/MeadowlarkConnection'; import { buildService } from '../../src/Service'; import { setupMockConfiguration } from '../ConfigHelper'; -jest.setTimeout(40000); - const verifyTokenRequest: InjectOptions = { method: 'POST', url: '/local/oauth/verify', diff --git a/Meadowlark-js/tests/config/e2e/jest.config.js b/Meadowlark-js/tests/config/e2e/jest.config.js index a67f2ca0..220f93d9 100644 --- a/Meadowlark-js/tests/config/e2e/jest.config.js +++ b/Meadowlark-js/tests/config/e2e/jest.config.js @@ -1,5 +1,5 @@ // eslint-disable-next-line import/no-extraneous-dependencies -const defaultConfig = require('./../jest.config.js'); +const defaultConfig = require('../jest.config.js'); module.exports = { displayName: 'E2E Tests', diff --git a/Meadowlark-js/tests/config/global-setup.js b/Meadowlark-js/tests/config/global-setup.js new file mode 100644 index 00000000..4d7598ce --- /dev/null +++ b/Meadowlark-js/tests/config/global-setup.js @@ -0,0 +1 @@ +jest.setTimeout(40000) diff --git a/Meadowlark-js/tests/config/jest.config.js b/Meadowlark-js/tests/config/jest.config.js index bb8c5c62..a15efad4 100644 --- a/Meadowlark-js/tests/config/jest.config.js +++ b/Meadowlark-js/tests/config/jest.config.js @@ -5,5 +5,6 @@ module.exports = { transformIgnorePatterns: ['.*(node_modules)(?!.*meadowlark-.*).*$'], modulePathIgnorePatterns: ['dist*', 'docs*'], setupFiles: ['dotenv/config'], + setupFilesAfterEnv: ['/tests/config/global-setup.js'], rootDir: '../../..', }; diff --git a/Meadowlark-js/tests/e2e/helpers/Credentials.ts b/Meadowlark-js/tests/e2e/helpers/Credentials.ts index b03f84fe..1acb2650 100644 --- a/Meadowlark-js/tests/e2e/helpers/Credentials.ts +++ b/Meadowlark-js/tests/e2e/helpers/Credentials.ts @@ -178,14 +178,16 @@ export async function createAutomationUsers(): Promise { export async function authenticateAdmin(): Promise { try { - if (process.env.DEVELOPER_MODE && process.env.ADMIN_KEY && process.env.ADMIN_SECRET) { + const hasExistingClient = process.env.ADMIN_KEY && process.env.ADMIN_SECRET; + + if (process.env.DEVELOPER_MODE && hasExistingClient) { + console.info('INFO ℹ️: Using existing admin key and secret'); await getAdminAccessToken(); } else { const credentials = await createAdminClient(); - if (!process.env.ADMIN_KEY && !process.env.ADMIN_SECRET) { - console.info( - 'INFO ℹ️: Add the following values to the .env file. \nIf not saved, tests cannot be executed again until cleaning the environment', - ); + if (process.env.DEVELOPER_MODE && !hasExistingClient) { + console.info('INFO ℹ️: Add the following values to the .env file.'); + console.info('If not saved, tests cannot be executed again until cleaning the environment.'); console.info(`ADMIN_KEY=${credentials.key}`); console.info(`ADMIN_SECRET=${credentials.secret}`); } diff --git a/Meadowlark-js/tests/e2e/scenarios/MultipleEdorgTypesResourceAssociations.test.ts b/Meadowlark-js/tests/e2e/scenarios/MultipleEdorgTypesResourceAssociations.test.ts index e26fb244..24ab5f5f 100644 --- a/Meadowlark-js/tests/e2e/scenarios/MultipleEdorgTypesResourceAssociations.test.ts +++ b/Meadowlark-js/tests/e2e/scenarios/MultipleEdorgTypesResourceAssociations.test.ts @@ -8,8 +8,6 @@ import { createLocalEducationAgency, createProgram, createSchool, createStudent import { deleteResourceByLocation } from '../helpers/Resources'; import { baseURLRequest, generateRandomId, rootURLRequest } from '../helpers/Shared'; -jest.setTimeout(40000); - describe('Given the existence of a student, a school, a local education agency and a program', () => { const schoolId = 100; const localEducationAgencyId = 101; diff --git a/Meadowlark-js/tests/e2e/scenarios/QueryStringValidation.test.ts b/Meadowlark-js/tests/e2e/scenarios/QueryStringValidation.test.ts index 01c67d93..133b2fd0 100644 --- a/Meadowlark-js/tests/e2e/scenarios/QueryStringValidation.test.ts +++ b/Meadowlark-js/tests/e2e/scenarios/QueryStringValidation.test.ts @@ -8,8 +8,6 @@ import { getAccessToken } from '../helpers/Credentials'; import { createResource, deleteResourceByLocation } from '../helpers/Resources'; import { baseURLRequest } from '../helpers/Shared'; -jest.setTimeout(40000); - describe('When retrieving information', () => { describe("given there's no data", () => { it('should return the total count', async () => { diff --git a/Meadowlark-js/tests/e2e/scenarios/SchoolYearScenarios.test.ts b/Meadowlark-js/tests/e2e/scenarios/SchoolYearScenarios.test.ts index e84289a4..5edb08f8 100644 --- a/Meadowlark-js/tests/e2e/scenarios/SchoolYearScenarios.test.ts +++ b/Meadowlark-js/tests/e2e/scenarios/SchoolYearScenarios.test.ts @@ -16,8 +16,6 @@ import { import { deleteResourceByLocation } from '../helpers/Resources'; import { generateRandomId } from '../helpers/Shared'; -jest.setTimeout(40000); - describe('When posting a resource that contains a SchoolYear enumeration', () => { /* There are several different ways of representing school years. Sometimes testing one way of storing it requires saving