fix: assetTagFilter any matching (#32027)

fix: assetTagFilter any matching (#32008)

(cherry picked from commit 28e375c0585f8ee69f80257dc0be073a2b114cdf)

Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>
This commit is contained in:
immich-push-o-matic[bot]
2026-10-02 15:50:49 +00:00
committed by GitHub
co-authored by Daniel Dietzler
parent 643e606a5b
commit 6e5a4fdf00
2 changed files with 123 additions and 2 deletions
@@ -21,6 +21,7 @@ import { WorkflowExecutionService } from 'src/services/workflow-execution.servic
import { resolveMethod } from 'src/utils/workflow.js';
import { MediumTestContext } from 'test/medium.factory.js';
import { mockEnvData } from 'test/repositories/config.repository.mock.js';
import { newUuid } from 'test/small.factory.js';
import { getKyselyDB } from 'test/utils.js';
let isInitialized = false;
@@ -602,6 +603,126 @@ describe('core plugin', () => {
});
});
describe('assetTagFilter', () => {
it('should favorite asset if it matches any tag', async () => {
const { user } = await ctx.newUser();
const { asset } = await ctx.newAsset({ ownerId: user.id });
const { tag } = await ctx.newTag({ userId: user.id, value: 'foo' });
await ctx.newTagAsset({ tagIds: [tag.id], assetIds: [asset.id] });
const workflow = await createWorkflow({
ownerId: user.id,
trigger: WorkflowTrigger.AssetCreate,
steps: [
{
method: 'immich-plugin-core#assetTagFilter',
config: { matching: 'any', tags: [tag.id, newUuid()] },
},
{
method: 'immich-plugin-core#assetFavorite',
},
],
});
await expect(ctx.sut.handleAssetTrigger({ workflowId: workflow.id, assetId: asset.id })).resolves.toBeUndefined();
await expect(ctx.get(AssetRepository).getById(asset.id)).resolves.toMatchObject({ isFavorite: true });
});
it('should not favorite asset if it has no tags with any filter', async () => {
const { user } = await ctx.newUser();
const { asset } = await ctx.newAsset({ ownerId: user.id });
const { tag } = await ctx.newTag({ userId: user.id, value: 'foo' });
const workflow = await createWorkflow({
ownerId: user.id,
trigger: WorkflowTrigger.AssetCreate,
steps: [
{
method: 'immich-plugin-core#assetTagFilter',
config: { matching: 'any', tags: [tag.id, newUuid()] },
},
{
method: 'immich-plugin-core#assetFavorite',
},
],
});
await expect(ctx.sut.handleAssetTrigger({ workflowId: workflow.id, assetId: asset.id })).resolves.toBeUndefined();
await expect(ctx.get(AssetRepository).getById(asset.id)).resolves.toMatchObject({ isFavorite: false });
});
it('should favorite asset if it matches all tags', async () => {
const { user } = await ctx.newUser();
const { asset } = await ctx.newAsset({ ownerId: user.id });
const { tag } = await ctx.newTag({ userId: user.id, value: 'foo' });
await ctx.newTagAsset({ tagIds: [tag.id], assetIds: [asset.id] });
const workflow = await createWorkflow({
ownerId: user.id,
trigger: WorkflowTrigger.AssetCreate,
steps: [
{
method: 'immich-plugin-core#assetTagFilter',
config: { matching: 'all', tags: [tag.id] },
},
{
method: 'immich-plugin-core#assetFavorite',
},
],
});
await expect(ctx.sut.handleAssetTrigger({ workflowId: workflow.id, assetId: asset.id })).resolves.toBeUndefined();
await expect(ctx.get(AssetRepository).getById(asset.id)).resolves.toMatchObject({ isFavorite: true });
});
it('should not favorite asset if it has no tags with all filter', async () => {
const { user } = await ctx.newUser();
const { asset } = await ctx.newAsset({ ownerId: user.id });
const { tag } = await ctx.newTag({ userId: user.id, value: 'foo' });
const workflow = await createWorkflow({
ownerId: user.id,
trigger: WorkflowTrigger.AssetCreate,
steps: [
{
method: 'immich-plugin-core#assetTagFilter',
config: { matching: 'all', tags: [tag.id, newUuid()] },
},
{
method: 'immich-plugin-core#assetFavorite',
},
],
});
await expect(ctx.sut.handleAssetTrigger({ workflowId: workflow.id, assetId: asset.id })).resolves.toBeUndefined();
await expect(ctx.get(AssetRepository).getById(asset.id)).resolves.toMatchObject({ isFavorite: false });
});
it('should favorite asset if it has none of the tags', async () => {
const { user } = await ctx.newUser();
const { asset } = await ctx.newAsset({ ownerId: user.id });
const { tag } = await ctx.newTag({ userId: user.id, value: 'foo' });
await ctx.newTagAsset({ tagIds: [tag.id], assetIds: [asset.id] });
const workflow = await createWorkflow({
ownerId: user.id,
trigger: WorkflowTrigger.AssetCreate,
steps: [
{
method: 'immich-plugin-core#assetTagFilter',
config: { matching: 'none', tags: [newUuid()] },
},
{
method: 'immich-plugin-core#assetFavorite',
},
],
});
await expect(ctx.sut.handleAssetTrigger({ workflowId: workflow.id, assetId: asset.id })).resolves.toBeUndefined();
await expect(ctx.get(AssetRepository).getById(asset.id)).resolves.toMatchObject({ isFavorite: true });
});
});
describe('webhook', () => {
it('should trigger a webhook on asset upload', async () => {
const { user } = await ctx.newUser();