-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
179 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { mondaycodercSchema } from 'services/schemas/mondaycoderc-schema'; | ||
|
||
describe('mondaycodercSchema Validation', () => { | ||
it('should validate a correct Python runtime and version', () => { | ||
const data = { RUNTIME: 'Python', RUNTIME_VERSION: '3.10.1' }; | ||
expect(() => mondaycodercSchema.parse(data)).not.toThrow(); | ||
}); | ||
|
||
it('should invalidate an incorrect Python runtime version', () => { | ||
const data = { RUNTIME: 'Python', RUNTIME_VERSION: '2.7.0' }; | ||
expect(() => mondaycodercSchema.parse(data)).toThrow('Invalid RUNTIME_VERSION'); | ||
}); | ||
|
||
it('should validate a correct Java runtime and version', () => { | ||
const data = { RUNTIME: 'Java', RUNTIME_VERSION: '17' }; | ||
expect(() => mondaycodercSchema.parse(data)).not.toThrow(); | ||
}); | ||
|
||
it('should validate a missing runtime version when runtime is specified', () => { | ||
const data = { RUNTIME: 'Java' }; | ||
expect(() => mondaycodercSchema.parse(data)).not.toThrow(); | ||
}); | ||
|
||
it('should validate when runtime is not specified', () => { | ||
const data = {}; | ||
expect(() => mondaycodercSchema.parse(data)).not.toThrow(); | ||
}); | ||
|
||
it('should invalidate an incorrect Go runtime version', () => { | ||
const data = { RUNTIME: 'Go', RUNTIME_VERSION: '2.0.0' }; | ||
expect(() => mondaycodercSchema.parse(data)).toThrow('Invalid RUNTIME_VERSION'); | ||
}); | ||
|
||
it('should invalidate an Unsupported Runtime', () => { | ||
const data = { RUNTIME: 'Invalid', RUNTIME_VERSION: '1.0.0' }; | ||
expect(() => mondaycodercSchema.parse(data)).toThrow('Invalid Runtime'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { z } from 'zod'; | ||
|
||
export const mondaycodercSchema = z | ||
.object({ | ||
RUNTIME: z | ||
.enum(['Python', 'Java', 'Go', 'PHP', 'Ruby', 'Node.js', 'NETCore'], { | ||
errorMap: () => ({ | ||
message: | ||
'Invalid Runtime in .mondaycoderc. Supported runtimes are Python, Java, Go, PHP, Ruby, Node.js, NETCore', | ||
}), | ||
}) | ||
.optional(), | ||
RUNTIME_VERSION: z.string().optional(), | ||
}) | ||
.strict() | ||
.refine(data => { | ||
if (data.RUNTIME_VERSION) { | ||
if (data.RUNTIME === 'Python') { | ||
if (!/^3\.(10|11|12)\.\d+$/.test(data.RUNTIME_VERSION || '')) { | ||
throw new Error( | ||
'Invalid RUNTIME_VERSION for Python in .mondaycoderc. Allowed versions are 3.10.x, 3.11.x, 3.12.x', | ||
); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
if (data.RUNTIME === 'Java') { | ||
if (!['11', '17', '18'].includes(data.RUNTIME_VERSION || '')) { | ||
throw new Error('Invalid RUNTIME_VERSION for Java in .mondaycoderc. Allowed versions are 11, 17, 18'); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
if (data.RUNTIME === 'Go') { | ||
if (!/^1\.\d+\.\d+$/.test(data.RUNTIME_VERSION || '')) { | ||
throw new Error('Invalid RUNTIME_VERSION for Go in .mondaycoderc. Allowed versions are 1.x.x'); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
if (data.RUNTIME === 'PHP') { | ||
if (!/^8\.(1|2)\.\d+$/.test(data.RUNTIME_VERSION || '')) { | ||
throw new Error('Invalid RUNTIME_VERSION for PHP in .mondaycoderc. Allowed versions are 8.1.x, 8.2.x'); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
if (data.RUNTIME === 'Ruby') { | ||
if (!/^3\.(1|2)\.\d+$/.test(data.RUNTIME_VERSION || '')) { | ||
throw new Error('Invalid RUNTIME_VERSION for Ruby in .mondaycoderc. Allowed versions are 3.1.x, 3.2.x'); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
if (data.RUNTIME === 'Node.js') { | ||
if (!/^(12|14|16|18|20)\.\d+\.\d+$/.test(data.RUNTIME_VERSION || '')) { | ||
throw new Error( | ||
'Invalid RUNTIME_VERSION for Node.js in .mondaycoderc. Allowed versions are 12.x.x, 14.x.x, 16.x.x, 18.x.x, 20.x.x', | ||
); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
if (data.RUNTIME === 'NETCore') { | ||
if (!/^(6|7)\.\d+$/.test(data.RUNTIME_VERSION || '')) { | ||
throw new Error('Invalid RUNTIME_VERSION for NETCore in .mondaycoderc. Allowed versions are 6.x, 7.x'); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
return true; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,12 +50,12 @@ | |
} | ||
}, | ||
"include": [ | ||
"src/**/*", | ||
"src/**/*" | ||
], | ||
"exclude": [ | ||
"test", | ||
"node_modules", | ||
"bin", | ||
"dist", | ||
"dist" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters