1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-25 10:43:13 +02:00

chore: cleanup e2e (#5051)

This commit is contained in:
Jason Rasmussen 2023-11-14 20:31:06 -05:00 committed by GitHub
parent 6127fd4c5c
commit 4b722517f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 77 additions and 171 deletions

View File

@ -1,24 +0,0 @@
import { dataSource } from '@app/infra';
export const db = {
reset: async () => {
if (!dataSource.isInitialized) {
await dataSource.initialize();
}
await dataSource.transaction(async (em) => {
for (const entity of dataSource.entityMetadatas) {
if (entity.tableName === 'users') {
continue;
}
await em.query(`DELETE FROM ${entity.tableName} CASCADE;`);
}
await em.query(`DELETE FROM "users" CASCADE;`);
});
},
disconnect: async () => {
if (dataSource.isInitialized) {
await dataSource.destroy();
}
},
};

View File

@ -3,8 +3,7 @@ import { ActivityController } from '@app/immich';
import { AssetFileUploadResponseDto } from '@app/immich/api-v1/asset/response-dto/asset-file-upload-response.dto';
import { ActivityEntity } from '@app/infra/entities';
import { api } from '@test/api';
import { db } from '@test/db';
import { errorStub, uuidStub } from '@test/fixtures';
import { errorStub, userDto, uuidStub } from '@test/fixtures';
import { testApp } from '@test/test-utils';
import request from 'supertest';
@ -17,14 +16,13 @@ describe(`${ActivityController.name} (e2e)`, () => {
beforeAll(async () => {
[server] = await testApp.create();
await db.reset();
await testApp.reset();
await api.authApi.adminSignUp(server);
admin = await api.authApi.adminLogin(server);
asset = await api.assetApi.upload(server, admin.accessToken, 'example');
const credentials = { email: 'user1@immich.app', password: 'Password123' };
await api.userApi.create(server, admin.accessToken, { ...credentials, name: 'User 1' });
nonOwner = await api.authApi.login(server, credentials);
await api.userApi.create(server, admin.accessToken, userDto.user1);
nonOwner = await api.authApi.login(server, userDto.user1);
album = await api.albumApi.create(server, admin.accessToken, {
albumName: 'Album 1',

View File

@ -3,8 +3,7 @@ import { AlbumController } from '@app/immich';
import { AssetFileUploadResponseDto } from '@app/immich/api-v1/asset/response-dto/asset-file-upload-response.dto';
import { SharedLinkType } from '@app/infra/entities';
import { api } from '@test/api';
import { db } from '@test/db';
import { errorStub, uuidStub } from '@test/fixtures';
import { errorStub, userDto, uuidStub } from '@test/fixtures';
import { testApp } from '@test/test-utils';
import request from 'supertest';
@ -33,26 +32,18 @@ describe(`${AlbumController.name} (e2e)`, () => {
});
beforeEach(async () => {
await db.reset();
await testApp.reset();
await api.authApi.adminSignUp(server);
admin = await api.authApi.adminLogin(server);
await Promise.all([
api.userApi.create(server, admin.accessToken, {
email: 'user1@immich.app',
password: 'Password123',
name: 'User 1',
}),
api.userApi.create(server, admin.accessToken, {
email: 'user2@immich.app',
password: 'Password123',
name: 'User 2',
}),
api.userApi.create(server, admin.accessToken, userDto.user1),
api.userApi.create(server, admin.accessToken, userDto.user2),
]);
[user1, user2] = await Promise.all([
api.authApi.login(server, { email: 'user1@immich.app', password: 'Password123' }),
api.authApi.login(server, { email: 'user2@immich.app', password: 'Password123' }),
api.authApi.login(server, userDto.user1),
api.authApi.login(server, userDto.user2),
]);
user1Asset = await api.assetApi.upload(server, user1.accessToken, 'example');

View File

@ -14,24 +14,12 @@ import { AssetEntity, AssetType, LibraryType, SharedLinkType } from '@app/infra/
import { AssetRepository } from '@app/infra/repositories';
import { INestApplication } from '@nestjs/common';
import { api } from '@test/api';
import { errorStub, uuidStub } from '@test/fixtures';
import { errorStub, userDto, uuidStub } from '@test/fixtures';
import { testApp } from '@test/test-utils';
import { randomBytes } from 'crypto';
import { DateTime } from 'luxon';
import request from 'supertest';
const user1Dto = {
email: 'user1@immich.app',
password: 'Password123',
name: 'User 1',
};
const user2Dto = {
email: 'user2@immich.app',
password: 'Password123',
name: 'User 2',
};
const today = DateTime.fromObject({ year: 2023, month: 11, day: 3 });
const yesterday = today.minus({ days: 1 });
@ -104,13 +92,13 @@ describe(`${AssetController.name} (e2e)`, () => {
const admin = await api.authApi.adminLogin(server);
await Promise.all([
api.userApi.create(server, admin.accessToken, user1Dto),
api.userApi.create(server, admin.accessToken, user2Dto),
api.userApi.create(server, admin.accessToken, userDto.user1),
api.userApi.create(server, admin.accessToken, userDto.user2),
]);
[user1, user2] = await Promise.all([
api.authApi.login(server, { email: user1Dto.email, password: user1Dto.password }),
api.authApi.login(server, { email: user2Dto.email, password: user2Dto.password }),
api.authApi.login(server, userDto.user1),
api.authApi.login(server, userDto.user2),
]);
const [user1Libraries, user2Libraries] = await Promise.all([

View File

@ -1,6 +1,5 @@
import { AuthController } from '@app/immich';
import { api } from '@test/api';
import { db } from '@test/db';
import {
adminSignupStub,
changePasswordStub,
@ -49,7 +48,7 @@ describe(`${AuthController.name} (e2e)`, () => {
});
beforeEach(async () => {
await db.reset();
await testApp.reset();
await api.authApi.adminSignUp(server);
const response = await api.authApi.adminLogin(server);
accessToken = response.accessToken;
@ -57,7 +56,7 @@ describe(`${AuthController.name} (e2e)`, () => {
describe('POST /auth/admin-sign-up', () => {
beforeEach(async () => {
await db.reset();
await testApp.reset();
});
const invalid = [

View File

@ -1,7 +1,7 @@
import { LoginResponseDto } from '@app/domain';
import { AssetType, LibraryType } from '@app/infra/entities';
import { api } from '@test/api';
import { IMMICH_TEST_ASSET_PATH, db, runAllTests, testApp } from '@test/test-utils';
import { IMMICH_TEST_ASSET_PATH, runAllTests, testApp } from '@test/test-utils';
describe(`Supported file formats (e2e)`, () => {
let server: any;
@ -176,7 +176,7 @@ describe(`Supported file formats (e2e)`, () => {
});
beforeEach(async () => {
await db.reset();
await testApp.reset();
await api.authApi.adminSignUp(server);
admin = await api.authApi.adminLogin(server);
await api.userApi.setExternalPath(server, admin.accessToken, admin.userId, '/');

View File

@ -2,28 +2,16 @@ import { LibraryResponseDto, LoginResponseDto } from '@app/domain';
import { LibraryController } from '@app/immich';
import { AssetType, LibraryType } from '@app/infra/entities';
import { api } from '@test/api';
import { IMMICH_TEST_ASSET_PATH, IMMICH_TEST_ASSET_TEMP_PATH, db, restoreTempFolder, testApp } from '@test/test-utils';
import { IMMICH_TEST_ASSET_PATH, IMMICH_TEST_ASSET_TEMP_PATH, restoreTempFolder, testApp } from '@test/test-utils';
import * as fs from 'fs';
import request from 'supertest';
import { utimes } from 'utimes';
import { errorStub, uuidStub } from '../fixtures';
import { errorStub, userDto, uuidStub } from '../fixtures';
describe(`${LibraryController.name} (e2e)`, () => {
let server: any;
let admin: LoginResponseDto;
const user1Dto = {
email: 'user1@immich.app',
password: 'Password123',
name: 'User 1',
};
const user2Dto = {
email: 'user2@immich.app',
password: 'Password123',
name: 'User 2',
};
beforeAll(async () => {
[server] = await testApp.create({ jobs: true });
});
@ -34,7 +22,7 @@ describe(`${LibraryController.name} (e2e)`, () => {
});
beforeEach(async () => {
await db.reset();
await testApp.reset();
await restoreTempFolder();
await api.authApi.adminSignUp(server);
admin = await api.authApi.adminLogin(server);
@ -195,8 +183,8 @@ describe(`${LibraryController.name} (e2e)`, () => {
});
it('should allow a user to create a library', async () => {
await api.userApi.create(server, admin.accessToken, user1Dto);
const user1 = await api.authApi.login(server, { email: user1Dto.email, password: user1Dto.password });
await api.userApi.create(server, admin.accessToken, userDto.user1);
const user1 = await api.authApi.login(server, userDto.user1);
const { status, body } = await request(server)
.post('/library')
@ -337,11 +325,15 @@ describe(`${LibraryController.name} (e2e)`, () => {
});
it("should not allow getting another user's library", async () => {
await api.userApi.create(server, admin.accessToken, user1Dto);
const user1 = await api.authApi.login(server, { email: user1Dto.email, password: user1Dto.password });
await Promise.all([
api.userApi.create(server, admin.accessToken, userDto.user1),
api.userApi.create(server, admin.accessToken, userDto.user2),
]);
await api.userApi.create(server, admin.accessToken, user2Dto);
const user2 = await api.authApi.login(server, { email: user2Dto.email, password: user2Dto.password });
const [user1, user2] = await Promise.all([
api.authApi.login(server, userDto.user1),
api.authApi.login(server, userDto.user2),
]);
const library = await api.libraryApi.create(server, user1.accessToken, { type: LibraryType.EXTERNAL });

View File

@ -1,6 +1,5 @@
import { OAuthController } from '@app/immich';
import { api } from '@test/api';
import { db } from '@test/db';
import { errorStub } from '@test/fixtures';
import { testApp } from '@test/test-utils';
import request from 'supertest';
@ -17,7 +16,7 @@ describe(`${OAuthController.name} (e2e)`, () => {
});
beforeEach(async () => {
await db.reset();
await testApp.reset();
await api.authApi.adminSignUp(server);
});

View File

@ -1,29 +1,10 @@
import { LoginResponseDto, PartnerDirection } from '@app/domain';
import { PartnerController } from '@app/immich';
import { api } from '@test/api';
import { db } from '@test/db';
import { errorStub } from '@test/fixtures';
import { errorStub, userDto } from '@test/fixtures';
import { testApp } from '@test/test-utils';
import request from 'supertest';
const user1Dto = {
email: 'user1@immich.app',
password: 'Password123',
name: 'User 1',
};
const user2Dto = {
email: 'user2@immich.app',
password: 'Password123',
name: 'User 2',
};
const user3Dto = {
email: 'user3@immich.app',
password: 'Password123',
name: 'User 3',
};
describe(`${PartnerController.name} (e2e)`, () => {
let server: any;
let user1: LoginResponseDto;
@ -33,20 +14,20 @@ describe(`${PartnerController.name} (e2e)`, () => {
beforeAll(async () => {
[server] = await testApp.create();
await db.reset();
await testApp.reset();
await api.authApi.adminSignUp(server);
const admin = await api.authApi.adminLogin(server);
await Promise.all([
api.userApi.create(server, admin.accessToken, user1Dto),
api.userApi.create(server, admin.accessToken, user2Dto),
api.userApi.create(server, admin.accessToken, user3Dto),
api.userApi.create(server, admin.accessToken, userDto.user1),
api.userApi.create(server, admin.accessToken, userDto.user2),
api.userApi.create(server, admin.accessToken, userDto.user3),
]);
[user1, user2, user3] = await Promise.all([
api.authApi.login(server, { email: user1Dto.email, password: user1Dto.password }),
api.authApi.login(server, { email: user2Dto.email, password: user2Dto.password }),
api.authApi.login(server, { email: user3Dto.email, password: user3Dto.password }),
api.authApi.login(server, userDto.user1),
api.authApi.login(server, userDto.user2),
api.authApi.login(server, userDto.user3),
]);
await Promise.all([

View File

@ -3,7 +3,6 @@ import { PersonController } from '@app/immich';
import { PersonEntity } from '@app/infra/entities';
import { INestApplication } from '@nestjs/common';
import { api } from '@test/api';
import { db } from '@test/db';
import { errorStub, uuidStub } from '@test/fixtures';
import { testApp } from '@test/test-utils';
import request from 'supertest';
@ -27,7 +26,7 @@ describe(`${PersonController.name}`, () => {
});
beforeEach(async () => {
await db.reset();
await testApp.reset();
await api.authApi.adminSignUp(server);
loginResponse = await api.authApi.adminLogin(server);
accessToken = loginResponse.accessToken;

View File

@ -1,17 +1,10 @@
import { LoginResponseDto } from '@app/domain';
import { ServerInfoController } from '@app/immich';
import { api } from '@test/api';
import { db } from '@test/db';
import { errorStub } from '@test/fixtures';
import { errorStub, userDto } from '@test/fixtures';
import { testApp } from '@test/test-utils';
import request from 'supertest';
const user1Dto = {
email: 'user1@immich.app',
password: 'Password123',
name: 'User 1',
};
describe(`${ServerInfoController.name} (e2e)`, () => {
let server: any;
let admin: LoginResponseDto;
@ -20,11 +13,11 @@ describe(`${ServerInfoController.name} (e2e)`, () => {
beforeAll(async () => {
[server] = await testApp.create();
await db.reset();
await testApp.reset();
await api.authApi.adminSignUp(server);
admin = await api.authApi.adminLogin(server);
await api.userApi.create(server, admin.accessToken, user1Dto);
nonAdmin = await api.authApi.login(server, user1Dto);
await api.userApi.create(server, admin.accessToken, userDto.user1);
nonAdmin = await api.authApi.login(server, userDto.user1);
});
afterAll(async () => {

View File

@ -3,23 +3,11 @@ import { SharedLinkController } from '@app/immich';
import { SharedLinkType } from '@app/infra/entities';
import { INestApplication } from '@nestjs/common';
import { api } from '@test/api';
import { errorStub, uuidStub } from '@test/fixtures';
import { errorStub, userDto, uuidStub } from '@test/fixtures';
import { testApp } from '@test/test-utils';
import { DateTime } from 'luxon';
import request from 'supertest';
const user1Dto = {
email: 'user1@immich.app',
password: 'Password123',
name: 'User 1',
};
const user2Dto = {
email: 'user2@immich.app',
password: 'Password123',
name: 'User 2',
};
const today = new Date();
describe(`${SharedLinkController.name} (e2e)`, () => {
@ -46,13 +34,13 @@ describe(`${SharedLinkController.name} (e2e)`, () => {
admin = await api.authApi.adminLogin(server);
await Promise.all([
api.userApi.create(server, admin.accessToken, user1Dto),
api.userApi.create(server, admin.accessToken, user2Dto),
api.userApi.create(server, admin.accessToken, userDto.user1),
api.userApi.create(server, admin.accessToken, userDto.user2),
]);
[user1, user2] = await Promise.all([
api.authApi.login(server, { email: user1Dto.email, password: user1Dto.password }),
api.authApi.login(server, { email: user2Dto.email, password: user2Dto.password }),
api.authApi.login(server, userDto.user1),
api.authApi.login(server, userDto.user2),
]);
const asset = await api.assetApi.create(server, user1.accessToken, {

View File

@ -1,17 +1,10 @@
import { LoginResponseDto } from '@app/domain';
import { SystemConfigController } from '@app/immich';
import { api } from '@test/api';
import { db } from '@test/db';
import { errorStub } from '@test/fixtures';
import { errorStub, userDto } from '@test/fixtures';
import { testApp } from '@test/test-utils';
import request from 'supertest';
const user1Dto = {
email: 'user1@immich.app',
password: 'Password123',
name: 'User 1',
};
describe(`${SystemConfigController.name} (e2e)`, () => {
let server: any;
let admin: LoginResponseDto;
@ -20,11 +13,11 @@ describe(`${SystemConfigController.name} (e2e)`, () => {
beforeAll(async () => {
[server] = await testApp.create();
await db.reset();
await testApp.reset();
await api.authApi.adminSignUp(server);
admin = await api.authApi.adminLogin(server);
await api.userApi.create(server, admin.accessToken, user1Dto);
nonAdmin = await api.authApi.login(server, user1Dto);
await api.userApi.create(server, admin.accessToken, userDto.user1);
nonAdmin = await api.authApi.login(server, userDto.user1);
});
afterAll(async () => {

View File

@ -4,8 +4,7 @@ import { UserEntity } from '@app/infra/entities';
import { INestApplication } from '@nestjs/common';
import { getRepositoryToken } from '@nestjs/typeorm';
import { api } from '@test/api';
import { db } from '@test/db';
import { errorStub, userSignupStub, userStub } from '@test/fixtures';
import { errorStub, userDto, userSignupStub, userStub } from '@test/fixtures';
import { testApp } from '@test/test-utils';
import request from 'supertest';
import { Repository } from 'typeorm';
@ -28,7 +27,7 @@ describe(`${UserController.name}`, () => {
});
beforeEach(async () => {
await db.reset();
await testApp.reset();
await api.authApi.adminSignUp(server);
loginResponse = await api.authApi.adminLogin(server);
accessToken = loginResponse.accessToken;
@ -36,11 +35,6 @@ describe(`${UserController.name}`, () => {
userService = app.get<UserService>(UserService);
});
afterAll(async () => {
await db.disconnect();
await app.close();
});
describe('GET /user', () => {
it('should require authentication', async () => {
const { status, body } = await request(server).get('/user');
@ -74,11 +68,7 @@ describe(`${UserController.name}`, () => {
});
it('should include deleted users', async () => {
const user1 = await api.userApi.create(server, accessToken, {
email: `user1@immich.app`,
password: 'Password123',
name: `User 1`,
});
const user1 = await api.userApi.create(server, accessToken, userDto.user1);
await api.userApi.delete(server, accessToken, user1.id);
@ -86,6 +76,7 @@ describe(`${UserController.name}`, () => {
.get(`/user`)
.query({ isAll: false })
.set('Authorization', `Bearer ${accessToken}`);
expect(status).toBe(200);
expect(body).toHaveLength(2);
expect(body[0]).toMatchObject({ id: user1.id, email: 'user1@immich.app', deletedAt: expect.any(String) });

View File

@ -1,6 +1,24 @@
import { UserAvatarColor, UserEntity } from '@app/infra/entities';
import { authStub } from './auth.stub';
export const userDto = {
user1: {
email: 'user1@immich.app',
password: 'Password123',
name: 'User 1',
},
user2: {
email: 'user2@immich.app',
password: 'Password123',
name: 'User 2',
},
user3: {
email: 'user3@immich.app',
password: 'Password123',
name: 'User 3',
},
};
export const userStub = {
admin: Object.freeze<UserEntity>({
...authStub.admin,