mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
Fix e2e tests (#1321)
* Fix e2e tests * Enable e2e tests in CI * Remove unnecessary TypeOrmModule from e2e tests
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import request from 'supertest';
|
||||
import { clearDb, getAuthUser, authCustom } from './test-utils';
|
||||
import { databaseConfig } from '@app/infra';
|
||||
import { InfraModule } from '@app/infra';
|
||||
import { AlbumModule } from '../src/api-v1/album/album.module';
|
||||
import { CreateAlbumDto } from '../src/api-v1/album/dto/create-album.dto';
|
||||
import { ImmichJwtModule } from '../src/modules/immich-jwt/immich-jwt.module';
|
||||
import { AuthUserDto } from '../src/decorators/auth-user.decorator';
|
||||
import { UserService } from '@app/domain';
|
||||
import { DomainModule, UserService } from '@app/domain';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { AuthService } from '../src/api-v1/auth/auth.service';
|
||||
import { AuthModule } from '../src/api-v1/auth/auth.module';
|
||||
|
||||
function _createAlbum(app: INestApplication, data: CreateAlbumDto) {
|
||||
return request(app.getHttpServer()).post('/album').send(data);
|
||||
@@ -19,15 +20,10 @@ describe('Album', () => {
|
||||
let app: INestApplication;
|
||||
let database: DataSource;
|
||||
|
||||
afterAll(async () => {
|
||||
await clearDb(database);
|
||||
await app.close();
|
||||
});
|
||||
|
||||
describe('without auth', () => {
|
||||
beforeAll(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AlbumModule, ImmichJwtModule, TypeOrmModule.forRoot(databaseConfig)],
|
||||
imports: [DomainModule.register({ imports: [InfraModule] }), AlbumModule, ImmichJwtModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
@@ -36,6 +32,7 @@ describe('Album', () => {
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await clearDb(database);
|
||||
await app.close();
|
||||
});
|
||||
|
||||
@@ -48,21 +45,27 @@ describe('Album', () => {
|
||||
describe('with auth', () => {
|
||||
let authUser: AuthUserDto;
|
||||
let userService: UserService;
|
||||
let authService: AuthService;
|
||||
|
||||
beforeAll(async () => {
|
||||
const builder = Test.createTestingModule({
|
||||
imports: [AlbumModule, TypeOrmModule.forRoot(databaseConfig)],
|
||||
imports: [DomainModule.register({ imports: [InfraModule] }), AuthModule, AlbumModule],
|
||||
});
|
||||
authUser = getAuthUser(); // set default auth user
|
||||
const moduleFixture: TestingModule = await authCustom(builder, () => authUser).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
userService = app.get(UserService);
|
||||
authService = app.get(AuthService);
|
||||
database = app.get(DataSource);
|
||||
|
||||
await app.init();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
describe('with empty DB', () => {
|
||||
afterEach(async () => {
|
||||
await clearDb(database);
|
||||
@@ -93,22 +96,21 @@ describe('Album', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
// setup users
|
||||
const result = await Promise.all([
|
||||
userService.createUser({
|
||||
email: 'one@test.com',
|
||||
password: '1234',
|
||||
firstName: 'one',
|
||||
lastName: 'test',
|
||||
}),
|
||||
userService.createUser({
|
||||
email: 'two@test.com',
|
||||
password: '1234',
|
||||
firstName: 'two',
|
||||
lastName: 'test',
|
||||
}),
|
||||
]);
|
||||
userOne = result[0];
|
||||
userTwo = result[1];
|
||||
const adminSignUpDto = await authService.adminSignUp({
|
||||
email: 'one@test.com',
|
||||
password: '1234',
|
||||
firstName: 'one',
|
||||
lastName: 'test',
|
||||
});
|
||||
userOne = { ...adminSignUpDto, isAdmin: true }; // TODO: find out why adminSignUp doesn't have isAdmin (maybe can just return UserResponseDto)
|
||||
|
||||
userTwo = await userService.createUser({
|
||||
email: 'two@test.com',
|
||||
password: '1234',
|
||||
firstName: 'two',
|
||||
lastName: 'test',
|
||||
});
|
||||
|
||||
// add user one albums
|
||||
authUser = userOne;
|
||||
await Promise.all([
|
||||
@@ -125,6 +127,10 @@ describe('Album', () => {
|
||||
authUser = userOne;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await clearDb(database);
|
||||
});
|
||||
|
||||
it('returns the album collection including owned and shared', async () => {
|
||||
const { status, body } = await request(app.getHttpServer()).get('/album');
|
||||
expect(status).toEqual(200);
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import request from 'supertest';
|
||||
import { clearDb, authCustom } from './test-utils';
|
||||
import { databaseConfig } from '@app/infra';
|
||||
import { InfraModule } from '@app/infra';
|
||||
import { ImmichJwtModule } from '../src/modules/immich-jwt/immich-jwt.module';
|
||||
import { CreateAdminDto, CreateUserDto, UserResponseDto, UserService } from '@app/domain';
|
||||
import { DomainModule, CreateUserDto, UserService, AuthUserDto } from '@app/domain';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { UserController } from '../src/controllers';
|
||||
import { AuthModule } from '../src/api-v1/auth/auth.module';
|
||||
import { AuthService } from '../src/api-v1/auth/auth.service';
|
||||
|
||||
function _createUser(userService: UserService, data: CreateUserDto | CreateAdminDto) {
|
||||
function _createUser(userService: UserService, data: CreateUserDto) {
|
||||
return userService.createUser(data);
|
||||
}
|
||||
|
||||
@@ -24,7 +26,8 @@ describe('User', () => {
|
||||
describe('without auth', () => {
|
||||
beforeAll(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [ImmichJwtModule, TypeOrmModule.forRoot(databaseConfig)],
|
||||
imports: [DomainModule.register({ imports: [InfraModule] }), ImmichJwtModule],
|
||||
controllers: [UserController],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
@@ -44,16 +47,19 @@ describe('User', () => {
|
||||
|
||||
describe('with auth', () => {
|
||||
let userService: UserService;
|
||||
let authUser: UserResponseDto;
|
||||
let authService: AuthService;
|
||||
let authUser: AuthUserDto;
|
||||
|
||||
beforeAll(async () => {
|
||||
const builder = Test.createTestingModule({
|
||||
imports: [TypeOrmModule.forRoot(databaseConfig)],
|
||||
imports: [DomainModule.register({ imports: [InfraModule] }), AuthModule],
|
||||
controllers: [UserController],
|
||||
});
|
||||
const moduleFixture: TestingModule = await authCustom(builder, () => authUser).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
userService = app.get(UserService);
|
||||
authService = app.get(AuthService);
|
||||
database = app.get(DataSource);
|
||||
await app.init();
|
||||
});
|
||||
@@ -65,13 +71,13 @@ describe('User', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
// first user must be admin
|
||||
authUser = await _createUser(userService, {
|
||||
const adminSignupResponseDto = await authService.adminSignUp({
|
||||
firstName: 'auth-user',
|
||||
lastName: 'test',
|
||||
email: authUserEmail,
|
||||
password: '1234',
|
||||
isAdmin: true,
|
||||
});
|
||||
authUser = { ...adminSignupResponseDto, isAdmin: true }; // TODO: find out why adminSignUp doesn't have isAdmin (maybe can just return UserResponseDto)
|
||||
await Promise.allSettled([
|
||||
_createUser(userService, {
|
||||
firstName: 'one',
|
||||
|
||||
Reference in New Issue
Block a user