diff --git a/server/src/dtos/person.dto.ts b/server/src/dtos/person.dto.ts index 3f4521e4e8..f836adde00 100644 --- a/server/src/dtos/person.dto.ts +++ b/server/src/dtos/person.dto.ts @@ -102,7 +102,7 @@ export class PersonResponseDto { @PropertyLifecycle({ addedAt: 'v1.107.0' }) updatedAt?: Date; @ApiProperty() - @PropertyLifecycle({ addedAt: 'DEV' }) + @PropertyLifecycle({ addedAt: 'v1.124.0' }) isFavorite?: boolean; } diff --git a/server/src/services/person.service.spec.ts b/server/src/services/person.service.spec.ts index 3b749c0ab6..13ccc626cf 100644 --- a/server/src/services/person.service.spec.ts +++ b/server/src/services/person.service.spec.ts @@ -31,6 +31,7 @@ const responseDto: PersonResponseDto = { thumbnailPath: '/path/to/thumbnail.jpg', isHidden: false, updatedAt: expect.any(Date), + isFavorite: false, }; const statistics = { assets: 3 }; @@ -126,6 +127,35 @@ describe(PersonService.name, () => { withHidden: true, }); }); + + it('should get all visible people and favorites should be first in the array', async () => { + personMock.getAllForUser.mockResolvedValue({ + items: [personStub.isFavorite, personStub.withName], + hasNextPage: false, + }); + personMock.getNumberOfPeople.mockResolvedValue({ total: 2, hidden: 1 }); + await expect(sut.getAll(authStub.admin, { withHidden: false, page: 1, size: 10 })).resolves.toEqual({ + hasNextPage: false, + total: 2, + hidden: 1, + people: [ + { + id: 'person-4', + name: '', + birthDate: null, + thumbnailPath: '/path/to/thumbnail.jpg', + isHidden: false, + isFavorite: true, + updatedAt: expect.any(Date), + }, + responseDto, + ], + }); + expect(personMock.getAllForUser).toHaveBeenCalledWith({ skip: 0, take: 10 }, authStub.admin.user.id, { + minimumFaceCount: 3, + withHidden: false, + }); + }); }); describe('getById', () => { @@ -246,6 +276,16 @@ describe(PersonService.name, () => { expect(accessMock.person.checkOwnerAccess).toHaveBeenCalledWith(authStub.admin.user.id, new Set(['person-1'])); }); + it('should update a person favorite status', async () => { + personMock.update.mockResolvedValue(personStub.withName); + accessMock.person.checkOwnerAccess.mockResolvedValue(new Set(['person-1'])); + + await expect(sut.update(authStub.admin, 'person-1', { isFavorite: true })).resolves.toEqual(responseDto); + + expect(personMock.update).toHaveBeenCalledWith({ id: 'person-1', isHidden: true }); + expect(accessMock.person.checkOwnerAccess).toHaveBeenCalledWith(authStub.admin.user.id, new Set(['person-1'])); + }); + it("should update a person's thumbnailPath", async () => { personMock.update.mockResolvedValue(personStub.withName); personMock.getFacesByIds.mockResolvedValue([faceStub.face1]); diff --git a/server/test/fixtures/person.stub.ts b/server/test/fixtures/person.stub.ts index 544894b31e..ecd5b0dbea 100644 --- a/server/test/fixtures/person.stub.ts +++ b/server/test/fixtures/person.stub.ts @@ -15,6 +15,7 @@ export const personStub = { faceAssetId: null, faceAsset: null, isHidden: false, + isFavorite: false, }), hidden: Object.freeze({ id: 'person-1', @@ -29,6 +30,7 @@ export const personStub = { faceAssetId: null, faceAsset: null, isHidden: true, + isFavorite: false, }), withName: Object.freeze({ id: 'person-1', @@ -43,6 +45,7 @@ export const personStub = { faceAssetId: 'assetFaceId', faceAsset: null, isHidden: false, + isFavorite: false, }), withBirthDate: Object.freeze({ id: 'person-1', @@ -57,6 +60,7 @@ export const personStub = { faceAssetId: null, faceAsset: null, isHidden: false, + isFavorite: false, }), noThumbnail: Object.freeze({ id: 'person-1', @@ -71,6 +75,7 @@ export const personStub = { faceAssetId: null, faceAsset: null, isHidden: false, + isFavorite: false, }), newThumbnail: Object.freeze({ id: 'person-1', @@ -85,6 +90,7 @@ export const personStub = { faceAssetId: 'asset-id', faceAsset: null, isHidden: false, + isFavorite: false, }), primaryPerson: Object.freeze({ id: 'person-1', @@ -99,6 +105,7 @@ export const personStub = { faceAssetId: null, faceAsset: null, isHidden: false, + isFavorite: false, }), mergePerson: Object.freeze({ id: 'person-2', @@ -113,6 +120,7 @@ export const personStub = { faceAssetId: null, faceAsset: null, isHidden: false, + isFavorite: false, }), randomPerson: Object.freeze({ id: 'person-3', @@ -127,5 +135,21 @@ export const personStub = { faceAssetId: null, faceAsset: null, isHidden: false, + isFavorite: false, + }), + isFavorite: Object.freeze({ + id: 'person-4', + createdAt: new Date('2021-01-01'), + updatedAt: new Date('2021-01-01'), + ownerId: userStub.admin.id, + owner: userStub.admin, + name: 'Person 1', + birthDate: null, + thumbnailPath: '/path/to/thumbnail.jpg', + faces: [], + faceAssetId: 'assetFaceId', + faceAsset: null, + isHidden: false, + isFavorite: true, }), };