Skip to content
Draft
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
8 changes: 8 additions & 0 deletions integration-tests/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @openfn/integration-tests-cli

## 1.0.9

### Patch Changes

- Updated dependencies [d1a0e7c]
- @openfn/project@0.11.0
- @openfn/lightning-mock@2.4.2

## 1.0.8

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@openfn/integration-tests-cli",
"private": true,
"version": "1.0.8",
"version": "1.0.9",
"description": "CLI integration tests",
"author": "Open Function Group <admin@openfn.org>",
"license": "ISC",
Expand Down
46 changes: 46 additions & 0 deletions integration-tests/cli/test/execute-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,41 @@ test.serial(
}
);

test.serial(
`openfn ${jobsPath}/wf-array.yaml -S "{ \\"data\\": { \\"items\\": [\\"z\\"] } }"`,
async (t) => {
const { err } = await run(t.title);
t.falsy(err);

const out = getJSON();
t.is(out.data.items.length, 4);
t.deepEqual(out.data.items, ['z', 'a', 'b', 'c']);
}
);

test.serial(
`openfn ${jobsPath}/wf-array-legacy.yaml -S "{ \\"data\\": { \\"items\\": [\\"z\\"] } }"`,
async (t) => {
const { stdout, err } = await run(t.title);
t.falsy(err);

const out = getJSON();
t.is(out.data.items.length, 3);
t.deepEqual(out.data.items, ['z', 'b', 'c']);
}
);

test.serial(
`openfn ${jobsPath}/wf-array-legacy.json -S "{ \\"data\\": { \\"items\\": [\\"z\\"] } }"`,
async (t) => {
const { err } = await run(t.title);
t.falsy(err);
const out = getJSON();
t.is(out.data.items.length, 3);
t.deepEqual(out.data.items, ['z', 'b', 'c']);
}
);

// special start step
test.serial(
`openfn ${jobsPath}/wf-array.json --start b -S "{ \\"data\\": { \\"items\\": [] } }"`,
Expand All @@ -96,6 +131,17 @@ test.serial(
t.true(out.data.items.includes('c'));
}
);
test.serial(
`openfn ${jobsPath}/wf-array-legacy.json --start c -S "{ \\"data\\": { \\"items\\": [] } }"`,
async (t) => {
const { err } = await run(t.title);
t.falsy(err);

const out = getJSON();
t.is(out.data.items.length, 1);
t.true(out.data.items.includes('c'));
}
);

// only step
test.serial(
Expand Down
26 changes: 26 additions & 0 deletions integration-tests/cli/test/fixtures/wf-array-legacy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"workflow": {
"steps": [
{
"id": "a",
"adaptor": "common",
"expression": "fn((state) => { if (!state.data.items) { state.data.items = []; } state.data.items.push('a'); return state; });",
"next": { "b": true }
},
{
"id": "b",
"adaptor": "common",
"expression": "fn((state) => { state.data.items.push('b'); return state; });",
"next": { "c": true }
},
{
"id": "c",
"adaptor": "common",
"expression": "fn((state) => { state.data.items.push('c'); return state; });"
}
]
},
"options": {
"start": "b"
}
}
17 changes: 17 additions & 0 deletions integration-tests/cli/test/fixtures/wf-array-legacy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
workflow:
steps:
- id: a
adaptor: common
expression: fn((state) => { if (!state.data.items) { state.data.items = []; } state.data.items.push('a'); return state; });
next:
b: true
- id: b
adaptor: common
expression: fn((state) => { state.data.items.push('b'); return state; });
next:
c: true
- id: c
adaptor: common
expression: fn((state) => { state.data.items.push('c'); return state; });
options:
start: b
40 changes: 19 additions & 21 deletions integration-tests/cli/test/fixtures/wf-array.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
{
"workflow": {
"steps": [
{
"id": "a",
"adaptor": "common",
"expression": "fn((state) => { if (!state.data.items) { state.data.items = []; } state.data.items.push('a'); return state; });",
"next": { "b": true }
},
{
"id": "b",
"adaptor": "common",
"expression": "fn((state) => { state.data.items.push('b'); return state; });",
"next": { "c": true }
},
{
"id": "c",
"adaptor": "common",
"expression": "fn((state) => { state.data.items.push('c'); return state; });"
}
]
}
"steps": [
{
"id": "a",
"adaptor": "common",
"expression": "fn((state) => { if (!state.data.items) { state.data.items = []; } state.data.items.push('a'); return state; });",
"next": { "b": true }
},
{
"id": "b",
"adaptor": "common",
"expression": "fn((state) => { state.data.items.push('b'); return state; });",
"next": { "c": true }
},
{
"id": "c",
"adaptor": "common",
"expression": "fn((state) => { state.data.items.push('c'); return state; });"
}
]
}
14 changes: 14 additions & 0 deletions integration-tests/cli/test/fixtures/wf-array.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
steps:
- id: a
adaptor: common
expression: fn((state) => { if (!state.data.items) { state.data.items = []; } state.data.items.push('a'); return state; });
next:
b: true
- id: b
adaptor: common
expression: fn((state) => { state.data.items.push('b'); return state; });
next:
c: true
- id: c
adaptor: common
expression: fn((state) => { state.data.items.push('c'); return state; });
36 changes: 27 additions & 9 deletions integration-tests/cli/test/project-v1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { rm, mkdir, writeFile, readFile } from 'node:fs/promises';
import path from 'node:path';
import run from '../src/run';

