mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor(cloud): reuse GlobalValues
class from shared (#3446)
This commit is contained in:
parent
c7bbdb40a0
commit
5caa95a6eb
5 changed files with 15 additions and 12 deletions
|
@ -6,5 +6,6 @@ const config = {
|
||||||
coveragePathIgnorePatterns: ['/node_modules/', '/test-utils/'],
|
coveragePathIgnorePatterns: ['/node_modules/', '/test-utils/'],
|
||||||
collectCoverageFrom: ['**/*.js'],
|
collectCoverageFrom: ['**/*.js'],
|
||||||
roots: ['./build'],
|
roots: ['./build'],
|
||||||
|
setupFilesAfterEnv: ['./jest.setup.js'],
|
||||||
};
|
};
|
||||||
export default config;
|
export default config;
|
||||||
|
|
7
packages/cloud/jest.setup.js
Normal file
7
packages/cloud/jest.setup.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
/**
|
||||||
|
* Setup environment variables for unit test
|
||||||
|
*/
|
||||||
|
|
||||||
|
process.env.DB_URL = 'postgres://mock.db.url';
|
||||||
|
process.env.ENDPOINT = 'https://logto.test';
|
||||||
|
process.env.NODE_ENV = 'test';
|
|
@ -1,11 +1,4 @@
|
||||||
const getEnv = (key: string) => process.env[key];
|
import { GlobalValues } from '@logto/shared';
|
||||||
|
|
||||||
class GlobalValues {
|
|
||||||
public readonly logtoEndpoint = new URL(getEnv('ADMIN_ENDPOINT') ?? 'http://localhost:3002');
|
|
||||||
|
|
||||||
public readonly dbUrl = getEnv('DB_URL');
|
|
||||||
public readonly isProduction = getEnv('NODE_ENV') === 'production';
|
|
||||||
}
|
|
||||||
|
|
||||||
export const EnvSet = {
|
export const EnvSet = {
|
||||||
global: new GlobalValues(),
|
global: new GlobalValues(),
|
||||||
|
|
|
@ -26,7 +26,9 @@ const { listen } = createServer({
|
||||||
'/api',
|
'/api',
|
||||||
compose<RequestContext>()
|
compose<RequestContext>()
|
||||||
.and(withBody())
|
.and(withBody())
|
||||||
.and(withAuth({ endpoint: EnvSet.global.logtoEndpoint, audience: cloudApiIndicator }))
|
.and(
|
||||||
|
withAuth({ endpoint: EnvSet.global.adminUrlSet.endpoint, audience: cloudApiIndicator })
|
||||||
|
)
|
||||||
.and(router.routes())
|
.and(router.routes())
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -17,10 +17,11 @@ import {
|
||||||
createAdminData,
|
createAdminData,
|
||||||
createAdminDataInAdminTenant,
|
createAdminDataInAdminTenant,
|
||||||
} from '@logto/schemas';
|
} from '@logto/schemas';
|
||||||
import { createTenantMetadata, DemoConnector, GlobalValues } from '@logto/shared';
|
import { createTenantMetadata, DemoConnector } from '@logto/shared';
|
||||||
import type { ZodType } from 'zod';
|
import type { ZodType } from 'zod';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
import { EnvSet } from '#src/env-set/index.js';
|
||||||
import { createApplicationsQueries } from '#src/queries/application.js';
|
import { createApplicationsQueries } from '#src/queries/application.js';
|
||||||
import { createConnectorsQuery } from '#src/queries/connector.js';
|
import { createConnectorsQuery } from '#src/queries/connector.js';
|
||||||
import type { Queries } from '#src/queries/index.js';
|
import type { Queries } from '#src/queries/index.js';
|
||||||
|
@ -116,8 +117,7 @@ export class TenantsLibrary {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Create demo connectors
|
// Create demo connectors
|
||||||
const globalValues = new GlobalValues();
|
const { cloudUrlSet } = EnvSet.global;
|
||||||
const { cloudUrlSet } = globalValues;
|
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
[DemoConnector.Email, DemoConnector.Sms].map(async (connectorId) => {
|
[DemoConnector.Email, DemoConnector.Sms].map(async (connectorId) => {
|
||||||
|
|
Loading…
Reference in a new issue