import { ManifestServiceForDev } from './ManifestServiceForDev'; import { ResourceNotFoundError } from '@squiz/dx-common-lib'; import path from 'path'; import { ManifestValidationError } from '../errors/ManifestValidationError'; describe('ManifestServiceForDev', () => { const service = new ManifestServiceForDev(); describe('readJobManifest', () => { it('should read and validate a job manifest from a file path', async () => { const p = path.join(__dirname, '../../../../../..', 'test-jobs/unit-test-jobs/test-job/1.0.0/manifest.json'); const res = await service.readJobManifest(p); expect(res).toMatchInlineSnapshot(` JobManifestV1 { "manifest": { "$schema": "http://localhost:3040/schemas/JobV1.json#", "concurrency": 2, "description": "some-description", "displayName": "Test Job", "functions": [ { "entry": "main.js", "input": { "properties": { "something": { "type": "string", }, }, "required": [ "something", ], "type": "object", }, "name": "main", }, { "entry": "promise.js", "input": { "properties": { "something": { "type": "string", }, }, "required": [ "something", ], "type": "object", }, "name": "promise-func", }, ], "mainFunction": "main", "name": "test-job", "timeout": 600, "version": "1.0.0", }, "manifestPath": "${p}", } `); }); it("should throw a ResourceNotFoundError error if manifest doesn't exist", async () => { const p = path.join(__dirname, '../../../../../..', 'test-jobs/unit-test-jobs/not-real/manifest.json'); await expect(service.readJobManifest(p)).rejects.toThrowError( new ResourceNotFoundError(`manifest could not be found`), ); }); it("should error if manifest doesn't meet schema version", async () => { const p = path.join( __dirname, '../../../../../..', 'test-jobs/unit-test-jobs/invalid-schema-job/1.0.0/manifest.json', ); await expect(service.readJobManifest(p)).rejects.toThrowError( new ManifestValidationError(`Could not determine manifest version from $schema value.`), ); }); }); it('should error if manifest is invalid', async () => { const p = path.join( __dirname, '../../../../../..', 'test-jobs/unit-test-jobs/invalid-manifest-job/1.0.0/manifest.json', ); await expect(service.readJobManifest(p)).rejects.toThrowError( new ManifestValidationError('failed validation: The required property `concurrency` is missing at `#`'), ); }); });