mirror of
https://github.com/tiennm99/tiennm99bot.git
synced 2026-10-11 03:13:46 +00:00
feat(schema): allow single-entry wheels
This commit is contained in:
1 parent
795d56e120
commit
529da3621d
4 files changed
+13
-3
No files matched your search
@@ -34,7 +34,7 @@ export const createWheelRequestSchema = (limits) =>
|
||||
.pipe(
|
||||
z
|
||||
.array(z.string().min(1).max(limits.maxOptionChars))
|
||||
.min(2)
|
||||
.min(1)
|
||||
.max(limits.maxOptions),
|
||||
),
|
||||
winnerIndex: z.number().int().nonnegative().optional(),
|
||||
|
||||
@@ -56,7 +56,7 @@ describe('POST /api/gif', () => {
|
||||
method: 'POST',
|
||||
url: '/api/gif',
|
||||
payload: {
|
||||
options: ['only one'],
|
||||
options: [],
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ describe('parseRenderLocalArgs', () => {
|
||||
});
|
||||
|
||||
test('rejects missing options and invalid integer flags', () => {
|
||||
expect(() => parseRenderLocalArgs(['--option', 'alpha'])).toThrow();
|
||||
expect(() => parseRenderLocalArgs([])).toThrow();
|
||||
expect(() =>
|
||||
parseRenderLocalArgs(['--option', 'alpha', '--option', 'beta', '--winner', '1.5']),
|
||||
).toThrow('--winner must be an integer');
|
||||
|
||||
@@ -36,6 +36,16 @@ describe('parseWheelRequest', () => {
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
test('accepts a single option', () => {
|
||||
const request = parseWheelRequest({options: ['solo']}, limits, () => 0);
|
||||
expect(request.options).toEqual(['solo']);
|
||||
expect(request.winnerIndex).toBe(0);
|
||||
});
|
||||
|
||||
test('rejects empty options', () => {
|
||||
expect(() => parseWheelRequest({options: []}, limits, () => 0)).toThrow();
|
||||
});
|
||||
|
||||
test('selects winner when omitted', () => {
|
||||
const request = parseWheelRequest({options: ['a', 'b']}, limits, () => 1);
|
||||
expect(request.winnerIndex).toBe(1);
|
||||
|
||||
Reference in new issue
Block a user