feat: add unit mapping functionality
Test Suite / test (24.15.0) (push) Has been cancelled

- Added new API path for unit mappings in `api_paths.dart`.
- Implemented `upsertUnitMapping` method in `ImportRepository` to handle unit mapping creation.
- Updated `ReceiptImportTab` to learn and save unit mappings during receipt import.
- Created DTO for unit mapping with validation in `create-unit-mapping.dto.ts`.
- Added SQL migration for `UnitMapping` table creation with necessary constraints.
This commit is contained in:
Nils-Johan Gynther
2026-05-07 10:00:42 +02:00
parent 26823fbf35
commit a68a0ca86f
35 changed files with 558 additions and 24 deletions
@@ -32,6 +32,7 @@ describe('ReceiptImportService test matrix', () => {
category: { findMany: jest.fn().mockResolvedValue([]) },
receiptAlias: { findMany: jest.fn().mockResolvedValue([]) },
product: { findMany: jest.fn().mockResolvedValue([]) },
unitMapping: { findMany: jest.fn().mockResolvedValue([]) },
};
const aiServiceMock = {
suggestCategory: jest.fn(),
@@ -44,6 +45,7 @@ describe('ReceiptImportService test matrix', () => {
jest.clearAllMocks();
prismaMock.receiptAlias.findMany.mockResolvedValue([]);
prismaMock.product.findMany.mockResolvedValue([]);
prismaMock.unitMapping.findMany.mockResolvedValue([]);
});
describe('ignore patterns', () => {
it.each([
@@ -171,6 +173,31 @@ describe('ReceiptImportService test matrix', () => {
expect(second[0].matchedProductName).toBe('Mjolk');
expect(second[0].suggestedProductId).toBeUndefined();
});
it('använder inlärd enhetsmappning vid aliasträff', async () => {
prismaMock.receiptAlias.findMany.mockResolvedValue([
{
receiptName: 'mjolk 1l',
productId: 501,
product: {
id: 501,
name: 'Mjolk user',
canonicalName: 'Mjolk user',
categoryId: 30,
categoryRef: { id: 30, name: 'Mejeri' },
},
},
]);
prismaMock.unitMapping.findMany.mockResolvedValue([
{
productId: 501,
originalUnit: 'l',
preferredUnit: 'st',
},
]);
const result = await service.matchProducts([{ rawName: 'MJOLK 1L', unit: 'L' }], 77);
expect(result[0].matchedProductId).toBe(501);
expect(result[0].unit).toBe('st');
});
});
});
//# sourceMappingURL=receipt-import.service.spec.js.map