diff --git a/integration-tests/worker/test/integration.test.ts b/integration-tests/worker/test/integration.test.ts index d7f787d48..e4e13afe6 100644 --- a/integration-tests/worker/test/integration.test.ts +++ b/integration-tests/worker/test/integration.test.ts @@ -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(); }); @@ -245,7 +244,6 @@ test('run a job with initial state (no top level keys)', (t) => { t.deepEqual(result, { ...initialState, data: {}, - configuration: {}, }); done(); }); @@ -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/language-http@5.0.4', + 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; diff --git a/packages/runtime/test/execute/expression.test.ts b/packages/runtime/test/execute/expression.test.ts index 2a9a02790..a282ee974 100644 --- a/packages/runtime/test/execute/expression.test.ts +++ b/packages/runtime/test/execute/expression.test.ts @@ -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'); } @@ -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();