mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor(cloud): clarify the isTest scope (#4310)
clarify the isTest scope
This commit is contained in:
parent
56c8436e19
commit
760e97eee5
3 changed files with 13 additions and 9 deletions
|
@ -2,9 +2,13 @@ import { assert } from '@silverhand/essentials';
|
|||
import { createMockPool, createMockQueryResult, createPool, parseDsn } from 'slonik';
|
||||
import { createInterceptors } from 'slonik-interceptor-preset';
|
||||
|
||||
const createPoolByEnv = async (databaseDsn: string, isTest: boolean, poolSize?: number) => {
|
||||
const createPoolByEnv = async (
|
||||
databaseDsn: string,
|
||||
mockDatabaseConnection: boolean,
|
||||
poolSize?: number
|
||||
) => {
|
||||
// Database connection is disabled in unit test environment
|
||||
if (isTest) {
|
||||
if (mockDatabaseConnection) {
|
||||
return createMockPool({ query: async () => createMockQueryResult([]) });
|
||||
}
|
||||
|
||||
|
|
|
@ -29,15 +29,15 @@ export class EnvSet {
|
|||
/** The value set for global configurations. */
|
||||
static values = new GlobalValues();
|
||||
|
||||
static get isTest() {
|
||||
return this.values.isTest;
|
||||
}
|
||||
|
||||
static get dbUrl() {
|
||||
return this.values.dbUrl;
|
||||
}
|
||||
|
||||
static sharedPool = createPoolByEnv(this.dbUrl, this.isTest, this.values.databasePoolSize);
|
||||
static sharedPool = createPoolByEnv(
|
||||
this.dbUrl,
|
||||
EnvSet.values.isUnitTest,
|
||||
this.values.databasePoolSize
|
||||
);
|
||||
|
||||
#pool: Optional<DatabasePool>;
|
||||
#oidc: Optional<Awaited<ReturnType<typeof loadOidcValues>>>;
|
||||
|
@ -66,7 +66,7 @@ export class EnvSet {
|
|||
async load() {
|
||||
const pool = await createPoolByEnv(
|
||||
this.databaseUrl,
|
||||
EnvSet.isTest,
|
||||
EnvSet.values.isUnitTest,
|
||||
EnvSet.values.databasePoolSize
|
||||
);
|
||||
|
||||
|
|
2
packages/shared/src/node/env/GlobalValues.ts
vendored
2
packages/shared/src/node/env/GlobalValues.ts
vendored
|
@ -5,8 +5,8 @@ import { throwErrorWithDsnMessage } from './throw-errors.js';
|
|||
|
||||
export default class GlobalValues {
|
||||
public readonly isProduction = getEnv('NODE_ENV') === 'production';
|
||||
public readonly isTest = getEnv('NODE_ENV') === 'test';
|
||||
public readonly isIntegrationTest = yes(getEnv('INTEGRATION_TEST'));
|
||||
public readonly isUnitTest = getEnv('NODE_ENV') === 'test';
|
||||
|
||||
public readonly httpsCert = process.env.HTTPS_CERT_PATH;
|
||||
public readonly httpsKey = process.env.HTTPS_KEY_PATH;
|
||||
|
|
Loading…
Reference in a new issue