Skip to content

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.

2.2 KB
Raw Blame
import { omit, pick } from 'es-toolkit/compat';
import { call_saved_workflow, schema, templates, workflow_return } from 'features/nodes/store/util/testUtils';
import { parseSchema } from 'features/nodes/util/schema/parseSchema';
import { describe, expect, it } from 'vitest';

const stripUndefinedDeep = <T>(value: T): T => JSON.parse(JSON.stringify(value)) as T;

describe('parseSchema', () => {
  it('should parse the schema', () => {
    const parsed = parseSchema(schema);
    expect(stripUndefinedDeep(parsed)).toEqual(stripUndefinedDeep(templates));
  });
  it('should omit denied nodes', () => {
    const parsed = parseSchema(schema, undefined, ['add']);
    expect(stripUndefinedDeep(parsed)).toEqual(stripUndefinedDeep(omit(templates, 'add')));
  });
  it('should include only allowed nodes', () => {
    const parsed = parseSchema(schema, ['add']);
    expect(stripUndefinedDeep(parsed)).toEqual(stripUndefinedDeep(pick(templates, 'add')));
  });
  it('should parse the call_saved_workflow node template', () => {
    const parsed = parseSchema(schema);
    expect(stripUndefinedDeep(parsed.call_saved_workflow)).toEqual(stripUndefinedDeep(call_saved_workflow));
    const template = parsed.call_saved_workflow;
    if (!template) {
      throw new Error('Expected call_saved_workflow template');
    }
    const workflowIdInput = template.inputs.workflow_id;
    if (!workflowIdInput) {
      throw new Error('Expected workflow_id input');
    }
    expect(workflowIdInput.type.name).toBe('SavedWorkflowField');
    expect(workflowIdInput.ui_type).toBe('SavedWorkflowField');
  });
  it('should parse the workflow_return node template', () => {
    const parsed = parseSchema(schema);
    expect(stripUndefinedDeep(parsed.workflow_return)).toEqual(stripUndefinedDeep(workflow_return));
    const template = parsed.workflow_return;
    if (!template) {
      throw new Error('Expected workflow_return template');
    }
    const collectionInput = template.inputs.collection;
    if (!collectionInput) {
      throw new Error('Expected collection input');
    }
    expect(collectionInput.type.name).toBe('CollectionField');
    expect(collectionInput.ui_type).toBe('CollectionField');
  });
});