mirror of
https://github.com/immich-app/immich.git
synced 2025-01-28 00:59:18 -05:00
feat(server): added unit test for favorite people
This commit is contained in:
parent
87fa163bdd
commit
78c0cadd78
3 changed files with 65 additions and 1 deletions
|
@ -102,7 +102,7 @@ export class PersonResponseDto {
|
||||||
@PropertyLifecycle({ addedAt: 'v1.107.0' })
|
@PropertyLifecycle({ addedAt: 'v1.107.0' })
|
||||||
updatedAt?: Date;
|
updatedAt?: Date;
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@PropertyLifecycle({ addedAt: 'DEV' })
|
@PropertyLifecycle({ addedAt: 'v1.124.0' })
|
||||||
isFavorite?: boolean;
|
isFavorite?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ const responseDto: PersonResponseDto = {
|
||||||
thumbnailPath: '/path/to/thumbnail.jpg',
|
thumbnailPath: '/path/to/thumbnail.jpg',
|
||||||
isHidden: false,
|
isHidden: false,
|
||||||
updatedAt: expect.any(Date),
|
updatedAt: expect.any(Date),
|
||||||
|
isFavorite: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const statistics = { assets: 3 };
|
const statistics = { assets: 3 };
|
||||||
|
@ -126,6 +127,35 @@ describe(PersonService.name, () => {
|
||||||
withHidden: true,
|
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', () => {
|
describe('getById', () => {
|
||||||
|
@ -246,6 +276,16 @@ describe(PersonService.name, () => {
|
||||||
expect(accessMock.person.checkOwnerAccess).toHaveBeenCalledWith(authStub.admin.user.id, new Set(['person-1']));
|
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 () => {
|
it("should update a person's thumbnailPath", async () => {
|
||||||
personMock.update.mockResolvedValue(personStub.withName);
|
personMock.update.mockResolvedValue(personStub.withName);
|
||||||
personMock.getFacesByIds.mockResolvedValue([faceStub.face1]);
|
personMock.getFacesByIds.mockResolvedValue([faceStub.face1]);
|
||||||
|
|
24
server/test/fixtures/person.stub.ts
vendored
24
server/test/fixtures/person.stub.ts
vendored
|
@ -15,6 +15,7 @@ export const personStub = {
|
||||||
faceAssetId: null,
|
faceAssetId: null,
|
||||||
faceAsset: null,
|
faceAsset: null,
|
||||||
isHidden: false,
|
isHidden: false,
|
||||||
|
isFavorite: false,
|
||||||
}),
|
}),
|
||||||
hidden: Object.freeze<PersonEntity>({
|
hidden: Object.freeze<PersonEntity>({
|
||||||
id: 'person-1',
|
id: 'person-1',
|
||||||
|
@ -29,6 +30,7 @@ export const personStub = {
|
||||||
faceAssetId: null,
|
faceAssetId: null,
|
||||||
faceAsset: null,
|
faceAsset: null,
|
||||||
isHidden: true,
|
isHidden: true,
|
||||||
|
isFavorite: false,
|
||||||
}),
|
}),
|
||||||
withName: Object.freeze<PersonEntity>({
|
withName: Object.freeze<PersonEntity>({
|
||||||
id: 'person-1',
|
id: 'person-1',
|
||||||
|
@ -43,6 +45,7 @@ export const personStub = {
|
||||||
faceAssetId: 'assetFaceId',
|
faceAssetId: 'assetFaceId',
|
||||||
faceAsset: null,
|
faceAsset: null,
|
||||||
isHidden: false,
|
isHidden: false,
|
||||||
|
isFavorite: false,
|
||||||
}),
|
}),
|
||||||
withBirthDate: Object.freeze<PersonEntity>({
|
withBirthDate: Object.freeze<PersonEntity>({
|
||||||
id: 'person-1',
|
id: 'person-1',
|
||||||
|
@ -57,6 +60,7 @@ export const personStub = {
|
||||||
faceAssetId: null,
|
faceAssetId: null,
|
||||||
faceAsset: null,
|
faceAsset: null,
|
||||||
isHidden: false,
|
isHidden: false,
|
||||||
|
isFavorite: false,
|
||||||
}),
|
}),
|
||||||
noThumbnail: Object.freeze<PersonEntity>({
|
noThumbnail: Object.freeze<PersonEntity>({
|
||||||
id: 'person-1',
|
id: 'person-1',
|
||||||
|
@ -71,6 +75,7 @@ export const personStub = {
|
||||||
faceAssetId: null,
|
faceAssetId: null,
|
||||||
faceAsset: null,
|
faceAsset: null,
|
||||||
isHidden: false,
|
isHidden: false,
|
||||||
|
isFavorite: false,
|
||||||
}),
|
}),
|
||||||
newThumbnail: Object.freeze<PersonEntity>({
|
newThumbnail: Object.freeze<PersonEntity>({
|
||||||
id: 'person-1',
|
id: 'person-1',
|
||||||
|
@ -85,6 +90,7 @@ export const personStub = {
|
||||||
faceAssetId: 'asset-id',
|
faceAssetId: 'asset-id',
|
||||||
faceAsset: null,
|
faceAsset: null,
|
||||||
isHidden: false,
|
isHidden: false,
|
||||||
|
isFavorite: false,
|
||||||
}),
|
}),
|
||||||
primaryPerson: Object.freeze<PersonEntity>({
|
primaryPerson: Object.freeze<PersonEntity>({
|
||||||
id: 'person-1',
|
id: 'person-1',
|
||||||
|
@ -99,6 +105,7 @@ export const personStub = {
|
||||||
faceAssetId: null,
|
faceAssetId: null,
|
||||||
faceAsset: null,
|
faceAsset: null,
|
||||||
isHidden: false,
|
isHidden: false,
|
||||||
|
isFavorite: false,
|
||||||
}),
|
}),
|
||||||
mergePerson: Object.freeze<PersonEntity>({
|
mergePerson: Object.freeze<PersonEntity>({
|
||||||
id: 'person-2',
|
id: 'person-2',
|
||||||
|
@ -113,6 +120,7 @@ export const personStub = {
|
||||||
faceAssetId: null,
|
faceAssetId: null,
|
||||||
faceAsset: null,
|
faceAsset: null,
|
||||||
isHidden: false,
|
isHidden: false,
|
||||||
|
isFavorite: false,
|
||||||
}),
|
}),
|
||||||
randomPerson: Object.freeze<PersonEntity>({
|
randomPerson: Object.freeze<PersonEntity>({
|
||||||
id: 'person-3',
|
id: 'person-3',
|
||||||
|
@ -127,5 +135,21 @@ export const personStub = {
|
||||||
faceAssetId: null,
|
faceAssetId: null,
|
||||||
faceAsset: null,
|
faceAsset: null,
|
||||||
isHidden: false,
|
isHidden: false,
|
||||||
|
isFavorite: false,
|
||||||
|
}),
|
||||||
|
isFavorite: Object.freeze<PersonEntity>({
|
||||||
|
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,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue