From 4a1b2bd7a6c00b9e1704f37f5b7c582808d9e699 Mon Sep 17 00:00:00 2001 From: Dhruv Patel Date: Thu, 10 Oct 2024 15:48:02 -0600 Subject: [PATCH] test: Add test to verify runWithService --- __tests__/fake-job.test.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 __tests__/fake-job.test.ts diff --git a/__tests__/fake-job.test.ts b/__tests__/fake-job.test.ts new file mode 100644 index 0000000..0792ff4 --- /dev/null +++ b/__tests__/fake-job.test.ts @@ -0,0 +1,30 @@ +import { runWithService } from '../src/hooks'; + +describe('fake-job', () => { + test('basic job functionality', async () => { + runWithService(async (app) => { + expect(app).toBeDefined(); + expect(app.locals).toBeDefined(); + expect(app.locals.logger).toBeDefined(); + expect(app.locals.config).toBeDefined(); + + // Verify that the configuration overwrites worked + expect(app.locals.config.get('test')).toEqual('foo bar'); + + // Verify that locals work as expected + Object.assign(app.locals, { + foo: 'bar', + }); + // @ts-ignore + expect(app.locals.foo).toEqual('bar'); + + // Verify that the runId provided to service run does get applied in locals + expect(app.locals.runId).toEqual('generated-uuid-123456789'); + }, { + runId: 'generated-uuid-123456789', + overwriteConfig: (config) => { + config.set('test', 'foo bar'); + }, + }); + }); +});