feat: implement matchedVia tracking for receipt items and enhance user alias management
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user