import { ManifestValidationError } from '../errors/ManifestValidationError'; import { JobManifestV1 } from '../../job/manifest/JobManifestV1'; import { JobManifestModel } from '../ManifestModel'; import { getAndAssertJobManifestVersion } from './getAndAssertJobManifestVersion'; describe('getAndAssertManifestVersion', () => { it("should throw an error if Manifest object hasn't defined a $schema", () => { expect(() => getAndAssertJobManifestVersion({ $schema: '', mainFunction: 'main', name: 'test', version: '1.0.0', concurrency: 10, timeout: 10000, displayName: 'something', description: 'some-description', functions: [ { entry: 'entry', input: {}, name: 'main', output: { responseType: 'html', }, }, ], }), ).toThrowError( new ManifestValidationError( 'Could not determine manifest version. Your manifest must have a $schema property defined.', ), ); expect(() => getAndAssertJobManifestVersion({ mainFunction: 'main', name: 'test', version: '1.0.0', displayName: 'something', concurrency: 10, timeout: 10000, description: 'some-description', functions: [ { entry: 'entry', input: {}, name: 'main', output: { responseType: 'html', }, }, ], } as unknown as JobManifestModel), ).toThrowError( new ManifestValidationError( 'Could not determine manifest version. Your manifest must have a $schema property defined.', ), ); }); it('should throw an error if Manifest object has invalid $schema version', () => { expect(() => getAndAssertJobManifestVersion({ $schema: 'something-invalid', mainFunction: 'main', name: 'test', version: '1.0.0', concurrency: 10, timeout: 10000, displayName: 'something', description: 'some-description', functions: [ { entry: 'entry', input: {}, name: 'main', output: { responseType: 'html', }, }, ], }), ).toThrowError(new ManifestValidationError('Could not determine manifest version from $schema value.')); }); it("should throw an error if Manifest isn't a valid/defined version", () => { expect(() => getAndAssertJobManifestVersion( { $schema: 'http://../schemas/JobV2.json', mainFunction: 'main', name: 'test', version: '1.0.0', concurrency: 10, timeout: 10000, displayName: 'something', description: 'some-description', functions: [ { entry: 'entry', input: {}, name: 'main', output: { responseType: 'html', }, }, ], }, JobManifestV1.getJobSchemaVersionRegex(), ), ).toThrowError( new ManifestValidationError(`manifest version "JobV2" isn't a valid version. Valid versions are "JobV1"`), ); }); it('should return the schema version number if its valid and exists', () => { expect( getAndAssertJobManifestVersion( { $schema: 'http://../schemas/JobV1.json', mainFunction: 'main', name: 'test', version: '1.0.0', displayName: 'something', description: 'some-description', concurrency: 10, timeout: 10000, functions: [ { entry: 'entry', input: {}, name: 'main', output: { responseType: 'html', }, }, ], }, JobManifestV1.getJobSchemaVersionRegex(), ), ).toEqual('JobV1'); }); });