feat: implement matchedVia tracking for receipt items and enhance user alias management
Test Suite / test (24.15.0) (push) Has been cancelled

This commit is contained in:
Nils-Johan Gynther
2026-05-07 13:57:41 +02:00
parent f7446cc2df
commit d92272e554
9 changed files with 287 additions and 8 deletions
@@ -257,4 +257,41 @@ describe('ReceiptImportService test matrix', () => {
expect(result[0].unit).toBe('st');
});
});
describe('matchedVia', () => {
it('sätter matchedVia: alias vid aliasträff', async () => {
prismaMock.receiptAlias.findMany.mockResolvedValue([
{
receiptName: 'snickers',
productId: 222,
product: { id: 222, name: 'Snickers', canonicalName: 'Snickers', categoryId: null, categoryRef: null },
},
]);
prismaMock.product.findMany.mockResolvedValue([]);
const result = await (service as any).matchProducts([{ rawName: 'SNICKERS' }], 10);
expect(result[0].matchedVia).toBe('alias');
});
it('sätter matchedVia: wordmatch vid ordbaserad matchning', async () => {
prismaMock.receiptAlias.findMany.mockResolvedValue([]);
prismaMock.product.findMany.mockResolvedValue([
{ id: 300, name: 'Mjolk', canonicalName: 'Mjolk', categoryId: null, categoryRef: null },
]);
const result = await (service as any).matchProducts([{ rawName: 'MJOLK 1L' }], 10);
expect(result[0].matchedVia).toBe('wordmatch');
});
it('sätter matchedVia: none när ingen matchning finns', async () => {
prismaMock.receiptAlias.findMany.mockResolvedValue([]);
prismaMock.product.findMany.mockResolvedValue([]);
const result = await (service as any).matchProducts([{ rawName: 'XYZXYZ' }], 10);
expect(result[0].matchedVia).toBe('none');
});
});
});