mirror of
https://github.com/immich-app/immich.git
synced 2024-11-16 02:18:50 -07:00
3d25d91e77
* refactor: library e2e * refactor: remove before each usages
72 lines
2.6 KiB
TypeScript
72 lines
2.6 KiB
TypeScript
import {
|
|
CreateLibraryDto,
|
|
LibraryResponseDto,
|
|
LibraryStatsResponseDto,
|
|
ScanLibraryDto,
|
|
UpdateLibraryDto,
|
|
ValidateLibraryDto,
|
|
ValidateLibraryResponseDto,
|
|
} from '@app/domain';
|
|
import request from 'supertest';
|
|
|
|
export const libraryApi = {
|
|
getAll: async (server: any, accessToken: string) => {
|
|
const { body, status } = await request(server).get(`/library/`).set('Authorization', `Bearer ${accessToken}`);
|
|
expect(status).toBe(200);
|
|
return body as LibraryResponseDto[];
|
|
},
|
|
create: async (server: any, accessToken: string, dto: CreateLibraryDto) => {
|
|
const { body, status } = await request(server)
|
|
.post(`/library/`)
|
|
.set('Authorization', `Bearer ${accessToken}`)
|
|
.send(dto);
|
|
expect(status).toBe(201);
|
|
return body as LibraryResponseDto;
|
|
},
|
|
setImportPaths: async (server: any, accessToken: string, id: string, importPaths: string[]) => {
|
|
const { body, status } = await request(server)
|
|
.put(`/library/${id}`)
|
|
.set('Authorization', `Bearer ${accessToken}`)
|
|
.send({ importPaths });
|
|
expect(status).toBe(200);
|
|
return body as LibraryResponseDto;
|
|
},
|
|
scanLibrary: async (server: any, accessToken: string, id: string, dto: ScanLibraryDto = {}) => {
|
|
const { status } = await request(server)
|
|
.post(`/library/${id}/scan`)
|
|
.set('Authorization', `Bearer ${accessToken}`)
|
|
.send(dto);
|
|
expect(status).toBe(204);
|
|
},
|
|
removeOfflineFiles: async (server: any, accessToken: string, id: string) => {
|
|
const { status } = await request(server)
|
|
.post(`/library/${id}/removeOffline`)
|
|
.set('Authorization', `Bearer ${accessToken}`)
|
|
.send();
|
|
expect(status).toBe(204);
|
|
},
|
|
getLibraryStatistics: async (server: any, accessToken: string, id: string): Promise<LibraryStatsResponseDto> => {
|
|
const { body, status } = await request(server)
|
|
.get(`/library/${id}/statistics`)
|
|
.set('Authorization', `Bearer ${accessToken}`);
|
|
expect(status).toBe(200);
|
|
return body;
|
|
},
|
|
update: async (server: any, accessToken: string, id: string, data: UpdateLibraryDto) => {
|
|
const { body, status } = await request(server)
|
|
.put(`/library/${id}`)
|
|
.set('Authorization', `Bearer ${accessToken}`)
|
|
.send(data);
|
|
expect(status).toBe(200);
|
|
return body as LibraryResponseDto;
|
|
},
|
|
validate: async (server: any, accessToken: string, id: string, data: ValidateLibraryDto) => {
|
|
const { body, status } = await request(server)
|
|
.post(`/library/${id}/validate`)
|
|
.set('Authorization', `Bearer ${accessToken}`)
|
|
.send(data);
|
|
expect(status).toBe(200);
|
|
return body as ValidateLibraryResponseDto;
|
|
},
|
|
};
|