mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
* feat(web): lighter timeline buckets * GalleryViewer * weird ssr * Remove generics from AssetInteraction * ensure keys on getAssetInfo, alt-text * empty - trigger ci * re-add alt-text * test fix * update tests * tests * missing import * feat(server): lighter buckets * fix: flappy e2e test * lint * revert settings * unneeded cast * fix after merge * Adapt web client to consume new server response format * test * missing import * lint * Use nulls, make-sql * openapi battle * date->string * tests * tests * lint/tests * lint * test * push aggregation to query * openapi * stack as tuple * openapi * update references to description * update alt text tests * update sql * update sql * update timeline tests * linting, fix expected response * string tuple * fix spec * fix * silly generator * rename patch * minimize sorting * review * lint * lint * sql * test * avoid abbreviations * review comment - type safety in test * merge conflicts * lint * lint/abbreviations * remove unncessary code * review comments * sql * re-add package-lock * use booleans, fix visibility in openapi spec, less cursed controller * update sql * no need to use sql template * array access actually doesn't seem to matter * remove redundant code * re-add sql decorator * unused type * remove null assertions * bad merge * Fix test * shave * extra clean shave * use decorator for content type * redundant types * redundant comment * update comment * unnecessary res --------- Co-authored-by: mertalev <101130780+mertalev@users.noreply.github.com> Co-authored-by: Alex <alex.tran1502@gmail.com>
206 lines
6.9 KiB
TypeScript
206 lines
6.9 KiB
TypeScript
import { AssetMediaResponseDto, AssetVisibility, LoginResponseDto, SharedLinkType } from '@immich/sdk';
|
|
import { DateTime } from 'luxon';
|
|
import { createUserDto } from 'src/fixtures';
|
|
import { errorDto } from 'src/responses';
|
|
import { app, utils } from 'src/utils';
|
|
import request from 'supertest';
|
|
import { beforeAll, describe, expect, it } from 'vitest';
|
|
|
|
// TODO this should probably be a test util function
|
|
const today = DateTime.fromObject({
|
|
year: 2023,
|
|
month: 11,
|
|
day: 3,
|
|
}) as DateTime<true>;
|
|
const yesterday = today.minus({ days: 1 });
|
|
|
|
describe('/timeline', () => {
|
|
let admin: LoginResponseDto;
|
|
let user: LoginResponseDto;
|
|
let timeBucketUser: LoginResponseDto;
|
|
|
|
let userAssets: AssetMediaResponseDto[];
|
|
|
|
beforeAll(async () => {
|
|
await utils.resetDatabase();
|
|
admin = await utils.adminSetup({ onboarding: false });
|
|
[user, timeBucketUser] = await Promise.all([
|
|
utils.userSetup(admin.accessToken, createUserDto.create('1')),
|
|
utils.userSetup(admin.accessToken, createUserDto.create('time-bucket')),
|
|
]);
|
|
|
|
userAssets = await Promise.all([
|
|
utils.createAsset(user.accessToken),
|
|
utils.createAsset(user.accessToken),
|
|
utils.createAsset(user.accessToken, {
|
|
isFavorite: true,
|
|
fileCreatedAt: yesterday.toISO(),
|
|
fileModifiedAt: yesterday.toISO(),
|
|
assetData: { filename: 'example.mp4' },
|
|
}),
|
|
utils.createAsset(user.accessToken),
|
|
utils.createAsset(user.accessToken),
|
|
]);
|
|
|
|
await Promise.all([
|
|
utils.createAsset(timeBucketUser.accessToken, { fileCreatedAt: new Date('1970-01-01').toISOString() }),
|
|
utils.createAsset(timeBucketUser.accessToken, { fileCreatedAt: new Date('1970-02-10').toISOString() }),
|
|
utils.createAsset(timeBucketUser.accessToken, { fileCreatedAt: new Date('1970-02-11').toISOString() }),
|
|
utils.createAsset(timeBucketUser.accessToken, { fileCreatedAt: new Date('1970-02-11').toISOString() }),
|
|
]);
|
|
});
|
|
|
|
describe('GET /timeline/buckets', () => {
|
|
it('should require authentication', async () => {
|
|
const { status, body } = await request(app).get('/timeline/buckets');
|
|
expect(status).toBe(401);
|
|
expect(body).toEqual(errorDto.unauthorized);
|
|
});
|
|
|
|
it('should get time buckets by month', async () => {
|
|
const { status, body } = await request(app)
|
|
.get('/timeline/buckets')
|
|
.set('Authorization', `Bearer ${timeBucketUser.accessToken}`);
|
|
|
|
expect(status).toBe(200);
|
|
expect(body).toEqual(
|
|
expect.arrayContaining([
|
|
{ count: 3, timeBucket: '1970-02-01T00:00:00.000Z' },
|
|
{ count: 1, timeBucket: '1970-01-01T00:00:00.000Z' },
|
|
]),
|
|
);
|
|
});
|
|
|
|
it('should not allow access for unrelated shared links', async () => {
|
|
const sharedLink = await utils.createSharedLink(user.accessToken, {
|
|
type: SharedLinkType.Individual,
|
|
assetIds: userAssets.map(({ id }) => id),
|
|
});
|
|
|
|
const { status, body } = await request(app).get('/timeline/buckets').query({ key: sharedLink.key });
|
|
|
|
expect(status).toBe(400);
|
|
expect(body).toEqual(errorDto.noPermission);
|
|
});
|
|
|
|
it('should return error if time bucket is requested with partners asset and archived', async () => {
|
|
const req1 = await request(app)
|
|
.get('/timeline/buckets')
|
|
.set('Authorization', `Bearer ${timeBucketUser.accessToken}`)
|
|
.query({ withPartners: true, visibility: AssetVisibility.Archive });
|
|
|
|
expect(req1.status).toBe(400);
|
|
expect(req1.body).toEqual(errorDto.badRequest());
|
|
|
|
const req2 = await request(app)
|
|
.get('/timeline/buckets')
|
|
.set('Authorization', `Bearer ${user.accessToken}`)
|
|
.query({ withPartners: true, visibility: undefined });
|
|
|
|
expect(req2.status).toBe(400);
|
|
expect(req2.body).toEqual(errorDto.badRequest());
|
|
});
|
|
|
|
it('should return error if time bucket is requested with partners asset and favorite', async () => {
|
|
const req1 = await request(app)
|
|
.get('/timeline/buckets')
|
|
.set('Authorization', `Bearer ${timeBucketUser.accessToken}`)
|
|
.query({ withPartners: true, isFavorite: true });
|
|
|
|
expect(req1.status).toBe(400);
|
|
expect(req1.body).toEqual(errorDto.badRequest());
|
|
|
|
const req2 = await request(app)
|
|
.get('/timeline/buckets')
|
|
.set('Authorization', `Bearer ${timeBucketUser.accessToken}`)
|
|
.query({ withPartners: true, isFavorite: false });
|
|
|
|
expect(req2.status).toBe(400);
|
|
expect(req2.body).toEqual(errorDto.badRequest());
|
|
});
|
|
|
|
it('should return error if time bucket is requested with partners asset and trash', async () => {
|
|
const req = await request(app)
|
|
.get('/timeline/buckets')
|
|
.set('Authorization', `Bearer ${user.accessToken}`)
|
|
.query({ withPartners: true, isTrashed: true });
|
|
|
|
expect(req.status).toBe(400);
|
|
expect(req.body).toEqual(errorDto.badRequest());
|
|
});
|
|
});
|
|
|
|
describe('GET /timeline/bucket', () => {
|
|
it('should require authentication', async () => {
|
|
const { status, body } = await request(app).get('/timeline/bucket').query({
|
|
timeBucket: '1900-01-01',
|
|
});
|
|
|
|
expect(status).toBe(401);
|
|
expect(body).toEqual(errorDto.unauthorized);
|
|
});
|
|
|
|
it('should handle 5 digit years', async () => {
|
|
const { status, body } = await request(app)
|
|
.get('/timeline/bucket')
|
|
.query({ timeBucket: '012345-01-01' })
|
|
.set('Authorization', `Bearer ${timeBucketUser.accessToken}`);
|
|
|
|
expect(status).toBe(200);
|
|
expect(body).toEqual({
|
|
city: [],
|
|
country: [],
|
|
duration: [],
|
|
id: [],
|
|
visibility: [],
|
|
isFavorite: [],
|
|
isImage: [],
|
|
isTrashed: [],
|
|
livePhotoVideoId: [],
|
|
localDateTime: [],
|
|
ownerId: [],
|
|
projectionType: [],
|
|
ratio: [],
|
|
status: [],
|
|
thumbhash: [],
|
|
});
|
|
});
|
|
|
|
// TODO enable date string validation while still accepting 5 digit years
|
|
// it('should fail if time bucket is invalid', async () => {
|
|
// const { status, body } = await request(app)
|
|
// .get('/timeline/bucket')
|
|
// .set('Authorization', `Bearer ${user.accessToken}`)
|
|
// .query({ timeBucket: 'foo' });
|
|
|
|
// expect(status).toBe(400);
|
|
// expect(body).toEqual(errorDto.badRequest);
|
|
// });
|
|
|
|
it('should return time bucket', async () => {
|
|
const { status, body } = await request(app)
|
|
.get('/timeline/bucket')
|
|
.set('Authorization', `Bearer ${timeBucketUser.accessToken}`)
|
|
.query({ timeBucket: '1970-02-10' });
|
|
|
|
expect(status).toBe(200);
|
|
expect(body).toEqual({
|
|
city: [],
|
|
country: [],
|
|
duration: [],
|
|
id: [],
|
|
visibility: [],
|
|
isFavorite: [],
|
|
isImage: [],
|
|
isTrashed: [],
|
|
livePhotoVideoId: [],
|
|
localDateTime: [],
|
|
ownerId: [],
|
|
projectionType: [],
|
|
ratio: [],
|
|
status: [],
|
|
thumbhash: [],
|
|
});
|
|
});
|
|
});
|
|
});
|