mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
hierarchical tag tests
This commit is contained in:
parent
09088678ab
commit
76374dc0fe
1 changed files with 34 additions and 7 deletions
|
|
@ -1,14 +1,11 @@
|
||||||
import { Kysely } from "kysely";
|
import { Kysely } from "kysely";
|
||||||
import { JobStatus } from "src/enum";
|
import { JobStatus } from "src/enum";
|
||||||
import { AccessRepository } from "src/repositories/access.repository";
|
import { AccessRepository } from "src/repositories/access.repository";
|
||||||
import { EventRepository } from "src/repositories/event.repository";
|
|
||||||
import { LoggingRepository } from "src/repositories/logging.repository";
|
import { LoggingRepository } from "src/repositories/logging.repository";
|
||||||
import { StorageRepository } from "src/repositories/storage.repository";
|
|
||||||
import { TagRepository } from "src/repositories/tag.repository";
|
import { TagRepository } from "src/repositories/tag.repository";
|
||||||
import { DB } from "src/schema";
|
import { DB } from "src/schema";
|
||||||
import { TagService } from "src/services/tag.service";
|
import { TagService } from "src/services/tag.service";
|
||||||
import { newMediumService } from "test/medium.factory";
|
import { newMediumService } from "test/medium.factory";
|
||||||
import { factory } from "test/small.factory";
|
|
||||||
import { getKyselyDB } from "test/utils";
|
import { getKyselyDB } from "test/utils";
|
||||||
|
|
||||||
let defaultDatabase: Kysely<DB>;
|
let defaultDatabase: Kysely<DB>;
|
||||||
|
|
@ -25,10 +22,6 @@ beforeAll(async () => {
|
||||||
defaultDatabase = await getKyselyDB();
|
defaultDatabase = await getKyselyDB();
|
||||||
});
|
});
|
||||||
|
|
||||||
// single tag exists, connected to one asset, and is not deleted
|
|
||||||
// hierarchical tag exists, and the parent is connected to an asset, and the child is deleted
|
|
||||||
// hierarchical tag exists, and only the child is connected to an asset, and nothing is deleted
|
|
||||||
|
|
||||||
describe(TagService.name, () => {
|
describe(TagService.name, () => {
|
||||||
describe('deleteEmptyTags', () => {
|
describe('deleteEmptyTags', () => {
|
||||||
it('single tag exists, not connected to any assets, and is deleted', async () => {
|
it('single tag exists, not connected to any assets, and is deleted', async () => {
|
||||||
|
|
@ -56,5 +49,39 @@ describe(TagService.name, () => {
|
||||||
await expect(tagRepo.getByValue(user.id, 'tag-1')).resolves.toEqual(expect.objectContaining({ id: tag.id }));
|
await expect(tagRepo.getByValue(user.id, 'tag-1')).resolves.toEqual(expect.objectContaining({ id: tag.id }));
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('hierarchical tag exists, and the parent is connected to an asset, and the child is deleted', async () => {
|
||||||
|
const { sut, ctx } = setup();
|
||||||
|
const { user } = await ctx.newUser();
|
||||||
|
const { asset } = await ctx.newAsset({ ownerId: user.id });
|
||||||
|
const { tag: parentTag } = await ctx.newTag({ userId: user.id, value: 'parent' });
|
||||||
|
const { tag: childrenTag } = await ctx.newTag({ userId: user.id, value: 'child', parentId: parentTag.id });
|
||||||
|
const tagRepo = ctx.get(TagRepository);
|
||||||
|
|
||||||
|
await ctx.newTagAsset({ tagIds: [parentTag.id], assetIds: [asset.id] });
|
||||||
|
|
||||||
|
await expect(tagRepo.getByValue(user.id, 'parent')).resolves.toEqual(expect.objectContaining({ id: parentTag.id }));
|
||||||
|
await expect(tagRepo.getByValue(user.id, 'child')).resolves.toEqual(expect.objectContaining({ id: childrenTag.id }));
|
||||||
|
await expect(sut.handleTagCleanup()).resolves.toBe(JobStatus.Success);
|
||||||
|
await expect(tagRepo.getByValue(user.id, 'parent')).resolves.toEqual(expect.objectContaining({ id: parentTag.id }));
|
||||||
|
await expect(tagRepo.getByValue(user.id, 'child')).resolves.toBeUndefined();
|
||||||
|
})
|
||||||
|
|
||||||
|
it('hierarchical tag exists, and only the child is connected to an asset, and nothing is deleted', async () => {
|
||||||
|
const { sut, ctx } = setup();
|
||||||
|
const { user } = await ctx.newUser();
|
||||||
|
const { asset } = await ctx.newAsset({ ownerId: user.id });
|
||||||
|
const { tag: parentTag } = await ctx.newTag({ userId: user.id, value: 'parent' });
|
||||||
|
const { tag: childrenTag } = await ctx.newTag({ userId: user.id, value: 'child', parentId: parentTag.id });
|
||||||
|
const tagRepo = ctx.get(TagRepository);
|
||||||
|
|
||||||
|
await ctx.newTagAsset({ tagIds: [childrenTag.id], assetIds: [asset.id] });
|
||||||
|
|
||||||
|
await expect(tagRepo.getByValue(user.id, 'parent')).resolves.toEqual(expect.objectContaining({ id: parentTag.id }));
|
||||||
|
await expect(tagRepo.getByValue(user.id, 'child')).resolves.toEqual(expect.objectContaining({ id: childrenTag.id }));
|
||||||
|
await expect(sut.handleTagCleanup()).resolves.toBe(JobStatus.Success);
|
||||||
|
await expect(tagRepo.getByValue(user.id, 'parent')).resolves.toEqual(expect.objectContaining({ id: parentTag.id }));
|
||||||
|
await expect(tagRepo.getByValue(user.id, 'child')).resolves.toEqual(expect.objectContaining({ id: childrenTag.id }));
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Loading…
Add table
Add a link
Reference in a new issue