/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { JobManifestModel } from '../ManifestModel'; import { JobFunctionService } from './JobFunctionService'; describe('JobFunctionService', () => { const service = new JobFunctionService(); const manifestModel: JobManifestModel = { $schema: './manifest-schemas/v1.json', name: 'hello', version: '1.0.1', displayName: 'some display name', description: 'some description', timeout: 600, concurrency: 10, mainFunction: 'hello', functions: [ { entry: 'whatever.js', name: 'hello', input: { type: 'object', properties: { hello: { type: 'string' }, }, required: ['hello'], }, }, { entry: 'whatever.js', name: 'static-files', input: { type: 'object', properties: { hello: { type: 'string' }, }, required: ['hello'], }, }, { entry: 'whatever.js', name: 'hello-json', input: { type: 'object', properties: { hello: { type: 'string' }, }, required: ['hello'], }, }, ], }; describe('assertInputValidForJobFunction', () => { const jobFunc = manifestModel.functions.find((f) => f.name === 'hello'); it('should validate the input for the job function', (): void => { const input = { // required property hello: 'world', }; expect(() => service.assertInputValidForJobFunction(input, jobFunc!)).not.toThrow(); }); it("should throw an error if the input to a component function doesn't meet the schema", () => { const input = {}; expect(() => service.assertInputValidForJobFunction(input, jobFunc!)).toThrowErrorMatchingInlineSnapshot( `"failed validation: The required property \`hello\` is missing at \`#\`"`, ); }); it('should throw an error if input is undefined', () => { expect(() => service.assertInputValidForJobFunction(undefined, jobFunc!)).toThrowErrorMatchingInlineSnapshot( `"input value for hello cannot be undefined"`, ); }); }); });