add e2e
This commit is contained in:
parent
bdf16a3189
commit
2f54770720
12
.env.e2e
12
.env.e2e
@ -1,6 +1,6 @@
|
|||||||
DB_HOST=localhost
|
DATABASE_USER=test
|
||||||
DB_PORT=4401
|
DATABASE_PASS=test
|
||||||
DB_USERNAME=test
|
DATABASE_HOST=localhost
|
||||||
DB_PASSWORD=test
|
DATABASE_NAME=test
|
||||||
DB_DATABASE=test
|
DATABASE_PORT=4401
|
||||||
JWT_SECRET=secret
|
JWT_SECRET="secret"
|
||||||
@ -9,3 +9,9 @@ services:
|
|||||||
POSTGRES_DB: test
|
POSTGRES_DB: test
|
||||||
ports:
|
ports:
|
||||||
- '4401:5432'
|
- '4401:5432'
|
||||||
|
volumes:
|
||||||
|
- e2epgdata:/var/lib/postgresql
|
||||||
|
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
e2epgdata: {}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ const moduleTypeOrm = TypeOrmModule.forRootAsync({
|
|||||||
imports: [ConfigModule],
|
imports: [ConfigModule],
|
||||||
inject: [ConfigService],
|
inject: [ConfigService],
|
||||||
useFactory: (configService: ConfigService) => {
|
useFactory: (configService: ConfigService) => {
|
||||||
|
// console.log("config Service", configService)
|
||||||
return {
|
return {
|
||||||
type: 'postgres',
|
type: 'postgres',
|
||||||
host: configService.get<string>('DATABASE_HOST'),
|
host: configService.get<string>('DATABASE_HOST'),
|
||||||
@ -28,7 +29,16 @@ const moduleTypeOrm = TypeOrmModule.forRootAsync({
|
|||||||
});
|
});
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ConfigModule.forRoot(), moduleTypeOrm, UserModule, AuthModule],
|
imports: [
|
||||||
|
ConfigModule.forRoot({
|
||||||
|
envFilePath: process.env.DATA_SOURCE_ENV
|
||||||
|
? process.env.DATA_SOURCE_ENV
|
||||||
|
: '.env',
|
||||||
|
}),
|
||||||
|
moduleTypeOrm,
|
||||||
|
UserModule,
|
||||||
|
AuthModule,
|
||||||
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
})
|
})
|
||||||
|
|||||||
@ -5,8 +5,14 @@ import { User } from './entity/user';
|
|||||||
import * as dotenv from 'dotenv';
|
import * as dotenv from 'dotenv';
|
||||||
import { UserGroup } from './entity/user-group';
|
import { UserGroup } from './entity/user-group';
|
||||||
import { UserRole } from './entity/user-role';
|
import { UserRole } from './entity/user-role';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
dotenv.config();
|
let envFilePath = path.resolve(process.cwd(), '.env');
|
||||||
|
if (process.env.DATA_SOURCE_ENV) {
|
||||||
|
envFilePath = path.resolve(process.cwd(), process.env.DATA_SOURCE_ENV);
|
||||||
|
}
|
||||||
|
|
||||||
|
dotenv.config({ path: envFilePath });
|
||||||
|
|
||||||
export const AppDataSource = new DataSource({
|
export const AppDataSource = new DataSource({
|
||||||
type: 'postgres',
|
type: 'postgres',
|
||||||
@ -18,8 +24,6 @@ export const AppDataSource = new DataSource({
|
|||||||
synchronize: false,
|
synchronize: false,
|
||||||
logging: false,
|
logging: false,
|
||||||
entities: [User, UserGroup, UserRole],
|
entities: [User, UserGroup, UserRole],
|
||||||
migrations: [
|
migrations: ['src/migration/**/*.ts'],
|
||||||
'src/migration/**/*.ts'
|
|
||||||
],
|
|
||||||
subscribers: [],
|
subscribers: [],
|
||||||
});
|
});
|
||||||
|
|||||||
@ -33,6 +33,7 @@ export class UserController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
findAll(): Promise<User[]> {
|
findAll(): Promise<User[]> {
|
||||||
|
console.log("findall", process.env);
|
||||||
return this.userService.findAll();
|
return this.userService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,10 @@ export default async () => {
|
|||||||
|
|
||||||
// Run migrations
|
// Run migrations
|
||||||
await new Promise<void>((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
console.info("running migration")
|
console.info('running migration');
|
||||||
exec(
|
exec(
|
||||||
'env && npm run migration:run',
|
'env && npm run migration:run',
|
||||||
{ env: { ...process.env, ...readEnvFile() } },
|
{ env: { ...process.env, DATA_SOURCE_ENV: '.env.e2e' } },
|
||||||
(err, stdout, stderr) => {
|
(err, stdout, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(stderr);
|
console.error(stderr);
|
||||||
@ -31,11 +31,13 @@ export default async () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// await new Promise(resolve => {setTimeout(resolve, 60000)})
|
||||||
};
|
};
|
||||||
|
|
||||||
function readEnvFile() {
|
// function readEnvFile() {
|
||||||
const fs = require('fs');
|
// const fs = require('fs');
|
||||||
const dotenv = require('dotenv');
|
// const dotenv = require('dotenv');
|
||||||
const envConfig = dotenv.parse(fs.readFileSync('.env.e2e'));
|
// const envConfig = dotenv.parse(fs.readFileSync('.env.e2e'));
|
||||||
return envConfig;
|
// return envConfig;
|
||||||
}
|
// }
|
||||||
|
|||||||
@ -7,11 +7,9 @@ import { Role } from '../src/auth/role.enum';
|
|||||||
import { UserService } from '../src/user/user.service';
|
import { UserService } from '../src/user/user.service';
|
||||||
import { User } from '../src/entity/user';
|
import { User } from '../src/entity/user';
|
||||||
import { UpdateUserDto } from '../src/user/dto/update-user.dto';
|
import { UpdateUserDto } from '../src/user/dto/update-user.dto';
|
||||||
import * as dotenv from 'dotenv';
|
|
||||||
|
|
||||||
dotenv.config({ path: '.env.e2e' });
|
|
||||||
|
|
||||||
describe('UserController (e2e)', () => {
|
describe('UserController (e2e)', () => {
|
||||||
|
process.env.DATA_SOURCE_ENV = '.env.e2e';
|
||||||
let app: INestApplication;
|
let app: INestApplication;
|
||||||
let jwtToken: string;
|
let jwtToken: string;
|
||||||
let adminUserId: number;
|
let adminUserId: number;
|
||||||
@ -21,6 +19,7 @@ describe('UserController (e2e)', () => {
|
|||||||
imports: [AppModule],
|
imports: [AppModule],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
|
// process.env.DATA_SOURCE_ENV=".env.e2e";
|
||||||
app = moduleFixture.createNestApplication();
|
app = moduleFixture.createNestApplication();
|
||||||
app.useGlobalPipes(new ValidationPipe());
|
app.useGlobalPipes(new ValidationPipe());
|
||||||
await app.init();
|
await app.init();
|
||||||
@ -29,13 +28,14 @@ describe('UserController (e2e)', () => {
|
|||||||
const adminUser = await userService.create({
|
const adminUser = await userService.create({
|
||||||
username: 'e2e_admin',
|
username: 'e2e_admin',
|
||||||
password: 'password',
|
password: 'password',
|
||||||
|
email: "admin@dvbooking.hu",
|
||||||
roles: [Role.Admin],
|
roles: [Role.Admin],
|
||||||
});
|
});
|
||||||
adminUserId = adminUser.id;
|
adminUserId = adminUser.id;
|
||||||
|
|
||||||
const response = await request(app.getHttpServer())
|
const response = await request(app.getHttpServer())
|
||||||
.post('/auth/login')
|
.post('/auth/login')
|
||||||
.send({ username: 'e2e_admin', password: 'password' });
|
.send({ username: 'admin', password: '123456' });
|
||||||
|
|
||||||
jwtToken = response.body.access_token;
|
jwtToken = response.body.access_token;
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user