mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat(server): create a person with optional values (#7706)
* feat: create person dto * chore: open api * fix: e2e * fix: web usage
This commit is contained in:
parent
f1a8e385e9
commit
661409bac7
20 changed files with 372 additions and 148 deletions
|
|
@ -5,7 +5,15 @@ import { app, utils } from 'src/utils';
|
|||
import request from 'supertest';
|
||||
import { beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
describe('/activity', () => {
|
||||
const invalidBirthday = [
|
||||
// TODO: enable after replacing `@Type(() => Date)`
|
||||
// { birthDate: 'false', response: 'Invalid date' },
|
||||
// { birthDate: '123567', response: 'Invalid date },
|
||||
// { birthDate: 123_567, response: ['Birth date cannot be in the future'] },
|
||||
{ birthDate: new Date(9999, 0, 0).toISOString(), response: ['Birth date cannot be in the future'] },
|
||||
];
|
||||
|
||||
describe('/person', () => {
|
||||
let admin: LoginResponseDto;
|
||||
let visiblePerson: PersonResponseDto;
|
||||
let hiddenPerson: PersonResponseDto;
|
||||
|
|
@ -14,10 +22,6 @@ describe('/activity', () => {
|
|||
beforeAll(async () => {
|
||||
await utils.resetDatabase();
|
||||
admin = await utils.adminSetup();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await utils.resetDatabase(['person']);
|
||||
|
||||
[visiblePerson, hiddenPerson, multipleAssetsPerson] = await Promise.all([
|
||||
utils.createPerson(admin.accessToken, {
|
||||
|
|
@ -141,6 +145,41 @@ describe('/activity', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('POST /person', () => {
|
||||
it('should require authentication', async () => {
|
||||
const { status, body } = await request(app).post(`/person`);
|
||||
expect(status).toBe(401);
|
||||
expect(body).toEqual(errorDto.unauthorized);
|
||||
});
|
||||
|
||||
it('should not accept invalid birth dates', async () => {
|
||||
for (const { birthDate, response } of invalidBirthday) {
|
||||
const { status, body } = await request(app)
|
||||
.post(`/person`)
|
||||
.set('Authorization', `Bearer ${admin.accessToken}`)
|
||||
.send({ birthDate });
|
||||
expect(status).toBe(400);
|
||||
expect(body).toEqual(errorDto.badRequest(response));
|
||||
}
|
||||
});
|
||||
|
||||
it('should create a person', async () => {
|
||||
const { status, body } = await request(app)
|
||||
.post(`/person`)
|
||||
.set('Authorization', `Bearer ${admin.accessToken}`)
|
||||
.send({
|
||||
name: 'New Person',
|
||||
birthDate: '1990-01-01T05:00:00.000Z',
|
||||
});
|
||||
expect(status).toBe(201);
|
||||
expect(body).toMatchObject({
|
||||
id: expect.any(String),
|
||||
name: 'New Person',
|
||||
birthDate: '1990-01-01T05:00:00.000Z',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /person/:id', () => {
|
||||
it('should require authentication', async () => {
|
||||
const { status, body } = await request(app).put(`/person/${uuidDto.notFound}`);
|
||||
|
|
@ -164,17 +203,9 @@ describe('/activity', () => {
|
|||
}
|
||||
|
||||
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: 123_567, response: 'Not found or no person.write access' },
|
||||
]) {
|
||||
for (const { birthDate, response } of invalidBirthday) {
|
||||
const { status, body } = await request(app)
|
||||
.put(`/person/${uuidDto.notFound}`)
|
||||
.put(`/person/${visiblePerson.id}`)
|
||||
.set('Authorization', `Bearer ${admin.accessToken}`)
|
||||
.send({ birthDate });
|
||||
expect(status).toBe(400);
|
||||
|
|
@ -192,15 +223,8 @@ describe('/activity', () => {
|
|||
});
|
||||
|
||||
it('should clear a date of birth', async () => {
|
||||
// TODO ironically this uses the update endpoint to create the person
|
||||
const person = await utils.createPerson(admin.accessToken, {
|
||||
birthDate: new Date('1990-01-01').toISOString(),
|
||||
});
|
||||
|
||||
expect(person.birthDate).toBeDefined();
|
||||
|
||||
const { status, body } = await request(app)
|
||||
.put(`/person/${person.id}`)
|
||||
.put(`/person/${visiblePerson.id}`)
|
||||
.set('Authorization', `Bearer ${admin.accessToken}`)
|
||||
.send({ birthDate: null });
|
||||
expect(status).toBe(200);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue