- 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:
@@ -40,6 +40,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 = {
|
||||
@@ -60,6 +61,7 @@ describe('ReceiptImportService test matrix', () => {
|
||||
jest.clearAllMocks();
|
||||
prismaMock.receiptAlias.findMany.mockResolvedValue([]);
|
||||
prismaMock.product.findMany.mockResolvedValue([]);
|
||||
prismaMock.unitMapping.findMany.mockResolvedValue([]);
|
||||
});
|
||||
|
||||
describe('ignore patterns', () => {
|
||||
@@ -222,5 +224,37 @@ 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 as any).matchProducts(
|
||||
[{ rawName: 'MJOLK 1L', unit: 'L' }],
|
||||
77,
|
||||
);
|
||||
|
||||
expect(result[0].matchedProductId).toBe(501);
|
||||
expect(result[0].unit).toBe('st');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user