Skip to content

Commit c263183

Browse files
authored
Merge pull request #1135 from OpenFn/more-state-sync-stuff
couple of tests on positions
2 parents 361e79c + 60d512e commit c263183

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

packages/project/test/parse/from-app-state.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import test from 'ava';
22
import type { Provisioner } from '@openfn/lexicon/lightning';
33
import fromAppState, { mapWorkflow } from '../../src/parse/from-app-state';
4+
import { clone, cloneDeep } from 'lodash-es';
45

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

112+
test('should create a Project from prov state with positions', (t) => {
113+
const newState = cloneDeep(state);
114+
115+
// assign a fake positions object
116+
// the provisioner right now doesn't include positions
117+
// - but one day it will, and Project needs to be able to sync it
118+
newState.workflows[0].positions = {
119+
x: 1,
120+
y: 1,
121+
};
122+
const project = fromAppState(newState, meta);
123+
124+
t.deepEqual(project.workflows[0].openfn.positions, {
125+
x: 1,
126+
y: 1,
127+
});
128+
});
129+
111130
test('should create a Project from prov state with a workflow', (t) => {
112131
const project = fromAppState(state, meta);
113132

packages/project/test/serialize/to-app-state.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,51 @@ test('should set defaults for keys that Lightning needs', (t) => {
133133
});
134134
});
135135

136+
test('should serialize workflow positions', (t) => {
137+
const data = {
138+
id: 'my-project',
139+
workflows: [
140+
{
141+
id: 'wf',
142+
openfn: {
143+
positions: {
144+
step: {
145+
x: 1,
146+
y: 1,
147+
},
148+
},
149+
},
150+
steps: [
151+
{
152+
id: 'trigger',
153+
type: 'webhook',
154+
next: {
155+
step: {},
156+
},
157+
},
158+
{
159+
id: 'step',
160+
expression: '.',
161+
},
162+
],
163+
},
164+
],
165+
};
166+
const project = new Project(data, {
167+
formats: {
168+
project: 'json',
169+
},
170+
});
171+
172+
const state = toAppState(project);
173+
t.deepEqual(state.workflows[0].positions, {
174+
step: {
175+
x: 1,
176+
y: 1,
177+
},
178+
});
179+
});
180+
136181
// This test just ensures that whatever we write to an openfn object
137182
// gets written back to state
138183
test('should write openfn keys to objects', (t) => {

0 commit comments

Comments
 (0)