Skip to content

Commit

Permalink
Merge pull request #466 from OpenFn/464-fix-runtime-err
Browse files Browse the repository at this point in the history
464 fix runtime err
  • Loading branch information
josephjclark authored Nov 13, 2023
2 parents 0e9abd1 + c07d7d3 commit 1fb7aad
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
43 changes: 40 additions & 3 deletions integration-tests/worker/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ test('run a job with initial state (with data)', (t) => {
const result = lightning.getResult(attempt.id);
t.deepEqual(result, {
...initialState,
configuration: {},
});
done();
});
Expand Down Expand Up @@ -245,7 +244,6 @@ test('run a job with initial state (no top level keys)', (t) => {
t.deepEqual(result, {
...initialState,
data: {},
configuration: {},
});
done();
});
Expand All @@ -261,9 +259,48 @@ test('run a job with initial state (no top level keys)', (t) => {
});
});

test('run a http adaptor job', (t) => {
return new Promise(async (done) => {
const attempt = {
id: crypto.randomUUID(),
jobs: [
{
adaptor: '@openfn/[email protected]',
body: 'get("https://jsonplaceholder.typicode.com/todos/1");',
},
],
};

initLightning();

lightning.on('attempt:complete', () => {
const result = lightning.getResult(attempt.id);

t.truthy(result.response);
t.is(result.response.status, 200);
t.truthy(result.response.headers);

t.deepEqual(result.data, {
userId: 1,
id: 1,
title: 'delectus aut autem',
completed: false,
});

done();
});

await initWorker();

lightning.enqueueAttempt(attempt);
});
});

// TODO this sort of works but the server side of it does not
// Will work on it more
test('run a job with credentials', (t) => {
// TODO2: the runtime doesn't return config anymore (correctly!)
// So this test will fail. I need to get the server stuff working.
test.skip('run a job with credentials', (t) => {
// Set up a little web server to receive a request
// (there are easier ways to do this, but this is an INTEGRATION test right??)
const PORT = 4826;
Expand Down
22 changes: 22 additions & 0 deletions packages/runtime/test/execute/expression.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ test(`notify ${NOTIFY_JOB_COMPLETE}`, async (t) => {
const { state, duration, jobId } = payload;
didCallCallback = true;
t.truthy(state);
t.deepEqual(state, state);
t.assert(!isNaN(duration));
t.is(jobId, 'j');
}
Expand All @@ -108,6 +109,27 @@ test(`notify ${NOTIFY_JOB_COMPLETE}`, async (t) => {
t.true(didCallCallback);
});

test(`notify ${NOTIFY_JOB_COMPLETE} should publish serializable state`, async (t) => {
// Promises will trigger an exception if you try to serialize them
// If we don't return finalState in execute/expression, this test will fail
const resultState = { x: new Promise((r) => r), y: 22 };
const expression = [(s: State) => resultState];
const state = createState();

const notify = (event: string, payload: any) => {
if (event === NOTIFY_JOB_COMPLETE) {
const { state, duration, jobId } = payload;
t.truthy(state);
t.assert(!isNaN(duration));
t.is(jobId, 'j');
}
};

const context = createContext({ notify });

await execute(context, expression, state, 'j');
});

test('jobs can handle a promise', async (t) => {
const job = [async (s: State) => s];
const state = createState();
Expand Down

0 comments on commit 1fb7aad

Please sign in to comment.