-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
1 deletion.
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
28 changes: 28 additions & 0 deletions
28
packages/@n8n/api-types/src/schemas/__tests__/nodeVersion.schema.test.ts
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,28 @@ | ||
import { nodeVersionSchema } from '../nodeVersion.schema'; | ||
|
||
describe('nodeVersionSchema', () => { | ||
describe('valid versions', () => { | ||
test.each([ | ||
[1, 'single digit'], | ||
[2, 'single digit'], | ||
[1.0, 'major.minor with zero minor'], | ||
[1.2, 'major.minor'], | ||
[10.5, 'major.minor with double digits'], | ||
])('should accept %s as a valid version (%s)', (version) => { | ||
const validated = nodeVersionSchema.parse(version); | ||
expect(validated).toBe(version); | ||
}); | ||
}); | ||
|
||
describe('invalid versions', () => { | ||
test.each([ | ||
['not-a-number', 'non-number input'], | ||
['1.2.3', 'more than two parts'], | ||
['1.a', 'non-numeric characters'], | ||
['1.2.3', 'more than two parts as string'], | ||
])('should reject %s as an invalid version (%s)', (version) => { | ||
const check = () => nodeVersionSchema.parse(version); | ||
expect(check).toThrowError(); | ||
}); | ||
}); | ||
}); |
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,17 @@ | ||
import { z } from 'zod'; | ||
|
||
export const nodeVersionSchema = z | ||
.number() | ||
.min(1) | ||
.refine( | ||
(val) => { | ||
const parts = String(val).split('.'); | ||
return ( | ||
(parts.length === 1 && !isNaN(Number(parts[0]))) || | ||
(parts.length === 2 && !isNaN(Number(parts[0])) && !isNaN(Number(parts[1]))) | ||
); | ||
}, | ||
{ | ||
message: 'Invalid node version. Must be in format: major.minor', | ||
}, | ||
); |