mirror of
https://github.com/immich-app/immich.git
synced 2026-03-07 10:37:22 +03:00
chore: remove asset stubs (#26187)
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { mapAsset } from 'src/dtos/asset-response.dto';
|
||||
import { AssetEditAction } from 'src/dtos/editing.dto';
|
||||
import { assetStub } from 'test/fixtures/asset.stub';
|
||||
import { faceStub } from 'test/fixtures/face.stub';
|
||||
import { personStub } from 'test/fixtures/person.stub';
|
||||
import { AssetFaceFactory } from 'test/factories/asset-face.factory';
|
||||
import { AssetFactory } from 'test/factories/asset.factory';
|
||||
import { PersonFactory } from 'test/factories/person.factory';
|
||||
|
||||
describe('mapAsset', () => {
|
||||
describe('peopleWithFaces', () => {
|
||||
it('should transform all faces when a person has multiple faces in the same image', () => {
|
||||
const person = PersonFactory.create();
|
||||
const face1 = {
|
||||
...faceStub.primaryFace1,
|
||||
boundingBoxX1: 100,
|
||||
boundingBoxY1: 100,
|
||||
boundingBoxX2: 200,
|
||||
@@ -18,8 +18,6 @@ describe('mapAsset', () => {
|
||||
};
|
||||
|
||||
const face2 = {
|
||||
...faceStub.primaryFace1,
|
||||
id: 'assetFaceId-second',
|
||||
boundingBoxX1: 300,
|
||||
boundingBoxY1: 400,
|
||||
boundingBoxX2: 400,
|
||||
@@ -28,16 +26,22 @@ describe('mapAsset', () => {
|
||||
imageHeight: 800,
|
||||
};
|
||||
|
||||
const asset = {
|
||||
...assetStub.withCropEdit,
|
||||
faces: [face1, face2],
|
||||
exifInfo: {
|
||||
exifImageWidth: 1000,
|
||||
exifImageHeight: 800,
|
||||
},
|
||||
};
|
||||
const asset = AssetFactory.from()
|
||||
.face(face1, (builder) => builder.person(person))
|
||||
.face(face2, (builder) => builder.person(person))
|
||||
.exif({ exifImageWidth: 1000, exifImageHeight: 800 })
|
||||
.edit({
|
||||
action: AssetEditAction.Crop,
|
||||
parameters: {
|
||||
width: 1512,
|
||||
height: 1152,
|
||||
x: 216,
|
||||
y: 1512,
|
||||
},
|
||||
})
|
||||
.build();
|
||||
|
||||
const result = mapAsset(asset as any);
|
||||
const result = mapAsset(asset);
|
||||
|
||||
expect(result.people).toBeDefined();
|
||||
expect(result.people).toHaveLength(1);
|
||||
@@ -61,32 +65,22 @@ describe('mapAsset', () => {
|
||||
});
|
||||
|
||||
it('should transform unassigned faces with edits and dimensions', () => {
|
||||
const unassignedFace = {
|
||||
...faceStub.noPerson1,
|
||||
const unassignedFace = AssetFaceFactory.create({
|
||||
boundingBoxX1: 100,
|
||||
boundingBoxY1: 100,
|
||||
boundingBoxX2: 200,
|
||||
boundingBoxY2: 200,
|
||||
imageWidth: 1000,
|
||||
imageHeight: 800,
|
||||
};
|
||||
});
|
||||
|
||||
const asset = {
|
||||
...assetStub.withCropEdit,
|
||||
faces: [unassignedFace],
|
||||
exifInfo: {
|
||||
exifImageWidth: 1000,
|
||||
exifImageHeight: 800,
|
||||
},
|
||||
edits: [
|
||||
{
|
||||
action: AssetEditAction.Crop,
|
||||
parameters: { x: 50, y: 50, width: 500, height: 400 },
|
||||
},
|
||||
],
|
||||
};
|
||||
const asset = AssetFactory.from()
|
||||
.face(unassignedFace)
|
||||
.exif({ exifImageWidth: 1000, exifImageHeight: 800 })
|
||||
.edit({ action: AssetEditAction.Crop, parameters: { x: 50, y: 50, width: 500, height: 400 } })
|
||||
.build();
|
||||
|
||||
const result = mapAsset(asset as any);
|
||||
const result = mapAsset(asset);
|
||||
|
||||
expect(result.unassignedFaces).toBeDefined();
|
||||
expect(result.unassignedFaces).toHaveLength(1);
|
||||
@@ -101,10 +95,6 @@ describe('mapAsset', () => {
|
||||
|
||||
it('should handle multiple people each with multiple faces', () => {
|
||||
const person1Face1 = {
|
||||
...faceStub.primaryFace1,
|
||||
id: 'face-1-1',
|
||||
person: personStub.withName,
|
||||
personId: personStub.withName.id,
|
||||
boundingBoxX1: 100,
|
||||
boundingBoxY1: 100,
|
||||
boundingBoxX2: 200,
|
||||
@@ -114,10 +104,6 @@ describe('mapAsset', () => {
|
||||
};
|
||||
|
||||
const person1Face2 = {
|
||||
...faceStub.primaryFace1,
|
||||
id: 'face-1-2',
|
||||
person: personStub.withName,
|
||||
personId: personStub.withName.id,
|
||||
boundingBoxX1: 300,
|
||||
boundingBoxY1: 300,
|
||||
boundingBoxX2: 400,
|
||||
@@ -127,10 +113,6 @@ describe('mapAsset', () => {
|
||||
};
|
||||
|
||||
const person2Face1 = {
|
||||
...faceStub.mergeFace1,
|
||||
id: 'face-2-1',
|
||||
person: personStub.mergePerson,
|
||||
personId: personStub.mergePerson.id,
|
||||
boundingBoxX1: 500,
|
||||
boundingBoxY1: 100,
|
||||
boundingBoxX2: 600,
|
||||
@@ -139,23 +121,22 @@ describe('mapAsset', () => {
|
||||
imageHeight: 800,
|
||||
};
|
||||
|
||||
const asset = {
|
||||
...assetStub.withCropEdit,
|
||||
faces: [person1Face1, person1Face2, person2Face1],
|
||||
exifInfo: {
|
||||
exifImageWidth: 1000,
|
||||
exifImageHeight: 800,
|
||||
},
|
||||
edits: [],
|
||||
};
|
||||
const person = PersonFactory.create({ id: 'person-1' });
|
||||
|
||||
const result = mapAsset(asset as any);
|
||||
const asset = AssetFactory.from()
|
||||
.face(person1Face1, (builder) => builder.person(person))
|
||||
.face(person1Face2, (builder) => builder.person(person))
|
||||
.face(person2Face1, (builder) => builder.person({ id: 'person-2' }))
|
||||
.exif({ exifImageWidth: 1000, exifImageHeight: 800 })
|
||||
.build();
|
||||
|
||||
const result = mapAsset(asset);
|
||||
|
||||
expect(result.people).toBeDefined();
|
||||
expect(result.people).toHaveLength(2);
|
||||
|
||||
const person1 = result.people!.find((p) => p.id === personStub.withName.id);
|
||||
const person2 = result.people!.find((p) => p.id === personStub.mergePerson.id);
|
||||
const person1 = result.people!.find((p) => p.id === 'person-1');
|
||||
const person2 = result.people!.find((p) => p.id === 'person-2');
|
||||
|
||||
expect(person1).toBeDefined();
|
||||
expect(person1!.faces).toHaveLength(2);
|
||||
@@ -173,10 +154,6 @@ describe('mapAsset', () => {
|
||||
|
||||
it('should combine faces of the same person into a single entry', () => {
|
||||
const face1 = {
|
||||
...faceStub.primaryFace1,
|
||||
id: 'face-1',
|
||||
person: personStub.withName,
|
||||
personId: personStub.withName.id,
|
||||
boundingBoxX1: 100,
|
||||
boundingBoxY1: 100,
|
||||
boundingBoxX2: 200,
|
||||
@@ -186,10 +163,6 @@ describe('mapAsset', () => {
|
||||
};
|
||||
|
||||
const face2 = {
|
||||
...faceStub.primaryFace1,
|
||||
id: 'face-2',
|
||||
person: personStub.withName,
|
||||
personId: personStub.withName.id,
|
||||
boundingBoxX1: 300,
|
||||
boundingBoxY1: 300,
|
||||
boundingBoxX2: 400,
|
||||
@@ -198,24 +171,21 @@ describe('mapAsset', () => {
|
||||
imageHeight: 800,
|
||||
};
|
||||
|
||||
const asset = {
|
||||
...assetStub.withCropEdit,
|
||||
faces: [face1, face2],
|
||||
exifInfo: {
|
||||
exifImageWidth: 1000,
|
||||
exifImageHeight: 800,
|
||||
},
|
||||
edits: [],
|
||||
};
|
||||
const person = PersonFactory.create();
|
||||
|
||||
const result = mapAsset(asset as any);
|
||||
const asset = AssetFactory.from()
|
||||
.face(face1, (builder) => builder.person(person))
|
||||
.face(face2, (builder) => builder.person(person))
|
||||
.exif({ exifImageWidth: 1000, exifImageHeight: 800 })
|
||||
.build();
|
||||
|
||||
const result = mapAsset(asset);
|
||||
|
||||
expect(result.people).toBeDefined();
|
||||
expect(result.people).toHaveLength(1);
|
||||
|
||||
const person = result.people![0];
|
||||
expect(person.id).toBe(personStub.withName.id);
|
||||
expect(person.faces).toHaveLength(2);
|
||||
expect(result.people![0].id).toBe(person.id);
|
||||
expect(result.people![0].faces).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user