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:
@@ -1,6 +1,72 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { formatPrintErrorMessage } from '../../src/api/labels.js';
|
||||
const apiRequestMock = vi.fn();
|
||||
|
||||
vi.mock('../../src/api/client.js', () => ({
|
||||
getPath(key) {
|
||||
const paths = {
|
||||
items: 'kitchen/items',
|
||||
};
|
||||
return paths[key];
|
||||
},
|
||||
apiRequest: (...args) => apiRequestMock(...args),
|
||||
}));
|
||||
|
||||
const {
|
||||
formatPrintErrorMessage,
|
||||
getItemLabel,
|
||||
previewLabel,
|
||||
} = await import('../../src/api/labels.js');
|
||||
|
||||
describe('api/labels', () => {
|
||||
beforeEach(() => {
|
||||
apiRequestMock.mockReset();
|
||||
});
|
||||
|
||||
it('previewLabel uses boolean label/preview query flags', async () => {
|
||||
apiRequestMock.mockResolvedValueOnce({
|
||||
label: 'YWJj',
|
||||
});
|
||||
|
||||
const response = await previewLabel({ config: { database: 'db' } }, { name: 'Rice' });
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||
{ config: { database: 'db' } },
|
||||
'kitchen/items',
|
||||
{
|
||||
method: 'POST',
|
||||
body: { name: 'Rice' },
|
||||
accept: 'image/svg+xml, image/png, application/json',
|
||||
query: { label: true, preview: true },
|
||||
},
|
||||
);
|
||||
expect(response).toEqual({
|
||||
objectUrl: 'data:image/png;base64,YWJj',
|
||||
contentType: 'image/png',
|
||||
});
|
||||
});
|
||||
|
||||
it('getItemLabel fetches PNG from /label endpoint', async () => {
|
||||
apiRequestMock.mockResolvedValueOnce({
|
||||
label: 'YWJj',
|
||||
});
|
||||
|
||||
const response = await getItemLabel({ config: { database: 'db' } }, 'item-1');
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||
{ config: { database: 'db' } },
|
||||
'kitchen/items/item-1/label',
|
||||
{
|
||||
method: 'GET',
|
||||
accept: 'image/png, application/json',
|
||||
},
|
||||
);
|
||||
expect(response).toEqual({
|
||||
objectUrl: 'data:image/png;base64,YWJj',
|
||||
contentType: 'image/png',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('api/labels formatPrintErrorMessage', () => {
|
||||
it('maps printer_unavailable payload to user-friendly message', () => {
|
||||
|
||||
Reference in New Issue
Block a user