2024-03-20 19:32:04 +01:00
|
|
|
import { CreateLibraryDto, LibraryResponseDto, ScanLibraryDto } from 'src/domain/library/library.dto';
|
2023-09-20 13:16:33 +02:00
|
|
|
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[];
|
|
|
|
},
|
2023-10-06 23:32:28 +02:00
|
|
|
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);
|
2024-02-29 21:10:08 +01:00
|
|
|
expect(status).toBe(204);
|
2023-10-06 23:32:28 +02:00
|
|
|
},
|
2023-09-20 13:16:33 +02:00
|
|
|
};
|