pull/715/head
Travis Fischer 2025-05-26 02:47:58 +07:00
rodzic 817e726044
commit 9da4820e00
4 zmienionych plików z 119 dodań i 1 usunięć

Wyświetl plik

@ -19,7 +19,8 @@
"scripts": {
"test": "run-s test:*",
"test:lint": "eslint .",
"test:typecheck": "tsc --noEmit"
"test:typecheck": "tsc --noEmit",
"test:unit": "vitest run"
},
"dependencies": {
"@agentic/platform-core": "workspace:*",

Wyświetl plik

@ -0,0 +1,67 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`rateLimitSchema invalid 1`] = `
[ZodError: [
{
"code": "too_small",
"minimum": 1,
"type": "string",
"inclusive": true,
"exact": false,
"message": "String must contain at least 1 character(s)",
"path": [
"interval"
]
}
]]
`;
exports[`rateLimitSchema invalid 2`] = `
[ZodError: [
{
"code": "custom",
"message": "Invalid interval \\"--\\"",
"path": [
"interval",
"interval"
]
}
]]
`;
exports[`rateLimitSchema invalid 3`] = `
[ZodError: [
{
"code": "too_small",
"minimum": 0,
"type": "number",
"inclusive": true,
"exact": false,
"message": "Number must be greater than or equal to 0",
"path": [
"maxPerInterval"
]
}
]]
`;
exports[`rateLimitSchema valid 1`] = `
{
"interval": 10,
"maxPerInterval": 100,
}
`;
exports[`rateLimitSchema valid 2`] = `
{
"interval": 10,
"maxPerInterval": 100,
}
`;
exports[`rateLimitSchema valid 3`] = `
{
"interval": 86400,
"maxPerInterval": 1000,
}
`;

Wyświetl plik

@ -0,0 +1,49 @@
import { expect, test } from 'vitest'
import { rateLimitSchema } from './schemas'
test('rateLimitSchema valid', () => {
expect(
rateLimitSchema.parse({
interval: 10,
maxPerInterval: 100
})
).toMatchSnapshot()
expect(
rateLimitSchema.parse({
interval: '10s',
maxPerInterval: 100
})
).toMatchSnapshot()
expect(
rateLimitSchema.parse({
interval: '1 day',
maxPerInterval: 1000
})
).toMatchSnapshot()
})
test('rateLimitSchema invalid', () => {
expect(() =>
rateLimitSchema.parse({
interval: '',
maxPerInterval: 5
})
).toThrowErrorMatchingSnapshot()
expect(() =>
rateLimitSchema.parse({
interval: '--',
maxPerInterval: 10
})
).toThrowErrorMatchingSnapshot()
expect(() =>
rateLimitSchema.parse({
interval: '1 day',
maxPerInterval: -1000
})
).toThrowErrorMatchingSnapshot()
})

Wyświetl plik

@ -59,6 +59,7 @@ export const rateLimitSchema = z
*/
maxPerInterval: z
.number()
.nonnegative()
.describe('Maximum number of operations per interval (unitless).')
})
.openapi('RateLimit')