feat: add integration tests (#6923)
### Summary This PR introduces several integration tests, a mix of manually written tests and those generated using the `generate-integration-tests` Python script located in the `scripts` folder. ### Tests Added: - **Authentication tests**: Validating login, registration, and token handling. - **FindMany queries**: Fetching multiple records for all existing entities that do not require input arguments. ### How the Integration Tests Work: - A `setupTest` function is called during the Jest test run. This function initializes a test instance of the application and exposes it on a dedicated port. - Since tests are executed in isolated workers, they do not have direct access to the in-memory app instance. Instead, the tests query the application through the exposed port. - A static accessToken is used, this one as a big expiration time so it will never expire (365 years) - The queries are executed, and the results are validated against expected outcomes. ### Current State and Next Steps: - These tests currently run using the existing development seed data. We plan to introduce more comprehensive test data using `faker` to improve coverage. - At the moment, the only mutation tests implemented are for authentication. Future updates should include broader mutation testing for other entities. --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -26,23 +26,15 @@ import { WorkspaceCacheStorageModule } from 'src/engine/workspace-cache-storage/
|
||||
import { ModulesModule } from 'src/modules/modules.module';
|
||||
|
||||
import { CoreEngineModule } from './engine/core-modules/core-engine.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
// Nest.js devtools, use devtools.nestjs.com to debug
|
||||
// DevtoolsModule.registerAsync({
|
||||
// useFactory: (environmentService: EnvironmentService) => ({
|
||||
// http: environmentService.get('DEBUG_MODE'),
|
||||
// port: environmentService.get('DEBUG_PORT'),
|
||||
// }),
|
||||
// inject: [EnvironmentService],
|
||||
// }),
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
envFilePath: process.env.NODE_ENV === 'test' ? '.env.test' : '.env',
|
||||
}),
|
||||
GraphQLModule.forRootAsync<YogaDriverConfig>({
|
||||
driver: YogaDriver,
|
||||
imports: [CoreEngineModule, GraphQLConfigModule],
|
||||
imports: [GraphQLConfigModule],
|
||||
useClass: GraphQLConfigService,
|
||||
}),
|
||||
TwentyORMModule,
|
||||
|
||||
@ -2,18 +2,24 @@ import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
|
||||
import { config } from 'dotenv';
|
||||
import { DataSource, DataSourceOptions } from 'typeorm';
|
||||
config();
|
||||
config({ path: process.env.NODE_ENV === 'test' ? '.env.test' : '.env' });
|
||||
|
||||
const isJest = process.argv.some((arg) => arg.includes('jest'));
|
||||
|
||||
export const typeORMCoreModuleOptions: TypeOrmModuleOptions = {
|
||||
url: process.env.PG_DATABASE_URL,
|
||||
type: 'postgres',
|
||||
logging: ['error'],
|
||||
schema: 'core',
|
||||
entities: ['dist/src/engine/core-modules/**/*.entity{.ts,.js}'],
|
||||
entities: [
|
||||
`${isJest ? '' : 'dist/'}src/engine/core-modules/**/*.entity{.ts,.js}`,
|
||||
],
|
||||
synchronize: false,
|
||||
migrationsRun: false,
|
||||
migrationsTableName: '_typeorm_migrations',
|
||||
migrations: ['dist/src/database/typeorm/core/migrations/*{.ts,.js}'],
|
||||
migrations: [
|
||||
`${isJest ? '' : 'dist/'}src/database/typeorm/core/migrations/*{.ts,.js}`,
|
||||
],
|
||||
ssl:
|
||||
process.env.PG_SSL_ALLOW_SELF_SIGNED === 'true'
|
||||
? {
|
||||
|
||||
@ -2,18 +2,24 @@ import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
|
||||
import { config } from 'dotenv';
|
||||
import { DataSource, DataSourceOptions } from 'typeorm';
|
||||
config();
|
||||
config({ path: process.env.NODE_ENV === 'test' ? '.env.test' : '.env' });
|
||||
|
||||
const isJest = process.argv.some((arg) => arg.includes('jest'));
|
||||
|
||||
export const typeORMMetadataModuleOptions: TypeOrmModuleOptions = {
|
||||
url: process.env.PG_DATABASE_URL,
|
||||
type: 'postgres',
|
||||
logging: ['error'],
|
||||
schema: 'metadata',
|
||||
entities: ['dist/src/engine/metadata-modules/**/*.entity{.ts,.js}'],
|
||||
entities: [
|
||||
`${isJest ? '' : 'dist/'}src/engine/metadata-modules/**/*.entity{.ts,.js}`,
|
||||
],
|
||||
synchronize: false,
|
||||
migrationsRun: false,
|
||||
migrationsTableName: '_typeorm_migrations',
|
||||
migrations: ['dist/src/database/typeorm/metadata/migrations/*{.ts,.js}'],
|
||||
migrations: [
|
||||
`${isJest ? '' : 'dist/'}src/database/typeorm/metadata/migrations/*{.ts,.js}`,
|
||||
],
|
||||
ssl:
|
||||
process.env.PG_SSL_ALLOW_SELF_SIGNED === 'true'
|
||||
? {
|
||||
@ -24,6 +30,7 @@ export const typeORMMetadataModuleOptions: TypeOrmModuleOptions = {
|
||||
query_timeout: 10000,
|
||||
},
|
||||
};
|
||||
|
||||
export const connectionSource = new DataSource(
|
||||
typeORMMetadataModuleOptions as DataSourceOptions,
|
||||
);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { config } from 'dotenv';
|
||||
import { DataSource, DataSourceOptions } from 'typeorm';
|
||||
config();
|
||||
config({ path: process.env.NODE_ENV === 'test' ? '.env.test' : '.env' });
|
||||
|
||||
const typeORMRawModuleOptions: DataSourceOptions = {
|
||||
url: process.env.PG_DATABASE_URL,
|
||||
|
||||
@ -4,15 +4,15 @@ import { DataSource } from 'typeorm';
|
||||
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity';
|
||||
import { User } from 'src/engine/core-modules/user/user.entity';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { AppToken } from 'src/engine/core-modules/app-token/app-token.entity';
|
||||
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
|
||||
import { BillingSubscription } from 'src/engine/core-modules/billing/entities/billing-subscription.entity';
|
||||
import { BillingSubscriptionItem } from 'src/engine/core-modules/billing/entities/billing-subscription-item.entity';
|
||||
import { UserWorkspace } from 'src/engine/core-modules/user-workspace/user-workspace.entity';
|
||||
import { BillingSubscription } from 'src/engine/core-modules/billing/entities/billing-subscription.entity';
|
||||
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
|
||||
import { KeyValuePair } from 'src/engine/core-modules/key-value-pair/key-value-pair.entity';
|
||||
import { PostgresCredentials } from 'src/engine/core-modules/postgres-credentials/postgres-credentials.entity';
|
||||
import { UserWorkspace } from 'src/engine/core-modules/user-workspace/user-workspace.entity';
|
||||
import { User } from 'src/engine/core-modules/user/user.entity';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
|
||||
@Injectable()
|
||||
export class TypeORMService implements OnModuleInit, OnModuleDestroy {
|
||||
|
||||
@ -5,6 +5,6 @@ import { CoreEngineModule } from 'src/engine/core-modules/core-engine.module';
|
||||
@Module({
|
||||
imports: [CoreEngineModule],
|
||||
providers: [],
|
||||
exports: [],
|
||||
exports: [CoreEngineModule],
|
||||
})
|
||||
export class GraphQLConfigModule {}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { ConfigurableModuleClass } from 'src/engine/core-modules/environment/environment.module-definition';
|
||||
import { validate } from 'src/engine/core-modules/environment/environment-variables';
|
||||
import { ConfigurableModuleClass } from 'src/engine/core-modules/environment/environment.module-definition';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
@ -12,6 +12,7 @@ import { validate } from 'src/engine/core-modules/environment/environment-variab
|
||||
isGlobal: true,
|
||||
expandVariables: true,
|
||||
validate,
|
||||
envFilePath: process.env.NODE_ENV === 'test' ? '.env.test' : '.env',
|
||||
}),
|
||||
],
|
||||
providers: [EnvironmentService],
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
export enum NodeEnvironment {
|
||||
test = 'test',
|
||||
development = 'development',
|
||||
production = 'production',
|
||||
}
|
||||
|
||||
@ -8,7 +8,6 @@ import { AuthContext } from 'src/engine/core-modules/auth/types/auth-context.typ
|
||||
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
|
||||
import { handleExceptionAndConvertToGraphQLError } from 'src/engine/utils/global-exception-handler.util';
|
||||
import { WorkspaceCacheStorageService } from 'src/engine/workspace-cache-storage/workspace-cache-storage.service';
|
||||
|
||||
class GraphqlTokenValidationProxy {
|
||||
private tokenService: TokenService;
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
import { config } from 'dotenv';
|
||||
config();
|
||||
config({ path: process.env.NODE_ENV === 'test' ? '.env.test' : '.env' });
|
||||
|
||||
export function generateFrontConfig(): void {
|
||||
const configObject = {
|
||||
|
||||
Reference in New Issue
Block a user