mirror of
https://github.com/immich-app/immich.git
synced 2026-02-28 09:38:43 +03:00
chore: remove asset stubs (#26187)
This commit is contained in:
47
server/test/factories/asset-face.factory.ts
Normal file
47
server/test/factories/asset-face.factory.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Selectable } from 'kysely';
|
||||
import { SourceType } from 'src/enum';
|
||||
import { AssetFaceTable } from 'src/schema/tables/asset-face.table';
|
||||
import { build } from 'test/factories/builder.factory';
|
||||
import { PersonFactory } from 'test/factories/person.factory';
|
||||
import { AssetFaceLike, FactoryBuilder, PersonLike } from 'test/factories/types';
|
||||
import { newDate, newUuid, newUuidV7 } from 'test/small.factory';
|
||||
|
||||
export class AssetFaceFactory {
|
||||
#person: PersonFactory | null = null;
|
||||
|
||||
private constructor(private readonly value: Selectable<AssetFaceTable>) {}
|
||||
|
||||
static create(dto: AssetFaceLike = {}) {
|
||||
return AssetFaceFactory.from(dto).build();
|
||||
}
|
||||
|
||||
static from(dto: AssetFaceLike = {}) {
|
||||
return new AssetFaceFactory({
|
||||
assetId: newUuid(),
|
||||
boundingBoxX1: 11,
|
||||
boundingBoxX2: 12,
|
||||
boundingBoxY1: 21,
|
||||
boundingBoxY2: 22,
|
||||
deletedAt: null,
|
||||
id: newUuid(),
|
||||
imageHeight: 42,
|
||||
imageWidth: 420,
|
||||
isVisible: true,
|
||||
personId: null,
|
||||
sourceType: SourceType.MachineLearning,
|
||||
updatedAt: newDate(),
|
||||
updateId: newUuidV7(),
|
||||
...dto,
|
||||
});
|
||||
}
|
||||
|
||||
person(dto: PersonLike = {}, builder?: FactoryBuilder<PersonFactory>) {
|
||||
this.#person = build(PersonFactory.from(dto), builder);
|
||||
this.value.personId = this.#person.build().id;
|
||||
return this;
|
||||
}
|
||||
|
||||
build() {
|
||||
return { ...this.value, person: this.#person?.build() ?? null };
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,23 @@
|
||||
import { Selectable } from 'kysely';
|
||||
import { AssetFileType, AssetStatus, AssetType, AssetVisibility } from 'src/enum';
|
||||
import { AssetFaceTable } from 'src/schema/tables/asset-face.table';
|
||||
import { AssetTable } from 'src/schema/tables/asset.table';
|
||||
import { StackTable } from 'src/schema/tables/stack.table';
|
||||
import { AssetEditFactory } from 'test/factories/asset-edit.factory';
|
||||
import { AssetExifFactory } from 'test/factories/asset-exif.factory';
|
||||
import { AssetFaceFactory } from 'test/factories/asset-face.factory';
|
||||
import { AssetFileFactory } from 'test/factories/asset-file.factory';
|
||||
import { build } from 'test/factories/builder.factory';
|
||||
import { AssetEditLike, AssetExifLike, AssetFileLike, AssetLike, FactoryBuilder, UserLike } from 'test/factories/types';
|
||||
import { StackFactory } from 'test/factories/stack.factory';
|
||||
import {
|
||||
AssetEditLike,
|
||||
AssetExifLike,
|
||||
AssetFaceLike,
|
||||
AssetFileLike,
|
||||
AssetLike,
|
||||
FactoryBuilder,
|
||||
StackLike,
|
||||
UserLike,
|
||||
} from 'test/factories/types';
|
||||
import { UserFactory } from 'test/factories/user.factory';
|
||||
import { newDate, newSha1, newUuid, newUuidV7 } from 'test/small.factory';
|
||||
|
||||
@@ -15,7 +26,8 @@ export class AssetFactory {
|
||||
#assetExif?: AssetExifFactory;
|
||||
#files: AssetFileFactory[] = [];
|
||||
#edits: AssetEditFactory[] = [];
|
||||
#faces: Selectable<AssetFaceTable>[] = [];
|
||||
#faces: AssetFaceFactory[] = [];
|
||||
#stack?: Selectable<StackTable> & { assets: Selectable<AssetTable>[]; primaryAsset: Selectable<AssetTable> };
|
||||
|
||||
private constructor(private readonly value: Selectable<AssetTable>) {
|
||||
value.ownerId ??= newUuid();
|
||||
@@ -83,8 +95,8 @@ export class AssetFactory {
|
||||
return this;
|
||||
}
|
||||
|
||||
face(dto: Selectable<AssetFaceTable>) {
|
||||
this.#faces.push(dto);
|
||||
face(dto: AssetFaceLike = {}, builder?: FactoryBuilder<AssetFaceFactory>) {
|
||||
this.#faces.push(build(AssetFaceFactory.from(dto), builder));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -117,6 +129,12 @@ export class AssetFactory {
|
||||
return this;
|
||||
}
|
||||
|
||||
stack(dto: StackLike = {}, builder?: FactoryBuilder<StackFactory>) {
|
||||
this.#stack = build(StackFactory.from(dto).primaryAsset(this.value), builder).build();
|
||||
this.value.stackId = this.#stack.id;
|
||||
return this;
|
||||
}
|
||||
|
||||
build() {
|
||||
const exif = this.#assetExif?.build();
|
||||
|
||||
@@ -126,8 +144,9 @@ export class AssetFactory {
|
||||
exifInfo: exif as NonNullable<typeof exif>,
|
||||
files: this.#files.map((file) => file.build()),
|
||||
edits: this.#edits.map((edit) => edit.build()),
|
||||
faces: this.#faces,
|
||||
stack: null,
|
||||
faces: this.#faces.map((face) => face.build()),
|
||||
stack: this.#stack ?? null,
|
||||
tags: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
34
server/test/factories/person.factory.ts
Normal file
34
server/test/factories/person.factory.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Selectable } from 'kysely';
|
||||
import { PersonTable } from 'src/schema/tables/person.table';
|
||||
import { PersonLike } from 'test/factories/types';
|
||||
import { newDate, newUuid, newUuidV7 } from 'test/small.factory';
|
||||
|
||||
export class PersonFactory {
|
||||
private constructor(private readonly value: Selectable<PersonTable>) {}
|
||||
|
||||
static create(dto: PersonLike = {}) {
|
||||
return PersonFactory.from(dto).build();
|
||||
}
|
||||
|
||||
static from(dto: PersonLike = {}) {
|
||||
return new PersonFactory({
|
||||
birthDate: null,
|
||||
color: null,
|
||||
createdAt: newDate(),
|
||||
faceAssetId: null,
|
||||
id: newUuid(),
|
||||
isFavorite: false,
|
||||
isHidden: false,
|
||||
name: 'person',
|
||||
ownerId: newUuid(),
|
||||
thumbnailPath: '/data/thumbs/person-thumbnail.jpg',
|
||||
updatedAt: newDate(),
|
||||
updateId: newUuidV7(),
|
||||
...dto,
|
||||
});
|
||||
}
|
||||
|
||||
build() {
|
||||
return { ...this.value };
|
||||
}
|
||||
}
|
||||
52
server/test/factories/stack.factory.ts
Normal file
52
server/test/factories/stack.factory.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { Selectable } from 'kysely';
|
||||
import { StackTable } from 'src/schema/tables/stack.table';
|
||||
import { AssetFactory } from 'test/factories/asset.factory';
|
||||
import { build } from 'test/factories/builder.factory';
|
||||
import { AssetLike, FactoryBuilder, StackLike } from 'test/factories/types';
|
||||
import { newDate, newUuid, newUuidV7 } from 'test/small.factory';
|
||||
|
||||
export class StackFactory {
|
||||
#assets: AssetFactory[] = [];
|
||||
#primaryAsset: AssetFactory;
|
||||
|
||||
private constructor(private readonly value: Selectable<StackTable>) {
|
||||
this.#primaryAsset = AssetFactory.from();
|
||||
this.value.primaryAssetId = this.#primaryAsset.build().id;
|
||||
}
|
||||
|
||||
static create(dto: StackLike = {}) {
|
||||
return StackFactory.from(dto).build();
|
||||
}
|
||||
|
||||
static from(dto: StackLike = {}) {
|
||||
return new StackFactory({
|
||||
createdAt: newDate(),
|
||||
id: newUuid(),
|
||||
ownerId: newUuid(),
|
||||
primaryAssetId: newUuid(),
|
||||
updatedAt: newDate(),
|
||||
updateId: newUuidV7(),
|
||||
...dto,
|
||||
});
|
||||
}
|
||||
|
||||
asset(dto: AssetLike = {}, builder?: FactoryBuilder<AssetFactory>) {
|
||||
this.#assets.push(build(AssetFactory.from(dto), builder));
|
||||
return this;
|
||||
}
|
||||
|
||||
primaryAsset(dto: AssetLike = {}, builder?: FactoryBuilder<AssetFactory>) {
|
||||
this.#primaryAsset = build(AssetFactory.from(dto), builder);
|
||||
this.value.primaryAssetId = this.#primaryAsset.build().id;
|
||||
this.#assets.push(this.#primaryAsset);
|
||||
return this;
|
||||
}
|
||||
|
||||
build() {
|
||||
return {
|
||||
...this.value,
|
||||
assets: this.#assets.map((asset) => asset.build()),
|
||||
primaryAsset: this.#primaryAsset.build(),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,12 @@ import { AlbumUserTable } from 'src/schema/tables/album-user.table';
|
||||
import { AlbumTable } from 'src/schema/tables/album.table';
|
||||
import { AssetEditTable } from 'src/schema/tables/asset-edit.table';
|
||||
import { AssetExifTable } from 'src/schema/tables/asset-exif.table';
|
||||
import { AssetFaceTable } from 'src/schema/tables/asset-face.table';
|
||||
import { AssetFileTable } from 'src/schema/tables/asset-file.table';
|
||||
import { AssetTable } from 'src/schema/tables/asset.table';
|
||||
import { PersonTable } from 'src/schema/tables/person.table';
|
||||
import { SharedLinkTable } from 'src/schema/tables/shared-link.table';
|
||||
import { StackTable } from 'src/schema/tables/stack.table';
|
||||
import { UserTable } from 'src/schema/tables/user.table';
|
||||
|
||||
export type FactoryBuilder<T, R extends T = T> = (builder: T) => R;
|
||||
@@ -18,3 +21,6 @@ export type AlbumLike = Partial<Selectable<AlbumTable>>;
|
||||
export type AlbumUserLike = Partial<Selectable<AlbumUserTable>>;
|
||||
export type SharedLinkLike = Partial<Selectable<SharedLinkTable>>;
|
||||
export type UserLike = Partial<Selectable<UserTable>>;
|
||||
export type AssetFaceLike = Partial<Selectable<AssetFaceTable>>;
|
||||
export type PersonLike = Partial<Selectable<PersonTable>>;
|
||||
export type StackLike = Partial<Selectable<StackTable>>;
|
||||
|
||||
Reference in New Issue
Block a user