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
28 changes: 28 additions & 0 deletions integration-tests/cli/test/execute-workflow.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import test from 'ava';
import { rm, mkdir } from 'node:fs/promises';
import path from 'node:path';

import createLightningServer from '@openfn/lightning-mock';

import run from '../src/run';
import { getJSON } from '../src/util';

// set up a lightning mock
let server: any;

const port = 8968;

test.before(async () => {
server = await createLightningServer({ port });
server.collections.createCollection('stuff');
// Important: the collection value MUST be as string
server.collections.upsert('stuff', 'x', JSON.stringify({ id: 'x' }));
});

const jobsPath = path.resolve('test/fixtures');

// Note that these tests are STATEFUL
Expand Down Expand Up @@ -285,3 +300,16 @@ test.serial(
});
}
);

// collections basic test
test.serial(
`openfn ${jobsPath}/collections.json --endpoint http://localhost:${port} --api-key xyz`,
async (t) => {
const { err } = await run(t.title);
t.falsy(err);

const out = getJSON();

t.deepEqual(out.data, { id: 'x' });
}
);
10 changes: 10 additions & 0 deletions integration-tests/cli/test/fixtures/collections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"workflow": {
"steps": [
{
"adaptor": "common",
"expression": "collections.get('stuff', 'x')"
}
]
}
}
2 changes: 1 addition & 1 deletion packages/lightning-mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dependencies": {
"@koa/router": "^12.0.2",
"@openfn/engine-multi": "workspace:*",
"@openfn/language-collections": "^0.6.2",
"@openfn/language-collections": "0.8.0",
"@openfn/lexicon": "workspace:^",
"@openfn/logger": "workspace:*",
"@openfn/runtime": "workspace:*",
Expand Down
4 changes: 3 additions & 1 deletion packages/lightning-mock/src/api-rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ export default (
router.get('/collections/:name/:key', (ctx) => {
const { name, key } = ctx.params;
try {
ctx.response.body = app.collections.fetch(name, key);
const result = app.collections.fetch(name, key);
ctx.body = { key: result.items[0].key, value: result.items[0].value };
} catch (e: any) {
console.log(e);
if ((e.message = 'COLLECTION_NOT_FOUND')) {
ctx.status = 404;
}
Expand Down
Loading