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:
Jérémy M
2024-09-20 11:02:52 +02:00
committed by GitHub
parent 7781d70bb8
commit eef7f1661d
69 changed files with 2797 additions and 492 deletions

View File

@ -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'
? {

View File

@ -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,
);

View File

@ -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,

View File

@ -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 {