Upgrade OFF lookup UX and stock detail identifier editing
This commit is contained in:
@@ -15,7 +15,10 @@ vi.mock('../../src/api/client.js', () => ({
|
||||
|
||||
const {
|
||||
applyItemUpsert,
|
||||
lookupItemByIdentifier,
|
||||
lookupItemDetails,
|
||||
listKitchenChanges,
|
||||
patchStockItem,
|
||||
previewItemUpsert,
|
||||
useStockItem,
|
||||
} = await import('../../src/api/stock.js');
|
||||
@@ -112,6 +115,101 @@ describe('api/stock', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('lookupItemByIdentifier normalizes lookup metadata fields', async () => {
|
||||
apiRequestMock.mockResolvedValueOnce({
|
||||
status: 'rate_limited',
|
||||
source: 'openfoodfacts',
|
||||
cache_hit: true,
|
||||
identifier_code: '1234',
|
||||
identifier_type: 'ean_13',
|
||||
retry_after_seconds: 42,
|
||||
payload_fetched_at: '2026-04-11T08:00:00Z',
|
||||
stale_cache: true,
|
||||
item: null,
|
||||
});
|
||||
|
||||
const response = await lookupItemByIdentifier(
|
||||
{ config: { database: 'db' } },
|
||||
'1234',
|
||||
);
|
||||
|
||||
expect(response).toEqual({
|
||||
status: 'rate_limited',
|
||||
source: 'openfoodfacts',
|
||||
cacheHit: true,
|
||||
identifierCode: '1234',
|
||||
identifierType: 'ean_13',
|
||||
retryAfterSeconds: 42,
|
||||
payloadFetchedAt: '2026-04-11T08:00:00Z',
|
||||
staleCache: true,
|
||||
item: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('lookupItemDetails maps item lookup response and query flag', async () => {
|
||||
apiRequestMock.mockResolvedValueOnce({
|
||||
status: 'ok',
|
||||
found: true,
|
||||
update: true,
|
||||
identifier_code: '555',
|
||||
identifier_type: 'ean_13',
|
||||
preview: { name: 'Milk' },
|
||||
updated_fields: ['name'],
|
||||
off_payload_fetched_at: '2026-04-11T09:00:00Z',
|
||||
retry_after_seconds: null,
|
||||
stale_cache: false,
|
||||
item: { uuid_b64: 'item-1', name: 'Milk' },
|
||||
});
|
||||
|
||||
const response = await lookupItemDetails(
|
||||
{ config: { database: 'db' } },
|
||||
'item-1',
|
||||
{ update: true },
|
||||
);
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||
{ config: { database: 'db' } },
|
||||
'kitchen/items/item-1/lookup',
|
||||
{ method: 'POST', query: { update: 1 } },
|
||||
);
|
||||
expect(response).toEqual({
|
||||
status: 'ok',
|
||||
found: true,
|
||||
update: true,
|
||||
identifierCode: '555',
|
||||
identifierType: 'ean_13',
|
||||
preview: { name: 'Milk' },
|
||||
updatedFields: ['name'],
|
||||
offPayloadFetchedAt: '2026-04-11T09:00:00Z',
|
||||
retryAfterSeconds: null,
|
||||
staleCache: false,
|
||||
item: { uuid_b64: 'item-1', name: 'Milk' },
|
||||
});
|
||||
});
|
||||
|
||||
it('patchStockItem sends PATCH to item endpoint', async () => {
|
||||
apiRequestMock.mockResolvedValueOnce({
|
||||
uuid_b64: 'item-1',
|
||||
identifier_code: '3830012345678',
|
||||
});
|
||||
|
||||
const response = await patchStockItem(
|
||||
{ config: { database: 'db' } },
|
||||
'item-1',
|
||||
{ identifier_code: '3830012345678' },
|
||||
);
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||
{ config: { database: 'db' } },
|
||||
'kitchen/items/item-1',
|
||||
{ method: 'PATCH', body: { identifier_code: '3830012345678' } },
|
||||
);
|
||||
expect(response).toEqual({
|
||||
uuid_b64: 'item-1',
|
||||
identifier_code: '3830012345678',
|
||||
});
|
||||
});
|
||||
|
||||
it('useStockItem returns used on 204', async () => {
|
||||
apiRequestMock.mockResolvedValueOnce(null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user