Refactor stock API to replace numeric flags with boolean values, add getItemLabel endpoint, and update tests/documentation
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
+34
-7
@@ -20,6 +20,7 @@ const {
|
||||
listGroupedStockEntries,
|
||||
listKitchenChanges,
|
||||
listStockEntries,
|
||||
markStockGone,
|
||||
lookupItemByIdentifier,
|
||||
lookupItemDetails,
|
||||
patchStockItem,
|
||||
@@ -84,7 +85,7 @@ describe('api/stock', () => {
|
||||
|
||||
await listGroupedStockEntries(
|
||||
{ config: { database: 'db' } },
|
||||
{ expanded: 0, searchName: 'Rice', limit: 10, offset: 0 },
|
||||
{ expanded: false, searchName: 'Rice', limit: 10, offset: 0 },
|
||||
);
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||
@@ -92,7 +93,7 @@ describe('api/stock', () => {
|
||||
'kitchen/items/grouped',
|
||||
{
|
||||
query: {
|
||||
expanded: 0,
|
||||
expanded: false,
|
||||
search_name: 'Rice',
|
||||
limit: 10,
|
||||
offset: 0,
|
||||
@@ -108,7 +109,7 @@ describe('api/stock', () => {
|
||||
|
||||
const response = await listGroupedStockEntries(
|
||||
{ config: { database: 'db' } },
|
||||
{ expanded: 1, searchName: 'Rice' },
|
||||
{ expanded: true, searchName: 'Rice' },
|
||||
);
|
||||
|
||||
expect(response).toHaveLength(101);
|
||||
@@ -116,13 +117,13 @@ describe('api/stock', () => {
|
||||
1,
|
||||
{ config: { database: 'db' } },
|
||||
'kitchen/items/grouped',
|
||||
{ query: { expanded: 1, search_name: 'Rice', limit: 100, offset: 0 } },
|
||||
{ query: { expanded: true, search_name: 'Rice', limit: 100, offset: 0 } },
|
||||
);
|
||||
expect(apiRequestMock).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
{ config: { database: 'db' } },
|
||||
'kitchen/items/grouped',
|
||||
{ query: { expanded: 1, search_name: 'Rice', limit: 100, offset: 100 } },
|
||||
{ query: { expanded: true, search_name: 'Rice', limit: 100, offset: 100 } },
|
||||
);
|
||||
});
|
||||
|
||||
@@ -151,7 +152,7 @@ describe('api/stock', () => {
|
||||
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||
{ config: { database: 'db' } },
|
||||
'kitchen/items/item-2',
|
||||
{ query: { allow_inactive: 1 } },
|
||||
{ query: { allow_inactive: true } },
|
||||
);
|
||||
});
|
||||
|
||||
@@ -297,7 +298,7 @@ describe('api/stock', () => {
|
||||
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||
{ config: { database: 'db' } },
|
||||
'kitchen/items/item-1/lookup',
|
||||
{ method: 'POST', query: { update: 1 } },
|
||||
{ method: 'POST', query: { update: true } },
|
||||
);
|
||||
expect(response).toEqual({
|
||||
status: 'ok',
|
||||
@@ -426,4 +427,30 @@ describe('api/stock', () => {
|
||||
});
|
||||
expect(apiRequestMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('markStockGone uses /use endpoint for consumed reason', async () => {
|
||||
apiRequestMock.mockResolvedValueOnce(null);
|
||||
|
||||
const result = await markStockGone({ config: { database: 'db' } }, 'item-1', 'consumed');
|
||||
|
||||
expect(result).toEqual({ status: 'gone', reason: 'consumed' });
|
||||
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||
{ config: { database: 'db' } },
|
||||
'kitchen/items/item-1/use',
|
||||
{ method: 'POST' },
|
||||
);
|
||||
});
|
||||
|
||||
it('markStockGone uses /stock endpoint for non-consumed reasons', async () => {
|
||||
apiRequestMock.mockResolvedValueOnce({ status: 'OK', stock: { id: 3 } });
|
||||
|
||||
const result = await markStockGone({ config: { database: 'db' } }, 'item-1', 'spoiled');
|
||||
|
||||
expect(result).toEqual({ status: 'gone', reason: 'spoiled' });
|
||||
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||
{ config: { database: 'db' } },
|
||||
'kitchen/items/item-1/stock',
|
||||
{ method: 'POST', body: { level: 'gone', gone_reason: 'spoiled' } },
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user