2023-09-11 17:56:38 +02:00
|
|
|
import { AssetResponseDto } from '@app/domain';
|
|
|
|
import { CreateAssetDto } from '@app/immich/api-v1/asset/dto/create-asset.dto';
|
|
|
|
import { AssetFileUploadResponseDto } from '@app/immich/api-v1/asset/response-dto/asset-file-upload-response.dto';
|
|
|
|
import { randomBytes } from 'crypto';
|
|
|
|
import request from 'supertest';
|
|
|
|
|
2024-01-25 00:24:53 +02:00
|
|
|
type UploadDto = Partial<CreateAssetDto> & { content?: Buffer; filename?: string };
|
2023-09-11 17:56:38 +02:00
|
|
|
|
2023-11-16 01:50:55 +02:00
|
|
|
const asset = {
|
|
|
|
deviceAssetId: 'test-1',
|
|
|
|
deviceId: 'test',
|
|
|
|
fileCreatedAt: new Date(),
|
|
|
|
fileModifiedAt: new Date(),
|
|
|
|
};
|
|
|
|
|
2023-09-11 17:56:38 +02:00
|
|
|
export const assetApi = {
|
2023-11-15 03:08:22 +02:00
|
|
|
create: async (
|
|
|
|
server: any,
|
|
|
|
accessToken: string,
|
2023-11-16 01:50:55 +02:00
|
|
|
dto?: Omit<CreateAssetDto, 'assetData'>,
|
2023-11-15 03:08:22 +02:00
|
|
|
): Promise<AssetResponseDto> => {
|
2023-11-16 01:50:55 +02:00
|
|
|
dto = dto || asset;
|
2023-11-15 03:08:22 +02:00
|
|
|
const { status, body } = await request(server)
|
|
|
|
.post(`/asset/upload`)
|
|
|
|
.field('deviceAssetId', dto.deviceAssetId)
|
|
|
|
.field('deviceId', dto.deviceId)
|
|
|
|
.field('fileCreatedAt', dto.fileCreatedAt.toISOString())
|
|
|
|
.field('fileModifiedAt', dto.fileModifiedAt.toISOString())
|
|
|
|
.attach('assetData', randomBytes(32), 'example.jpg')
|
|
|
|
.set('Authorization', `Bearer ${accessToken}`);
|
|
|
|
|
|
|
|
expect([200, 201].includes(status)).toBe(true);
|
|
|
|
|
|
|
|
return body as AssetResponseDto;
|
|
|
|
},
|
2023-10-06 23:32:28 +02:00
|
|
|
get: async (server: any, accessToken: string, id: string): Promise<AssetResponseDto> => {
|
2023-09-11 17:56:38 +02:00
|
|
|
const { body, status } = await request(server)
|
|
|
|
.get(`/asset/assetById/${id}`)
|
|
|
|
.set('Authorization', `Bearer ${accessToken}`);
|
|
|
|
expect(status).toBe(200);
|
|
|
|
return body as AssetResponseDto;
|
|
|
|
},
|
2023-10-06 23:32:28 +02:00
|
|
|
getAllAssets: async (server: any, accessToken: string) => {
|
|
|
|
const { body, status } = await request(server).get(`/asset/`).set('Authorization', `Bearer ${accessToken}`);
|
|
|
|
expect(status).toBe(200);
|
|
|
|
return body as AssetResponseDto[];
|
|
|
|
},
|
2024-01-25 00:24:53 +02:00
|
|
|
upload: async (server: any, accessToken: string, deviceAssetId: string, dto: UploadDto = {}) => {
|
|
|
|
const { content, filename, isFavorite = false, isArchived = false } = dto;
|
2023-09-11 17:56:38 +02:00
|
|
|
const { body, status } = await request(server)
|
|
|
|
.post('/asset/upload')
|
|
|
|
.set('Authorization', `Bearer ${accessToken}`)
|
2024-01-25 00:24:53 +02:00
|
|
|
.field('deviceAssetId', deviceAssetId)
|
2023-09-11 17:56:38 +02:00
|
|
|
.field('deviceId', 'TEST')
|
|
|
|
.field('fileCreatedAt', new Date().toISOString())
|
|
|
|
.field('fileModifiedAt', new Date().toISOString())
|
|
|
|
.field('isFavorite', isFavorite)
|
|
|
|
.field('isArchived', isArchived)
|
|
|
|
.field('duration', '0:00:00.000000')
|
2024-01-25 00:24:53 +02:00
|
|
|
.attach('assetData', content || randomBytes(32), filename || 'example.jpg');
|
2023-09-11 17:56:38 +02:00
|
|
|
|
|
|
|
expect(status).toBe(201);
|
|
|
|
return body as AssetFileUploadResponseDto;
|
|
|
|
},
|
2023-12-26 23:27:51 +02:00
|
|
|
getWebpThumbnail: async (server: any, accessToken: string, assetId: string) => {
|
|
|
|
const { body, status } = await request(server)
|
|
|
|
.get(`/asset/thumbnail/${assetId}`)
|
|
|
|
.set('Authorization', `Bearer ${accessToken}`);
|
|
|
|
expect(status).toBe(200);
|
|
|
|
return body;
|
|
|
|
},
|
|
|
|
getJpegThumbnail: async (server: any, accessToken: string, assetId: string) => {
|
|
|
|
const { body, status } = await request(server)
|
|
|
|
.get(`/asset/thumbnail/${assetId}?format=JPEG`)
|
|
|
|
.set('Authorization', `Bearer ${accessToken}`);
|
|
|
|
expect(status).toBe(200);
|
|
|
|
return body;
|
|
|
|
},
|
2023-09-11 17:56:38 +02:00
|
|
|
};
|