From d17f49cac8bee294b098acb93b72e998aafd3216 Mon Sep 17 00:00:00 2001 From: Daniel Vainshtein Date: Thu, 26 Sep 2024 10:32:31 +0300 Subject: [PATCH] added invalid runtime error and test --- src/services/__tests__/mondaycoderc-schema.test.ts | 5 +++++ src/services/schemas/mondaycoderc-schema.ts | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/services/__tests__/mondaycoderc-schema.test.ts b/src/services/__tests__/mondaycoderc-schema.test.ts index 8a0e25f..f04ab51 100644 --- a/src/services/__tests__/mondaycoderc-schema.test.ts +++ b/src/services/__tests__/mondaycoderc-schema.test.ts @@ -30,4 +30,9 @@ describe('mondaycodercSchema Validation', () => { const data = { RUNTIME: 'Go', RUNTIME_VERSION: '2.0.0' }; expect(() => mondaycodercSchema.parse(data)).toThrow('Invalid RUNTIME_VERSION for the specified RUNTIME'); }); + + it('should invalidate an Unsupported Runtime', () => { + const data = { RUNTIME: 'Invalid', RUNTIME_VERSION: '1.0.0' }; + expect(() => mondaycodercSchema.parse(data)).toThrow('Invalid Runtime'); + }); }); diff --git a/src/services/schemas/mondaycoderc-schema.ts b/src/services/schemas/mondaycoderc-schema.ts index eeed94f..480d38d 100644 --- a/src/services/schemas/mondaycoderc-schema.ts +++ b/src/services/schemas/mondaycoderc-schema.ts @@ -2,7 +2,13 @@ import { z } from 'zod'; export const mondaycodercSchema = z .object({ - RUNTIME: z.enum(['Python', 'Java', 'Go', 'PHP', 'Ruby', 'Nodejs', 'NETCore']).optional(), + RUNTIME: z + .enum(['Python', 'Java', 'Go', 'PHP', 'Ruby', 'Nodejs', 'NETCore'], { + errorMap: () => ({ + message: 'Invalid Runtime. Supported runtimes are Python, Java, Go, PHP, Ruby, Nodejs, NETCore', + }), + }) + .optional(), RUNTIME_VERSION: z.string().optional(), }) .refine( @@ -36,8 +42,6 @@ export const mondaycodercSchema = z return /^(6|7)\.\d+$/.test(data.RUNTIME_VERSION || ''); } } - - return true; }, { message: 'Invalid RUNTIME_VERSION for the specified RUNTIME',