Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
import { describe, expect, it } from 'vitest';
import { mapQueueItemDetailDTO, mapQueueItemDTO, mapQueueItemIdsDTO, mapQueueStatusDTO } from './mappers';
describe('queue transport mappers', () => {
it('maps a backend queue item into the live read model', () => {
expect(
mapQueueItemDTO({
batch_id: 'batch-1',
completed_at: '2026-07-18T01:00:00Z',
created_at: '2026-07-18T00:00:00Z',
destination: 'gallery',
device: 'cuda:1',
error_message: null,
error_traceback: null,
error_type: null,
field_values: [
{ field_name: 'seed', node_path: 'noise', value: 42 },
{ field_name: 'image', node_path: 'input', value: { image_name: 'input.png' } },
],
item_id: 7,
origin: 'webv2:item-1',
retried_from_item_id: 3,
session: {
results: {
collection: { collection: [{ image_name: 'first.png' }, { image_name: 'second.png' }] },
image: { image: { image_name: 'single.png' } },
},
},
session_id: 'session-1',
started_at: '2026-07-18T00:30:00Z',
status: 'completed',
updated_at: '2026-07-18T01:00:00Z',
user_display_name: 'Ada',
user_email: '[email protected]',
user_id: 'user-1',
workflow: { name: 'Portrait upscale', nodes: [] },
})
).toEqual({
batchId: 'batch-1',
completedAt: '2026-07-18T01:00:00Z',
createdAt: '2026-07-18T00:00:00Z',
destination: 'gallery',
device: 'cuda:1',
errorMessage: null,
errorTraceback: null,
errorType: null,
fieldValues: [
{ fieldName: 'seed', nodePath: 'noise', value: 42 },
{ fieldName: 'image', nodePath: 'input', value: { imageName: 'input.png' } },
],
id: 7,
origin: 'webv2:item-1',
resultImageNames: ['first.png', 'second.png', 'single.png'],
retriedFromItemId: 3,
sessionId: 'session-1',
startedAt: '2026-07-18T00:30:00Z',
status: 'completed',
updatedAt: '2026-07-18T01:00:00Z',
userDisplayName: 'Ada',
userEmail: '[email protected]',
userId: 'user-1',
workflowName: 'Portrait upscale',
});
});
it('preserves absent nullable fields without exposing the raw session', () => {
const item = mapQueueItemDTO({
batch_id: 'batch-2',
created_at: '2026-07-18T00:00:00Z',
item_id: 8,
session_id: 'session-2',
status: 'pending',
updated_at: '2026-07-18T00:00:00Z',
});
expect(item.fieldValues).toBeUndefined();
expect(item.resultImageNames).toEqual([]);
expect(item).not.toHaveProperty('session');
});
it('reads naive server timestamps as UTC, keeping null and ISO values', () => {
const item = mapQueueItemDTO({
batch_id: 'batch-3',
completed_at: '2026-10-19 08:05:30.5',
created_at: '2026-10-19 08:00:00.123',
item_id: 9,
session_id: 'session-3',
started_at: null,
status: 'completed',
updated_at: '2026-10-19T08:05:30.500Z',
});
expect(item.createdAt).toBe('2026-10-19T08:00:00.123Z');
expect(item.completedAt).toBe('2026-10-19T08:05:30.500Z');
expect(item.startedAt).toBeNull();
expect(item.updatedAt).toBe('2026-10-19T08:05:30.500Z');
});
it('maps status and id-list response names at the adapter boundary', () => {
expect(mapQueueItemIdsDTO({ item_ids: [9, 8] })).toEqual({ itemIds: [9, 8] });
expect(
mapQueueStatusDTO({
processor: { is_processing: true, is_started: true },
queue: {
batch_id: 'batch-1',
canceled: 1,
completed: 2,
failed: 3,
in_progress: 4,
item_id: 7,
pending: 5,
queue_id: 'default',
session_id: 'session-1',
total: 15,
user_in_progress: 1,
user_pending: 2,
waiting: 0,
},
})
).toEqual({
processor: { isProcessing: true, isStarted: true },
queue: {
batchId: 'batch-1',
canceled: 1,
completed: 2,
failed: 3,
inProgress: 4,
itemId: 7,
pending: 5,
queueId: 'default',
sessionId: 'session-1',
total: 15,
userInProgress: 1,
userPending: 2,
waiting: 0,
},
});
});
it('maps the saved execution data of an item separately from the live row', () => {
const graph = { edges: [], id: 'graph-1', nodes: { noise: { id: 'noise', type: 'noise' } } };
const results = { noise: { noise: { image_name: 'noise.png' } } };
const workflow = { name: 'Portrait', nodes: [] };
expect(
mapQueueItemDetailDTO({
batch_id: 'batch-1',
created_at: '2026-07-18T00:00:00Z',
error_message: 'boom',
error_traceback: 'Traceback…',
error_type: 'RuntimeError',
item_id: 7,
priority: 1,
session: { graph, results },
session_id: 'session-1',
status: 'failed',
updated_at: '2026-07-18T01:00:00Z',
workflow,
})
).toEqual({
errorMessage: 'boom',
errorTraceback: 'Traceback…',
errorType: 'RuntimeError',
graph,
id: 7,
priority: 1,
results,
sessionId: 'session-1',
status: 'failed',
workflow,
});
});
it('reads an empty detail for a redacted or still-pending item', () => {
expect(
mapQueueItemDetailDTO({
batch_id: 'redacted',
created_at: '2026-07-18T00:00:00Z',
item_id: 8,
session_id: 'redacted',
status: 'pending',
updated_at: '2026-07-18T00:00:00Z',
})
).toEqual({
errorMessage: null,
errorTraceback: null,
errorType: null,
graph: {},
id: 8,
priority: null,
results: {},
sessionId: 'redacted',
status: 'pending',
workflow: null,
});
});
it('keeps the workflow-call parent on the live row so child items can hide retry', () => {
expect(
mapQueueItemDTO({
batch_id: 'batch-1',
created_at: '2026-07-18T00:00:00Z',
item_id: 9,
parent_item_id: 7,
session_id: 'session-9',
status: 'failed',
updated_at: '2026-07-18T00:00:00Z',
}).parentItemId
).toBe(7);
});
});