mirror of
https://github.com/immich-app/immich.git
synced 2025-01-01 08:31:59 +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:
parent
e9fda40b2b
commit
036d0556a4
5 changed files with 55 additions and 46 deletions
16
.github/workflows/test.yml
vendored
16
.github/workflows/test.yml
vendored
|
@ -6,17 +6,17 @@ on:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# e2e-tests:
|
e2e-tests:
|
||||||
# name: Run end-to-end test suites
|
name: Run end-to-end test suites
|
||||||
|
|
||||||
# runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
# steps:
|
steps:
|
||||||
# - name: Checkout code
|
- name: Checkout code
|
||||||
# uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# - name: Run Immich Server E2E Test
|
- name: Run Immich Server E2E Test
|
||||||
# run: docker-compose -f ./docker/docker-compose.test.yml --env-file ./docker/.env.test up --abort-on-container-exit --exit-code-from immich-server-test
|
run: docker-compose -f ./docker/docker-compose.test.yml --env-file ./docker/.env.test up --abort-on-container-exit --exit-code-from immich-server-test
|
||||||
|
|
||||||
server-unit-tests:
|
server-unit-tests:
|
||||||
name: Run server unit test suites and checks
|
name: Run server unit test suites and checks
|
||||||
|
|
|
@ -26,7 +26,6 @@ const ASSET_REPOSITORY_PROVIDER = {
|
||||||
CommunicationModule,
|
CommunicationModule,
|
||||||
BackgroundTaskModule,
|
BackgroundTaskModule,
|
||||||
DownloadModule,
|
DownloadModule,
|
||||||
AlbumModule,
|
|
||||||
TagModule,
|
TagModule,
|
||||||
StorageModule,
|
StorageModule,
|
||||||
forwardRef(() => AlbumModule),
|
forwardRef(() => AlbumModule),
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { INestApplication } from '@nestjs/common';
|
import { INestApplication } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
import { clearDb, getAuthUser, authCustom } from './test-utils';
|
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 { AlbumModule } from '../src/api-v1/album/album.module';
|
||||||
import { CreateAlbumDto } from '../src/api-v1/album/dto/create-album.dto';
|
import { CreateAlbumDto } from '../src/api-v1/album/dto/create-album.dto';
|
||||||
import { ImmichJwtModule } from '../src/modules/immich-jwt/immich-jwt.module';
|
import { ImmichJwtModule } from '../src/modules/immich-jwt/immich-jwt.module';
|
||||||
import { AuthUserDto } from '../src/decorators/auth-user.decorator';
|
import { AuthUserDto } from '../src/decorators/auth-user.decorator';
|
||||||
import { UserService } from '@app/domain';
|
import { DomainModule, UserService } from '@app/domain';
|
||||||
import { DataSource } from 'typeorm';
|
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) {
|
function _createAlbum(app: INestApplication, data: CreateAlbumDto) {
|
||||||
return request(app.getHttpServer()).post('/album').send(data);
|
return request(app.getHttpServer()).post('/album').send(data);
|
||||||
|
@ -19,15 +20,10 @@ describe('Album', () => {
|
||||||
let app: INestApplication;
|
let app: INestApplication;
|
||||||
let database: DataSource;
|
let database: DataSource;
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
await clearDb(database);
|
|
||||||
await app.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('without auth', () => {
|
describe('without auth', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||||
imports: [AlbumModule, ImmichJwtModule, TypeOrmModule.forRoot(databaseConfig)],
|
imports: [DomainModule.register({ imports: [InfraModule] }), AlbumModule, ImmichJwtModule],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
app = moduleFixture.createNestApplication();
|
app = moduleFixture.createNestApplication();
|
||||||
|
@ -36,6 +32,7 @@ describe('Album', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
await clearDb(database);
|
||||||
await app.close();
|
await app.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -48,21 +45,27 @@ describe('Album', () => {
|
||||||
describe('with auth', () => {
|
describe('with auth', () => {
|
||||||
let authUser: AuthUserDto;
|
let authUser: AuthUserDto;
|
||||||
let userService: UserService;
|
let userService: UserService;
|
||||||
|
let authService: AuthService;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const builder = Test.createTestingModule({
|
const builder = Test.createTestingModule({
|
||||||
imports: [AlbumModule, TypeOrmModule.forRoot(databaseConfig)],
|
imports: [DomainModule.register({ imports: [InfraModule] }), AuthModule, AlbumModule],
|
||||||
});
|
});
|
||||||
authUser = getAuthUser(); // set default auth user
|
authUser = getAuthUser(); // set default auth user
|
||||||
const moduleFixture: TestingModule = await authCustom(builder, () => authUser).compile();
|
const moduleFixture: TestingModule = await authCustom(builder, () => authUser).compile();
|
||||||
|
|
||||||
app = moduleFixture.createNestApplication();
|
app = moduleFixture.createNestApplication();
|
||||||
userService = app.get(UserService);
|
userService = app.get(UserService);
|
||||||
|
authService = app.get(AuthService);
|
||||||
database = app.get(DataSource);
|
database = app.get(DataSource);
|
||||||
|
|
||||||
await app.init();
|
await app.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await app.close();
|
||||||
|
});
|
||||||
|
|
||||||
describe('with empty DB', () => {
|
describe('with empty DB', () => {
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await clearDb(database);
|
await clearDb(database);
|
||||||
|
@ -93,22 +96,21 @@ describe('Album', () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// setup users
|
// setup users
|
||||||
const result = await Promise.all([
|
const adminSignUpDto = await authService.adminSignUp({
|
||||||
userService.createUser({
|
email: 'one@test.com',
|
||||||
email: 'one@test.com',
|
password: '1234',
|
||||||
password: '1234',
|
firstName: 'one',
|
||||||
firstName: 'one',
|
lastName: 'test',
|
||||||
lastName: 'test',
|
});
|
||||||
}),
|
userOne = { ...adminSignUpDto, isAdmin: true }; // TODO: find out why adminSignUp doesn't have isAdmin (maybe can just return UserResponseDto)
|
||||||
userService.createUser({
|
|
||||||
email: 'two@test.com',
|
userTwo = await userService.createUser({
|
||||||
password: '1234',
|
email: 'two@test.com',
|
||||||
firstName: 'two',
|
password: '1234',
|
||||||
lastName: 'test',
|
firstName: 'two',
|
||||||
}),
|
lastName: 'test',
|
||||||
]);
|
});
|
||||||
userOne = result[0];
|
|
||||||
userTwo = result[1];
|
|
||||||
// add user one albums
|
// add user one albums
|
||||||
authUser = userOne;
|
authUser = userOne;
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
|
@ -125,6 +127,10 @@ describe('Album', () => {
|
||||||
authUser = userOne;
|
authUser = userOne;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await clearDb(database);
|
||||||
|
});
|
||||||
|
|
||||||
it('returns the album collection including owned and shared', async () => {
|
it('returns the album collection including owned and shared', async () => {
|
||||||
const { status, body } = await request(app.getHttpServer()).get('/album');
|
const { status, body } = await request(app.getHttpServer()).get('/album');
|
||||||
expect(status).toEqual(200);
|
expect(status).toEqual(200);
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { INestApplication } from '@nestjs/common';
|
import { INestApplication } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
import { clearDb, authCustom } from './test-utils';
|
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 { 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 { 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);
|
return userService.createUser(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +26,8 @@ describe('User', () => {
|
||||||
describe('without auth', () => {
|
describe('without auth', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||||
imports: [ImmichJwtModule, TypeOrmModule.forRoot(databaseConfig)],
|
imports: [DomainModule.register({ imports: [InfraModule] }), ImmichJwtModule],
|
||||||
|
controllers: [UserController],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
app = moduleFixture.createNestApplication();
|
app = moduleFixture.createNestApplication();
|
||||||
|
@ -44,16 +47,19 @@ describe('User', () => {
|
||||||
|
|
||||||
describe('with auth', () => {
|
describe('with auth', () => {
|
||||||
let userService: UserService;
|
let userService: UserService;
|
||||||
let authUser: UserResponseDto;
|
let authService: AuthService;
|
||||||
|
let authUser: AuthUserDto;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const builder = Test.createTestingModule({
|
const builder = Test.createTestingModule({
|
||||||
imports: [TypeOrmModule.forRoot(databaseConfig)],
|
imports: [DomainModule.register({ imports: [InfraModule] }), AuthModule],
|
||||||
|
controllers: [UserController],
|
||||||
});
|
});
|
||||||
const moduleFixture: TestingModule = await authCustom(builder, () => authUser).compile();
|
const moduleFixture: TestingModule = await authCustom(builder, () => authUser).compile();
|
||||||
|
|
||||||
app = moduleFixture.createNestApplication();
|
app = moduleFixture.createNestApplication();
|
||||||
userService = app.get(UserService);
|
userService = app.get(UserService);
|
||||||
|
authService = app.get(AuthService);
|
||||||
database = app.get(DataSource);
|
database = app.get(DataSource);
|
||||||
await app.init();
|
await app.init();
|
||||||
});
|
});
|
||||||
|
@ -65,13 +71,13 @@ describe('User', () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// first user must be admin
|
// first user must be admin
|
||||||
authUser = await _createUser(userService, {
|
const adminSignupResponseDto = await authService.adminSignUp({
|
||||||
firstName: 'auth-user',
|
firstName: 'auth-user',
|
||||||
lastName: 'test',
|
lastName: 'test',
|
||||||
email: authUserEmail,
|
email: authUserEmail,
|
||||||
password: '1234',
|
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([
|
await Promise.allSettled([
|
||||||
_createUser(userService, {
|
_createUser(userService, {
|
||||||
firstName: 'one',
|
firstName: 'one',
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
"paths": {
|
"paths": {
|
||||||
"@app/common": ["libs/common/src"],
|
"@app/common": ["libs/common/src"],
|
||||||
"@app/common/*": ["libs/common/src/*"],
|
"@app/common/*": ["libs/common/src/*"],
|
||||||
"@app/infra": ["libs/database/src"],
|
|
||||||
"@app/infra/*": ["libs/database/src/*"],
|
|
||||||
"@app/job": ["libs/job/src"],
|
"@app/job": ["libs/job/src"],
|
||||||
"@app/job/*": ["libs/job/src/*"],
|
"@app/job/*": ["libs/job/src/*"],
|
||||||
"@app/immich-config": ["libs/immich-config/src"],
|
"@app/immich-config": ["libs/immich-config/src"],
|
||||||
|
|
Loading…
Reference in a new issue