const TMP_DIR = path.resolve('tmp/project-v1');

// These tests use the legacy v1 yaml structure

const mainYaml = `
Expand Down Expand Up @@ -35,7 +37,7 @@ workflows:
jobs:
- name: Transform data
body: |
// TODO
fn(() => ({ x: 1}))
adaptor: "@openfn/language-common@latest"
id: b8b780f3-98dd-4244-880b-e534d8f24547
project_credential_id: null
Expand Down Expand Up @@ -95,16 +97,16 @@ workflows:
source_trigger_id: 7bb476cc-0292-4573-89d0-b13417bc648e
condition_type: always
`;
const projectsPath = path.resolve('tmp/project');
const projectsPath = path.resolve(TMP_DIR);

test.before(async () => {
// await rm('tmp/project', { recursive: true });
await mkdir('tmp/project/.projects', { recursive: true });
// await rm(TMP_DIR, { recursive: true });
await mkdir(`${TMP_DIR}/.projects`, { recursive: true });

await writeFile('tmp/project/openfn.yaml', '');
await writeFile('tmp/project/.projects/main@app.openfn.org.yaml', mainYaml);
await writeFile(`${TMP_DIR}/openfn.yaml`, '');
await writeFile(`${TMP_DIR}/.projects/main@app.openfn.org.yaml`, mainYaml);
await writeFile(
'tmp/project/.projects/staging@app.openfn.org.yaml',
`${TMP_DIR}/.projects/staging@app.openfn.org.yaml`,
stagingYaml
);
});
Expand All @@ -131,6 +133,7 @@ test.serial('Checkout a project', async (t) => {
workflowYaml,
`id: my-workflow
name: my workflow
start: trigger-webhook
options: {}
steps:
- id: trigger
Expand All @@ -150,7 +153,22 @@ steps:
path.resolve(projectsPath, 'workflows/my-workflow/transform-data.js'),
'utf8'
);
t.is(expr.trim(), '// TODO');
t.is(expr.trim(), 'fn(() => ({ x: 1}))');
});

// note: order of tests is important here
test.serial('execute a workflow from the checked out project', async (t) => {
// cheeky bonus test of checkout by alias
await run(`openfn checkout main -w ${projectsPath}`);

// execute a workflow
const { stdout } = await run(
`openfn my-workflow -o ${TMP_DIR}/output.json --log debug --workspace ${projectsPath}`
);

const output = await readFile(`${TMP_DIR}/output.json`, 'utf8');
const finalState = JSON.parse(output);
t.deepEqual(finalState, { x: 1 });
});

// requires the prior test to run
Expand All @@ -163,7 +181,7 @@ test.serial('merge a project', async (t) => {

// assert the initial step code
const initial = await readStep();
t.is(initial, '// TODO');
t.is(initial, 'fn(() => ({ x: 1}))');

// Run the merge
await run(`openfn merge hello-world-staging -w ${projectsPath} --force`);
Expand Down
Loading