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