|
1 | 1 | import test from 'ava'; |
2 | 2 | import { rm, mkdir } from 'node:fs/promises'; |
3 | 3 | import path from 'node:path'; |
| 4 | + |
| 5 | +import createLightningServer from '@openfn/lightning-mock'; |
| 6 | + |
4 | 7 | import run from '../src/run'; |
5 | 8 | import { getJSON } from '../src/util'; |
6 | 9 |
|
| 10 | +// set up a lightning mock |
| 11 | +let server: any; |
| 12 | + |
| 13 | +const port = 8968; |
| 14 | + |
| 15 | +test.before(async () => { |
| 16 | + server = await createLightningServer({ port }); |
| 17 | + server.collections.createCollection('stuff'); |
| 18 | + // Important: the collection value MUST be as string |
| 19 | + server.collections.upsert('stuff', 'x', JSON.stringify({ id: 'x' })); |
| 20 | +}); |
| 21 | + |
7 | 22 | const jobsPath = path.resolve('test/fixtures'); |
8 | 23 |
|
9 | 24 | // Note that these tests are STATEFUL |
@@ -147,6 +162,17 @@ test.serial( |
147 | 162 | } |
148 | 163 | ); |
149 | 164 |
|
| 165 | +test.serial( |
| 166 | + `openfn ${jobsPath}/wf-creds.json --credentials ${jobsPath}/creds.json`, |
| 167 | + async (t) => { |
| 168 | + const { err, stdout, stderr } = await run(t.title); |
| 169 | + t.falsy(err); |
| 170 | + |
| 171 | + const out = getJSON(); |
| 172 | + t.is(out.value, 'admin:admin'); |
| 173 | + } |
| 174 | +); |
| 175 | + |
150 | 176 | test.serial( |
151 | 177 | `openfn ${jobsPath}/wf-errors.json -S "{ \\"data\\": { \\"number\\": 2 } }"`, |
152 | 178 | async (t) => { |
@@ -273,3 +299,16 @@ test.serial( |
273 | 299 | }); |
274 | 300 | } |
275 | 301 | ); |
| 302 | + |
| 303 | +// collections basic test |
| 304 | +test.serial( |
| 305 | + `openfn ${jobsPath}/collections.json --endpoint http://localhost:${port} --api-key xyz`, |
| 306 | + async (t) => { |
| 307 | + const { err } = await run(t.title); |
| 308 | + t.falsy(err); |
| 309 | + |
| 310 | + const out = getJSON(); |
| 311 | + |
| 312 | + t.deepEqual(out.data, { id: 'x' }); |
| 313 | + } |
| 314 | +); |
0 commit comments