Implement upsert label flow and use-based mark gone handling
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const applyItemUpsertMock = vi.fn();
|
||||
const previewItemUpsertMock = vi.fn();
|
||||
|
||||
vi.mock('../../../src/api/stock.js', () => ({
|
||||
applyItemUpsert: (...args) => applyItemUpsertMock(...args),
|
||||
previewItemUpsert: (...args) => previewItemUpsertMock(...args),
|
||||
searchItemDefinitions: vi.fn(async () => []),
|
||||
}));
|
||||
|
||||
vi.mock('../../../src/api/labels.js', () => ({
|
||||
previewLabel: vi.fn(async () => ({ objectUrl: 'blob:preview' })),
|
||||
}));
|
||||
|
||||
vi.mock('../../../src/api/locations.js', () => ({
|
||||
fetchLocations: vi.fn(async () => ({ flat: [], tree: [] })),
|
||||
}));
|
||||
|
||||
const { labelCreatePageData } = await import('../../../src/features/labels/label-create-page.js');
|
||||
|
||||
describe('label create upsert-first submit', () => {
|
||||
it('builds upsert payload with selected template uuid', () => {
|
||||
const store = {
|
||||
isConnected: false,
|
||||
activeKitchen: { id: 7 },
|
||||
addAlert: vi.fn(),
|
||||
};
|
||||
const data = labelCreatePageData(store);
|
||||
data.form = {
|
||||
...data.form,
|
||||
itemUuidB64: 'uuid-template-1',
|
||||
name: 'Beans',
|
||||
description: 'Dry beans',
|
||||
stockType: 'measured',
|
||||
quantity: '2',
|
||||
uom: 'kg',
|
||||
level: '',
|
||||
productionDate: '2026-04-10',
|
||||
expirationDate: '2026-08-10',
|
||||
locationId: '',
|
||||
identifierCode: '12345',
|
||||
};
|
||||
|
||||
const payload = data.buildUpsertPayload();
|
||||
|
||||
expect(payload.uuid_b64).toBe('uuid-template-1');
|
||||
expect(payload.identifier_code).toBe('12345');
|
||||
expect(payload.item.name).toBe('Beans');
|
||||
expect(payload.item.quantity_initial).toBe(2);
|
||||
});
|
||||
|
||||
it('create uses applyItemUpsert and sets operation-aware success message', async () => {
|
||||
applyItemUpsertMock.mockResolvedValueOnce({
|
||||
operation: 'update',
|
||||
item: { name: 'Rice' },
|
||||
});
|
||||
|
||||
const addAlert = vi.fn();
|
||||
const store = {
|
||||
isConnected: false,
|
||||
activeKitchen: { id: 3 },
|
||||
addAlert,
|
||||
};
|
||||
const data = labelCreatePageData(store);
|
||||
data.validateBeforeSubmit = () => true;
|
||||
data.form = {
|
||||
...data.form,
|
||||
name: 'Rice',
|
||||
stockType: 'binary',
|
||||
locationId: '',
|
||||
productionDate: '2026-04-10',
|
||||
itemUuidB64: 'uuid-rice-1',
|
||||
};
|
||||
|
||||
await data.create();
|
||||
|
||||
expect(applyItemUpsertMock).toHaveBeenCalledTimes(1);
|
||||
expect(applyItemUpsertMock.mock.calls[0][1].uuid_b64).toBe('uuid-rice-1');
|
||||
expect(data.successMessage).toBe('Rice was updated successfully.');
|
||||
expect(addAlert).toHaveBeenCalledWith({
|
||||
type: 'success',
|
||||
message: 'Rice was updated successfully.',
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user