mirror of
https://github.com/immich-app/immich.git
synced 2024-12-23 02:06:15 +02:00
4e9b96ff1a
* Allow building and installing cli * feat: add format fix * docs: remove cli folder * feat: use immich scoped package * feat: rewrite cli readme * docs: add info on running without building * cleanup * chore: remove import functionality from cli * feat: add logout to cli * docs: add todo for file format from server * docs: add compilation step to cli * fix: success message spacing * feat: can create albums * fix: add check step to cli * fix: typos * feat: pull file formats from server * chore: use crawl service from server * chore: fix lint * docs: add cli documentation * chore: rename ignore pattern * chore: add version number to cli * feat: use sdk * fix: cleanup * feat: album name on windows * chore: remove skipped asset field * feat: add more info to server-info command * chore: cleanup * wip * chore: remove unneeded packages * e2e test can start * git ignore for geocode in cli * add cli e2e to github actions * can do e2e tests in the cli * simplify e2e test * cleanup * set matrix strategy in workflow * run npm ci in server * choose different working directory * check out submodules too * increase test timeout * set node version * cli docker e2e tests * fix cli docker file * run cli e2e in correct folder * set docker context * correct docker build * remove cli from dockerignore * chore: fix docs links * feat: add cli v2 milestone * fix: set correct cli date * remove submodule * chore: add npmignore * chore(cli): push to npm * fix: server e2e * run npm ci in server * remove state from e2e * run npm ci in server * reshuffle docker compose files * use new e2e composes in makefile * increase test timeout to 10 minutes * make github actions run makefile e2e tests * cleanup github test names * assert on server version * chore: split cli e2e tests into one file per command * chore: set cli release working dir * chore: add repo url to npmjs * chore: bump node setup to v4 * chore: normalize the github url * check e2e code in lint * fix lint * test key login flow * feat: allow configurable config dir * fix session service tests * create missing dir * cleanup * bump cli version to 2.0.4 * remove form-data * feat: allow single files as argument * add version option * bump dependencies * fix lint * wip use axios as upload * version bump * cApiTALiZaTiON * don't touch package lock * wip: don't use job queues * don't use make for cli e2e * fix server e2e * chore: remove old gha step * add npm ci to server --------- Co-authored-by: Alex <alex.tran1502@gmail.com> Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
190 lines
6.3 KiB
TypeScript
190 lines
6.3 KiB
TypeScript
import { IPersonRepository, LoginResponseDto } from '@app/domain';
|
|
import { PersonController } from '@app/immich';
|
|
import { PersonEntity } from '@app/infra/entities';
|
|
import { INestApplication } from '@nestjs/common';
|
|
import { api } from '@test/api';
|
|
import { errorStub, uuidStub } from '@test/fixtures';
|
|
import { testApp } from '@test/test-utils';
|
|
import request from 'supertest';
|
|
|
|
describe(`${PersonController.name}`, () => {
|
|
let app: INestApplication;
|
|
let server: any;
|
|
let loginResponse: LoginResponseDto;
|
|
let accessToken: string;
|
|
let personRepository: IPersonRepository;
|
|
let visiblePerson: PersonEntity;
|
|
let hiddenPerson: PersonEntity;
|
|
|
|
beforeAll(async () => {
|
|
app = await testApp.create();
|
|
server = app.getHttpServer();
|
|
personRepository = app.get<IPersonRepository>(IPersonRepository);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await testApp.teardown();
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
await testApp.reset();
|
|
await api.authApi.adminSignUp(server);
|
|
loginResponse = await api.authApi.adminLogin(server);
|
|
accessToken = loginResponse.accessToken;
|
|
|
|
const faceAsset = await api.assetApi.upload(server, accessToken, 'face_asset');
|
|
visiblePerson = await personRepository.create({
|
|
ownerId: loginResponse.userId,
|
|
name: 'visible_person',
|
|
thumbnailPath: '/thumbnail/face_asset',
|
|
});
|
|
await personRepository.createFace({
|
|
assetId: faceAsset.id,
|
|
personId: visiblePerson.id,
|
|
embedding: Array.from({ length: 512 }, Math.random),
|
|
});
|
|
|
|
hiddenPerson = await personRepository.create({
|
|
ownerId: loginResponse.userId,
|
|
name: 'hidden_person',
|
|
isHidden: true,
|
|
thumbnailPath: '/thumbnail/face_asset',
|
|
});
|
|
await personRepository.createFace({
|
|
assetId: faceAsset.id,
|
|
personId: hiddenPerson.id,
|
|
embedding: Array.from({ length: 512 }, Math.random),
|
|
});
|
|
});
|
|
|
|
describe('GET /person', () => {
|
|
beforeEach(async () => {});
|
|
|
|
it('should require authentication', async () => {
|
|
const { status, body } = await request(server).get('/person');
|
|
|
|
expect(status).toBe(401);
|
|
expect(body).toEqual(errorStub.unauthorized);
|
|
});
|
|
|
|
it('should return all people (including hidden)', async () => {
|
|
const { status, body } = await request(server)
|
|
.get('/person')
|
|
.set('Authorization', `Bearer ${accessToken}`)
|
|
.query({ withHidden: true });
|
|
|
|
expect(status).toBe(200);
|
|
expect(body).toEqual({
|
|
total: 2,
|
|
visible: 1,
|
|
people: [
|
|
expect.objectContaining({ name: 'visible_person' }),
|
|
expect.objectContaining({ name: 'hidden_person' }),
|
|
],
|
|
});
|
|
});
|
|
|
|
it('should return only visible people', async () => {
|
|
const { status, body } = await request(server).get('/person').set('Authorization', `Bearer ${accessToken}`);
|
|
|
|
expect(status).toBe(200);
|
|
expect(body).toEqual({
|
|
total: 1,
|
|
visible: 1,
|
|
people: [expect.objectContaining({ name: 'visible_person' })],
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('GET /person/:id', () => {
|
|
it('should require authentication', async () => {
|
|
const { status, body } = await request(server).get(`/person/${uuidStub.notFound}`);
|
|
|
|
expect(status).toBe(401);
|
|
expect(body).toEqual(errorStub.unauthorized);
|
|
});
|
|
|
|
it('should throw error if person with id does not exist', async () => {
|
|
const { status, body } = await request(server)
|
|
.get(`/person/${uuidStub.notFound}`)
|
|
.set('Authorization', `Bearer ${accessToken}`);
|
|
|
|
expect(status).toBe(400);
|
|
expect(body).toEqual(errorStub.badRequest());
|
|
});
|
|
|
|
it('should return person information', async () => {
|
|
const { status, body } = await request(server)
|
|
.get(`/person/${visiblePerson.id}`)
|
|
.set('Authorization', `Bearer ${accessToken}`);
|
|
|
|
expect(status).toBe(200);
|
|
expect(body).toEqual(expect.objectContaining({ id: visiblePerson.id }));
|
|
});
|
|
});
|
|
|
|
describe('PUT /person/:id', () => {
|
|
it('should require authentication', async () => {
|
|
const { status, body } = await request(server).put(`/person/${uuidStub.notFound}`);
|
|
expect(status).toBe(401);
|
|
expect(body).toEqual(errorStub.unauthorized);
|
|
});
|
|
|
|
for (const { key, type } of [
|
|
{ key: 'name', type: 'string' },
|
|
{ key: 'featureFaceAssetId', type: 'string' },
|
|
{ key: 'isHidden', type: 'boolean value' },
|
|
]) {
|
|
it(`should not allow null ${key}`, async () => {
|
|
const { status, body } = await request(server)
|
|
.put(`/person/${visiblePerson.id}`)
|
|
.set('Authorization', `Bearer ${accessToken}`)
|
|
.send({ [key]: null });
|
|
expect(status).toBe(400);
|
|
expect(body).toEqual(errorStub.badRequest([`${key} must be a ${type}`]));
|
|
});
|
|
}
|
|
|
|
it('should not accept invalid birth dates', async () => {
|
|
for (const { birthDate, response } of [
|
|
{ birthDate: false, response: 'Not found or no person.write access' },
|
|
{ birthDate: 'false', response: ['birthDate must be a Date instance'] },
|
|
{ birthDate: '123567', response: 'Not found or no person.write access' },
|
|
{ birthDate: 123567, response: 'Not found or no person.write access' },
|
|
]) {
|
|
const { status, body } = await request(server)
|
|
.put(`/person/${uuidStub.notFound}`)
|
|
.set('Authorization', `Bearer ${accessToken}`)
|
|
.send({ birthDate });
|
|
expect(status).toBe(400);
|
|
expect(body).toEqual(errorStub.badRequest(response));
|
|
}
|
|
});
|
|
|
|
it('should update a date of birth', async () => {
|
|
const { status, body } = await request(server)
|
|
.put(`/person/${visiblePerson.id}`)
|
|
.set('Authorization', `Bearer ${accessToken}`)
|
|
.send({ birthDate: '1990-01-01T05:00:00.000Z' });
|
|
expect(status).toBe(200);
|
|
expect(body).toMatchObject({ birthDate: '1990-01-01' });
|
|
});
|
|
|
|
it('should clear a date of birth', async () => {
|
|
const person = await personRepository.create({
|
|
birthDate: new Date('1990-01-01'),
|
|
ownerId: loginResponse.userId,
|
|
});
|
|
|
|
expect(person.birthDate).toBeDefined();
|
|
|
|
const { status, body } = await request(server)
|
|
.put(`/person/${person.id}`)
|
|
.set('Authorization', `Bearer ${accessToken}`)
|
|
.send({ birthDate: null });
|
|
expect(status).toBe(200);
|
|
expect(body).toMatchObject({ birthDate: null });
|
|
});
|
|
});
|
|
});
|