feat: add updateCategoryMine endpoint to manage product category updates
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
- Implemented a new PATCH endpoint in ProductsController to update the category of a user's product. - Added corresponding service method in ProductsService to handle business logic and validation. - Created UpdateCategoryMineDto for request validation. - Enhanced error handling for forbidden actions and not found resources. - Updated API error mapping in Flutter to handle specific forbidden messages. - Modified ProductPickerField to allow product creation directly from the picker. - Added tests for the new endpoint and service method to ensure proper functionality and error handling.
This commit is contained in:
@@ -10,6 +10,7 @@ describe('Products controller security', () => {
|
||||
createPending: jest.fn(),
|
||||
updateCanonicalNamePrivate: jest.fn(),
|
||||
mergePrivate: jest.fn(),
|
||||
updateCategoryMine: jest.fn(),
|
||||
};
|
||||
|
||||
const aiServiceMock = {
|
||||
@@ -107,6 +108,14 @@ describe('Products controller security', () => {
|
||||
expect(productsServiceMock.mergePrivate).toHaveBeenCalledWith(42, 10, 20);
|
||||
});
|
||||
|
||||
it('updateCategoryMine vidarebefordrar req.user.id', () => {
|
||||
productsServiceMock.updateCategoryMine.mockResolvedValue({ id: 1, categoryId: 5 });
|
||||
|
||||
controller.updateCategoryMine(1, { categoryId: 5 } as any, { user: { id: 42 } } as any);
|
||||
|
||||
expect(productsServiceMock.updateCategoryMine).toHaveBeenCalledWith(42, 1, 5);
|
||||
});
|
||||
|
||||
it('suggestCategory använder canonicalName fallback name', async () => {
|
||||
productsServiceMock.findOne.mockResolvedValue({ id: 1, name: 'Mjolk', canonicalName: 'Mjolk 1L' });
|
||||
categoriesServiceMock.findFlattened.mockResolvedValue([{ id: 1, name: 'Mejeri' }]);
|
||||
|
||||
Reference in New Issue
Block a user