- 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:
@@ -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
|
||||
Reference in New Issue
Block a user