feat(schema): allow single-entry wheels

This commit is contained in:
tiennm99 committed 2026-08-06 11:43:10 +07:00
1 parent 795d56e120
commit 529da3621d
4 files changed
+13 -3

No files matched your search

+1 -1
View File
@@ -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(),
+1 -1
View File
@@ -56,7 +56,7 @@ describe('POST /api/gif', () => {
method: 'POST',
url: '/api/gif',
payload: {
options: ['only one'],
options: [],
},
});
+1 -1
View File
@@ -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');
+10
View File
@@ -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);