chore(server): test assetFileFilter (#30430)

This commit is contained in:
Ben Beckford 2026-08-03 02:55:40 -07:00 committed by GitHub
parent b3718fd18a
commit fb4a08c17a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -406,6 +406,101 @@ describe('core plugin', () => {
});
});
describe('assetFileFilter', () => {
it('should match assets case-insensitively', async () => {
const { user } = await ctx.newUser();
const [{ asset: asset1 }, { asset: asset2 }] = await Promise.all([
ctx.newAsset({ ownerId: user.id, originalFileName: 'exampleFile.png' }),
ctx.newAsset({ ownerId: user.id, originalFileName: 'anotherfile.jpg' }),
]);
const workflow = await createWorkflow({
ownerId: user.id,
trigger: WorkflowTrigger.AssetCreate,
steps: [
{
method: 'immich-plugin-core#assetFileFilter',
config: { matchType: 'contains', pattern: 'File' },
},
{
method: 'immich-plugin-core#assetFavorite',
},
],
});
await expect(
ctx.sut.handleAssetTrigger({ workflowId: workflow.id, assetId: asset1.id }),
).resolves.toBeUndefined();
await expect(
ctx.sut.handleAssetTrigger({ workflowId: workflow.id, assetId: asset2.id }),
).resolves.toBeUndefined();
await expect(ctx.get(AssetRepository).getById(asset1.id)).resolves.toMatchObject({ isFavorite: true });
await expect(ctx.get(AssetRepository).getById(asset2.id)).resolves.toMatchObject({ isFavorite: true });
});
it('should match assets by regex', async () => {
const { user } = await ctx.newUser();
const [{ asset: asset1 }, { asset: asset2 }] = await Promise.all([
ctx.newAsset({ ownerId: user.id, originalFileName: 'exampleFile.png' }),
ctx.newAsset({ ownerId: user.id, originalFileName: 'anotherfile.jpg' }),
]);
const workflow = await createWorkflow({
ownerId: user.id,
trigger: WorkflowTrigger.AssetCreate,
steps: [
{
method: 'immich-plugin-core#assetFileFilter',
config: { matchType: 'regex', pattern: '.+png' },
},
{
method: 'immich-plugin-core#assetFavorite',
},
],
});
await expect(
ctx.sut.handleAssetTrigger({ workflowId: workflow.id, assetId: asset1.id }),
).resolves.toBeUndefined();
await expect(
ctx.sut.handleAssetTrigger({ workflowId: workflow.id, assetId: asset2.id }),
).resolves.toBeUndefined();
await expect(ctx.get(AssetRepository).getById(asset1.id)).resolves.toMatchObject({ isFavorite: true });
await expect(ctx.get(AssetRepository).getById(asset2.id)).resolves.toMatchObject({ isFavorite: false });
});
it('should filter assets by path if specified', async () => {
const { user } = await ctx.newUser();
const [{ asset: asset1 }, { asset: asset2 }] = await Promise.all([
ctx.newAsset({ ownerId: user.id, originalPath: '/library/folder/file1.png' }),
ctx.newAsset({ ownerId: user.id, originalPath: '/library/file2.png' }),
]);
const workflow = await createWorkflow({
ownerId: user.id,
trigger: WorkflowTrigger.AssetCreate,
steps: [
{
method: 'immich-plugin-core#assetFileFilter',
config: { matchType: 'contains', pattern: 'folder', usePath: true },
},
{
method: 'immich-plugin-core#assetFavorite',
},
],
});
await expect(
ctx.sut.handleAssetTrigger({ workflowId: workflow.id, assetId: asset1.id }),
).resolves.toBeUndefined();
await expect(
ctx.sut.handleAssetTrigger({ workflowId: workflow.id, assetId: asset2.id }),
).resolves.toBeUndefined();
await expect(ctx.get(AssetRepository).getById(asset1.id)).resolves.toMatchObject({ isFavorite: true });
await expect(ctx.get(AssetRepository).getById(asset2.id)).resolves.toMatchObject({ isFavorite: false });
});
});
describe('assetTypeFilter', () => {
it('should favorite asset if it is a video', async () => {
const { user } = await ctx.newUser();