mirror of
https://github.com/immich-app/immich.git
synced 2025-01-26 17:21:29 +02:00
refactor: e2e client (#7324)
This commit is contained in:
parent
5c0c98473d
commit
2ebb57cbd4
@ -531,8 +531,8 @@ describe(`${AssetController.name} (e2e)`, () => {
|
|||||||
|
|
||||||
expect(status).toBe(200);
|
expect(status).toBe(200);
|
||||||
expect(body.length).toBe(assets.length);
|
expect(body.length).toBe(assets.length);
|
||||||
for (let i = 0; i < assets.length; i++) {
|
for (const [i, asset] of assets.entries()) {
|
||||||
expect(body[i]).toEqual(expect.objectContaining({ id: assets[i].id }));
|
expect(body[i]).toEqual(expect.objectContaining({ id: asset.id }));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -699,7 +699,7 @@ describe(`${AssetController.name} (e2e)`, () => {
|
|||||||
|
|
||||||
it("should not upload to another user's library", async () => {
|
it("should not upload to another user's library", async () => {
|
||||||
const content = randomBytes(32);
|
const content = randomBytes(32);
|
||||||
const library = (await api.libraryApi.getAll(server, user2.accessToken))[0];
|
const [library] = await api.libraryApi.getAll(server, user2.accessToken);
|
||||||
await api.assetApi.upload(server, user1.accessToken, 'example-image', { content });
|
await api.assetApi.upload(server, user1.accessToken, 'example-image', { content });
|
||||||
|
|
||||||
const { body, status } = await request(server)
|
const { body, status } = await request(server)
|
||||||
|
@ -44,7 +44,7 @@ describe(`${SearchController.name}`, () => {
|
|||||||
|
|
||||||
describe('GET /search (exif)', () => {
|
describe('GET /search (exif)', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const assetId = (await assetRepository.create(generateAsset(loginResponse.userId, libraries))).id;
|
const { id: assetId } = await assetRepository.create(generateAsset(loginResponse.userId, libraries));
|
||||||
await assetRepository.upsertExif({ assetId, ...searchStub.exif });
|
await assetRepository.upsertExif({ assetId, ...searchStub.exif });
|
||||||
|
|
||||||
const assetWithMetadata = await assetRepository.getById(assetId, { exifInfo: true });
|
const assetWithMetadata = await assetRepository.getById(assetId, { exifInfo: true });
|
||||||
@ -166,7 +166,7 @@ describe(`${SearchController.name}`, () => {
|
|||||||
|
|
||||||
describe('GET /search (smart info)', () => {
|
describe('GET /search (smart info)', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const assetId = (await assetRepository.create(generateAsset(loginResponse.userId, libraries))).id;
|
const { id: assetId } = await assetRepository.create(generateAsset(loginResponse.userId, libraries));
|
||||||
await assetRepository.upsertExif({ assetId, ...searchStub.exif });
|
await assetRepository.upsertExif({ assetId, ...searchStub.exif });
|
||||||
await smartInfoRepository.upsert({ assetId, ...searchStub.smartInfo }, Array.from({ length: 512 }, Math.random));
|
await smartInfoRepository.upsert({ assetId, ...searchStub.smartInfo }, Array.from({ length: 512 }, Math.random));
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ describe(`${SearchController.name}`, () => {
|
|||||||
|
|
||||||
describe('GET /search (file name)', () => {
|
describe('GET /search (file name)', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const assetId = (await assetRepository.create(generateAsset(loginResponse.userId, libraries))).id;
|
const { id: assetId } = await assetRepository.create(generateAsset(loginResponse.userId, libraries));
|
||||||
await assetRepository.upsertExif({ assetId, ...searchStub.exif });
|
await assetRepository.upsertExif({ assetId, ...searchStub.exif });
|
||||||
|
|
||||||
const assetWithMetadata = await assetRepository.getById(assetId, { exifInfo: true });
|
const assetWithMetadata = await assetRepository.getById(assetId, { exifInfo: true });
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
import { ActivityCreateDto, ActivityResponseDto } from '@app/domain';
|
|
||||||
import request from 'supertest';
|
|
||||||
|
|
||||||
export const activityApi = {
|
|
||||||
create: async (server: any, accessToken: string, dto: ActivityCreateDto) => {
|
|
||||||
const res = await request(server).post('/activity').set('Authorization', `Bearer ${accessToken}`).send(dto);
|
|
||||||
expect(res.status === 200 || res.status === 201).toBe(true);
|
|
||||||
return res.body as ActivityResponseDto;
|
|
||||||
},
|
|
||||||
delete: async (server: any, accessToken: string, id: string) => {
|
|
||||||
const res = await request(server).delete(`/activity/${id}`).set('Authorization', `Bearer ${accessToken}`);
|
|
||||||
expect(res.status).toEqual(204);
|
|
||||||
},
|
|
||||||
};
|
|
@ -1,28 +0,0 @@
|
|||||||
import { AddUsersDto, AlbumResponseDto, BulkIdResponseDto, BulkIdsDto, CreateAlbumDto } from '@app/domain';
|
|
||||||
import request from 'supertest';
|
|
||||||
|
|
||||||
export const albumApi = {
|
|
||||||
create: async (server: any, accessToken: string, dto: CreateAlbumDto) => {
|
|
||||||
const res = await request(server).post('/album').set('Authorization', `Bearer ${accessToken}`).send(dto);
|
|
||||||
expect(res.status).toEqual(201);
|
|
||||||
return res.body as AlbumResponseDto;
|
|
||||||
},
|
|
||||||
addAssets: async (server: any, accessToken: string, id: string, dto: BulkIdsDto) => {
|
|
||||||
const res = await request(server)
|
|
||||||
.put(`/album/${id}/assets`)
|
|
||||||
.set('Authorization', `Bearer ${accessToken}`)
|
|
||||||
.send(dto);
|
|
||||||
expect(res.status).toEqual(200);
|
|
||||||
return res.body as BulkIdResponseDto[];
|
|
||||||
},
|
|
||||||
addUsers: async (server: any, accessToken: string, id: string, dto: AddUsersDto) => {
|
|
||||||
const res = await request(server).put(`/album/${id}/users`).set('Authorization', `Bearer ${accessToken}`).send(dto);
|
|
||||||
expect(res.status).toEqual(200);
|
|
||||||
return res.body as AlbumResponseDto;
|
|
||||||
},
|
|
||||||
getAllAlbums: async (server: any, accessToken: string) => {
|
|
||||||
const res = await request(server).get(`/album/`).set('Authorization', `Bearer ${accessToken}`).send();
|
|
||||||
expect(res.status).toEqual(200);
|
|
||||||
return res.body as AlbumResponseDto[];
|
|
||||||
},
|
|
||||||
};
|
|
@ -1,16 +0,0 @@
|
|||||||
import { APIKeyCreateResponseDto } from '@app/domain';
|
|
||||||
import { apiKeyCreateStub } from '@test';
|
|
||||||
import request from 'supertest';
|
|
||||||
|
|
||||||
export const apiKeyApi = {
|
|
||||||
createApiKey: async (server: any, accessToken: string) => {
|
|
||||||
const { status, body } = await request(server)
|
|
||||||
.post('/api-key')
|
|
||||||
.set('Authorization', `Bearer ${accessToken}`)
|
|
||||||
.send(apiKeyCreateStub);
|
|
||||||
|
|
||||||
expect(status).toBe(201);
|
|
||||||
|
|
||||||
return body as APIKeyCreateResponseDto;
|
|
||||||
},
|
|
||||||
};
|
|
@ -1,4 +1,4 @@
|
|||||||
import { AuthDeviceResponseDto, LoginCredentialDto, LoginResponseDto, UserResponseDto } from '@app/domain';
|
import { LoginCredentialDto, LoginResponseDto, UserResponseDto } from '@app/domain';
|
||||||
import { adminSignupStub, loginResponseStub, loginStub } from '@test';
|
import { adminSignupStub, loginResponseStub, loginStub } from '@test';
|
||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
|
|
||||||
@ -27,19 +27,4 @@ export const authApi = {
|
|||||||
|
|
||||||
return body as LoginResponseDto;
|
return body as LoginResponseDto;
|
||||||
},
|
},
|
||||||
getAuthDevices: async (server: any, accessToken: string) => {
|
|
||||||
const { status, body } = await request(server).get('/auth/devices').set('Authorization', `Bearer ${accessToken}`);
|
|
||||||
|
|
||||||
expect(body).toEqual(expect.any(Array));
|
|
||||||
expect(status).toBe(200);
|
|
||||||
|
|
||||||
return body as AuthDeviceResponseDto[];
|
|
||||||
},
|
|
||||||
validateToken: async (server: any, accessToken: string) => {
|
|
||||||
const { status, body } = await request(server)
|
|
||||||
.post('/auth/validateToken')
|
|
||||||
.set('Authorization', `Bearer ${accessToken}`);
|
|
||||||
expect(body).toEqual({ authStatus: true });
|
|
||||||
expect(status).toBe(200);
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
@ -1,25 +1,15 @@
|
|||||||
import { activityApi } from './activity-api';
|
|
||||||
import { albumApi } from './album-api';
|
|
||||||
import { apiKeyApi } from './api-key-api';
|
|
||||||
import { assetApi } from './asset-api';
|
import { assetApi } from './asset-api';
|
||||||
import { authApi } from './auth-api';
|
import { authApi } from './auth-api';
|
||||||
import { libraryApi } from './library-api';
|
import { libraryApi } from './library-api';
|
||||||
import { partnerApi } from './partner-api';
|
|
||||||
import { serverInfoApi } from './server-info-api';
|
|
||||||
import { sharedLinkApi } from './shared-link-api';
|
import { sharedLinkApi } from './shared-link-api';
|
||||||
import { trashApi } from './trash-api';
|
import { trashApi } from './trash-api';
|
||||||
import { userApi } from './user-api';
|
import { userApi } from './user-api';
|
||||||
|
|
||||||
export const api = {
|
export const api = {
|
||||||
activityApi,
|
|
||||||
authApi,
|
authApi,
|
||||||
apiKeyApi,
|
|
||||||
assetApi,
|
assetApi,
|
||||||
libraryApi,
|
libraryApi,
|
||||||
serverInfoApi,
|
|
||||||
sharedLinkApi,
|
sharedLinkApi,
|
||||||
trashApi,
|
trashApi,
|
||||||
albumApi,
|
|
||||||
userApi,
|
userApi,
|
||||||
partnerApi,
|
|
||||||
};
|
};
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
import { PartnerResponseDto } from '@app/domain';
|
|
||||||
import request from 'supertest';
|
|
||||||
|
|
||||||
export const partnerApi = {
|
|
||||||
create: async (server: any, accessToken: string, id: string) => {
|
|
||||||
const { status, body } = await request(server).post(`/partner/${id}`).set('Authorization', `Bearer ${accessToken}`);
|
|
||||||
expect(status).toBe(201);
|
|
||||||
return body as PartnerResponseDto;
|
|
||||||
},
|
|
||||||
};
|
|
@ -1,10 +0,0 @@
|
|||||||
import { ServerConfigDto } from '@app/domain';
|
|
||||||
import request from 'supertest';
|
|
||||||
|
|
||||||
export const serverInfoApi = {
|
|
||||||
getConfig: async (server: any) => {
|
|
||||||
const res = await request(server).get('/server-info/config');
|
|
||||||
expect(res.status).toBe(200);
|
|
||||||
return res.body as ServerConfigDto;
|
|
||||||
},
|
|
||||||
};
|
|
@ -10,11 +10,4 @@ export const sharedLinkApi = {
|
|||||||
expect(status).toBe(201);
|
expect(status).toBe(201);
|
||||||
return body as SharedLinkResponseDto;
|
return body as SharedLinkResponseDto;
|
||||||
},
|
},
|
||||||
|
|
||||||
getMySharedLink: async (server: any, key: string) => {
|
|
||||||
const { status, body } = await request(server).get('/shared-link/me').query({ key });
|
|
||||||
|
|
||||||
expect(status).toBe(200);
|
|
||||||
return body as SharedLinkResponseDto;
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
@ -18,16 +18,6 @@ export const userApi = {
|
|||||||
|
|
||||||
return body as UserResponseDto;
|
return body as UserResponseDto;
|
||||||
},
|
},
|
||||||
get: async (server: any, accessToken: string, id: string) => {
|
|
||||||
const { status, body } = await request(server)
|
|
||||||
.get(`/user/info/${id}`)
|
|
||||||
.set('Authorization', `Bearer ${accessToken}`);
|
|
||||||
|
|
||||||
expect(status).toBe(200);
|
|
||||||
expect(body).toMatchObject({ id });
|
|
||||||
|
|
||||||
return body as UserResponseDto;
|
|
||||||
},
|
|
||||||
update: async (server: any, accessToken: string, dto: UpdateUserDto) => {
|
update: async (server: any, accessToken: string, dto: UpdateUserDto) => {
|
||||||
const { status, body } = await request(server).put('/user').set('Authorization', `Bearer ${accessToken}`).send(dto);
|
const { status, body } = await request(server).put('/user').set('Authorization', `Bearer ${accessToken}`).send(dto);
|
||||||
|
|
||||||
@ -39,12 +29,4 @@ export const userApi = {
|
|||||||
setExternalPath: async (server: any, accessToken: string, id: string, externalPath: string) => {
|
setExternalPath: async (server: any, accessToken: string, id: string, externalPath: string) => {
|
||||||
return await userApi.update(server, accessToken, { id, externalPath });
|
return await userApi.update(server, accessToken, { id, externalPath });
|
||||||
},
|
},
|
||||||
delete: async (server: any, accessToken: string, id: string) => {
|
|
||||||
const { status, body } = await request(server).delete(`/user/${id}`).set('Authorization', `Bearer ${accessToken}`);
|
|
||||||
|
|
||||||
expect(status).toBe(200);
|
|
||||||
expect(body).toMatchObject({ id, deletedAt: expect.any(String) });
|
|
||||||
|
|
||||||
return body as UserResponseDto;
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { LoginResponseDto } from '@app/domain';
|
import { LoginResponseDto } from '@app/domain';
|
||||||
import { AssetType } from '@app/infra/entities';
|
import { AssetType } from '@app/infra/entities';
|
||||||
import { readFile } from 'fs/promises';
|
import { readFile } from 'node:fs/promises';
|
||||||
import { basename, join } from 'path';
|
import { basename, join } from 'node:path';
|
||||||
import { IMMICH_TEST_ASSET_PATH, testApp } from '../../../src/test-utils/utils';
|
import { IMMICH_TEST_ASSET_PATH, testApp } from '../../../src/test-utils/utils';
|
||||||
import { api } from '../../client';
|
import { api } from '../../client';
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ const JPEG = {
|
|||||||
iso: 200,
|
iso: 200,
|
||||||
fNumber: 11,
|
fNumber: 11,
|
||||||
exposureTime: '1/160',
|
exposureTime: '1/160',
|
||||||
fileSizeInByte: 53493,
|
fileSizeInByte: 53_493,
|
||||||
make: 'SONY',
|
make: 'SONY',
|
||||||
model: 'DSLR-A550',
|
model: 'DSLR-A550',
|
||||||
orientation: null,
|
orientation: null,
|
||||||
@ -42,11 +42,11 @@ const tests = [
|
|||||||
exifImageWidth: 4032,
|
exifImageWidth: 4032,
|
||||||
exifImageHeight: 3024,
|
exifImageHeight: 3024,
|
||||||
latitude: 41.2203,
|
latitude: 41.2203,
|
||||||
longitude: -96.071625,
|
longitude: -96.071_625,
|
||||||
make: 'Apple',
|
make: 'Apple',
|
||||||
model: 'iPhone 7',
|
model: 'iPhone 7',
|
||||||
lensModel: 'iPhone 7 back camera 3.99mm f/1.8',
|
lensModel: 'iPhone 7 back camera 3.99mm f/1.8',
|
||||||
fileSizeInByte: 880703,
|
fileSizeInByte: 880_703,
|
||||||
exposureTime: '1/887',
|
exposureTime: '1/887',
|
||||||
iso: 20,
|
iso: 20,
|
||||||
focalLength: 3.99,
|
focalLength: 3.99,
|
||||||
@ -66,7 +66,7 @@ const tests = [
|
|||||||
exifImageHeight: 800,
|
exifImageHeight: 800,
|
||||||
latitude: null,
|
latitude: null,
|
||||||
longitude: null,
|
longitude: null,
|
||||||
fileSizeInByte: 25408,
|
fileSizeInByte: 25_408,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -84,7 +84,7 @@ const tests = [
|
|||||||
fNumber: 10,
|
fNumber: 10,
|
||||||
focalLength: 18,
|
focalLength: 18,
|
||||||
iso: 100,
|
iso: 100,
|
||||||
fileSizeInByte: 9057784,
|
fileSizeInByte: 9_057_784,
|
||||||
dateTimeOriginal: '2010-07-20T17:27:12.000Z',
|
dateTimeOriginal: '2010-07-20T17:27:12.000Z',
|
||||||
latitude: null,
|
latitude: null,
|
||||||
longitude: null,
|
longitude: null,
|
||||||
@ -106,7 +106,7 @@ const tests = [
|
|||||||
fNumber: 11,
|
fNumber: 11,
|
||||||
focalLength: 85,
|
focalLength: 85,
|
||||||
iso: 200,
|
iso: 200,
|
||||||
fileSizeInByte: 15856335,
|
fileSizeInByte: 15_856_335,
|
||||||
dateTimeOriginal: '2016-09-22T22:10:29.060Z',
|
dateTimeOriginal: '2016-09-22T22:10:29.060Z',
|
||||||
latitude: null,
|
latitude: null,
|
||||||
longitude: null,
|
longitude: null,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { LibraryResponseDto, LibraryService, LoginResponseDto } from '@app/domain';
|
import { LibraryResponseDto, LibraryService, LoginResponseDto } from '@app/domain';
|
||||||
import { AssetType, LibraryType } from '@app/infra/entities';
|
import { AssetType, LibraryType } from '@app/infra/entities';
|
||||||
import fs from 'fs/promises';
|
import fs from 'node:fs/promises';
|
||||||
import path from 'path';
|
import path from 'node:path';
|
||||||
import {
|
import {
|
||||||
IMMICH_TEST_ASSET_PATH,
|
IMMICH_TEST_ASSET_PATH,
|
||||||
IMMICH_TEST_ASSET_TEMP_PATH,
|
IMMICH_TEST_ASSET_TEMP_PATH,
|
||||||
@ -20,7 +20,8 @@ describe(`Library watcher (e2e)`, () => {
|
|||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
process.env.IMMICH_CONFIG_FILE = path.normalize(`${__dirname}/../config/library-watcher-e2e-config.json`);
|
process.env.IMMICH_CONFIG_FILE = path.normalize(`${__dirname}/../config/library-watcher-e2e-config.json`);
|
||||||
|
|
||||||
server = (await testApp.create()).getHttpServer();
|
const app = await testApp.create();
|
||||||
|
server = app.getHttpServer();
|
||||||
libraryService = testApp.get(LibraryService);
|
libraryService = testApp.get(LibraryService);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user