This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'; | |
@Entity() | |
export class Task { | |
@PrimaryGeneratedColumn() | |
id: number; | |
@Column() | |
name: string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@nestjs/common'; | |
import { EntityManager } from 'typeorm'; | |
import { faker } from '@faker-js/faker'; | |
import { Task } from '@/infrastructure/database/entities/task.entity'; | |
@Injectable() | |
export class TaskSeedService { | |
private done = [0, 1]; | |
constructor(private readonly entityManager: EntityManager) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MigrationInterface, QueryRunner, Table } from 'typeorm'; | |
export class CreateTaskTable1722825209848 implements MigrationInterface { | |
public async up(queryRunner: QueryRunner): Promise<void> { | |
await queryRunner.createTable( | |
new Table({ | |
name: 'task', | |
columns: [ | |
{ | |
name: 'id', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { DynamicModule, Module } from '@nestjs/common'; | |
import { MysqlModule } from './mysql/mysql.module'; | |
import { InMemoryModule } from './in-memory/in-memory.module'; | |
@Module({ | |
imports: [MysqlModule, InMemoryModule], | |
}) | |
export class DatabaseModule { | |
static forRoot(): DynamicModule { | |
const isTestEnv = process.env.NODE_ENV === 'test'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { registerAs } from '@nestjs/config'; | |
import { TypeOrmModuleOptions } from '@nestjs/typeorm'; | |
export const mysqlDatabaseConfig = registerAs( | |
'database.mysql', | |
(): TypeOrmModuleOptions => ({ | |
type: 'mysql', | |
host: process.env.DB_HOST, | |
username: process.env.DB_USERNAME, | |
password: process.env.DB_PASSWORD, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { registerAs } from '@nestjs/config'; | |
import { TypeOrmModuleOptions } from '@nestjs/typeorm'; | |
export const inMemoryDatabaseConfig = registerAs( | |
'database.inMemory', | |
(): TypeOrmModuleOptions => ({ | |
type: 'sqlite', | |
database: ':memory', | |
entities: [ | |
__dirname + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.8' | |
services: | |
mysql: | |
image: mysql:8.0 | |
container_name: mysql | |
environment: | |
MYSQL_ROOT_PASSWORD: root | |
MYSQL_DATABASE: nestjs_testing | |
MYSQL_USER: user | |
MYSQL_PASSWORD: user |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"moduleFileExtensions": ["js", "json", "ts"], | |
"rootDir": "../", | |
"testEnvironment": "node", | |
"testRegex": ".e2e-spec.ts$", | |
"transform": { | |
"^.+\\.(t|j)s$": "ts-jest" | |
}, | |
"moduleNameMapper": { | |
"^@/(.*)$": "<rootDir>/src/$1", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
preset: 'ts-jest', | |
moduleFileExtensions: ['js', 'json', 'ts', 'node'], | |
rootDir: 'src', | |
testRegex: '.*\\.spec\\.ts$', | |
transform: { | |
'^.+\\.(t|j)s$': 'ts-jest', | |
}, | |
moduleNameMapper: { | |
'^@/(.*)$': '<rootDir>/$1', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
"module": "commonjs", | |
"declaration": true, | |
"removeComments": true, | |
"emitDecoratorMetadata": true, | |
"experimentalDecorators": true, | |
"allowSyntheticDefaultImports": true, | |
"target": "ES2021", | |
"sourceMap": true, |