Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/project/test/parse/from-app-state.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import test from 'ava';
import type { Provisioner } from '@openfn/lexicon/lightning';
import fromAppState, { mapWorkflow } from '../../src/parse/from-app-state';
import { clone, cloneDeep } from 'lodash-es';

// I don't think this file really represents anything
// loosely maps to the old config file
Expand Down Expand Up @@ -108,6 +109,24 @@ test('should create a Project from prov state with credentials', (t) => {
t.deepEqual(project.credentials, []);
});

test('should create a Project from prov state with positions', (t) => {
const newState = cloneDeep(state);

// assign a fake positions object
// the provisioner right now doesn't include positions
// - but one day it will, and Project needs to be able to sync it
newState.workflows[0].positions = {
x: 1,
y: 1,
};
const project = fromAppState(newState, meta);

t.deepEqual(project.workflows[0].openfn.positions, {
x: 1,
y: 1,
});
});

test('should create a Project from prov state with a workflow', (t) => {
const project = fromAppState(state, meta);

Expand Down
45 changes: 45 additions & 0 deletions packages/project/test/serialize/to-app-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,51 @@ test('should set defaults for keys that Lightning needs', (t) => {
});
});

test('should serialize workflow positions', (t) => {
const data = {
id: 'my-project',
workflows: [
{
id: 'wf',
openfn: {
positions: {
step: {
x: 1,
y: 1,
},
},
},
steps: [
{
id: 'trigger',
type: 'webhook',
next: {
step: {},
},
},
{
id: 'step',
expression: '.',
},
],
},
],
};
const project = new Project(data, {
formats: {
project: 'json',
},
});

const state = toAppState(project);
t.deepEqual(state.workflows[0].positions, {
step: {
x: 1,
y: 1,
},
});
});

// This test just ensures that whatever we write to an openfn object
// gets written back to state
test('should write openfn keys to objects', (t) => {
Expand Down