From 60d512eb6aed8628088c114280ba47e7b7c2f3c8 Mon Sep 17 00:00:00 2001 From: Joe Clark Date: Tue, 18 Nov 2025 14:50:29 +0000 Subject: [PATCH] couple of tests on positions --- .../project/test/parse/from-app-state.test.ts | 19 ++++++++ .../test/serialize/to-app-state.test.ts | 45 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/packages/project/test/parse/from-app-state.test.ts b/packages/project/test/parse/from-app-state.test.ts index a6b776ca4..b1d0c42f1 100644 --- a/packages/project/test/parse/from-app-state.test.ts +++ b/packages/project/test/parse/from-app-state.test.ts @@ -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 @@ -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); diff --git a/packages/project/test/serialize/to-app-state.test.ts b/packages/project/test/serialize/to-app-state.test.ts index 3b0ae65a6..b3dc017b9 100644 --- a/packages/project/test/serialize/to-app-state.test.ts +++ b/packages/project/test/serialize/to-app-state.test.ts @@ -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) => {