Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/void/src/cli/gen-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ function parseRouteArgs(args: Array<string>): GenArgs {
);
}
}
methods = [...new Set(methods)];
}

// Strip leading slashes
Expand Down
12 changes: 12 additions & 0 deletions packages/void/test/unit/gen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { log, outro } from '@voidzero-dev/vite-plus-prompts';
import { toSlash } from 'pathslash';
import { describe, it, expect, afterEach, beforeEach, vi } from 'vite-plus/test';
import { packageFixturePath } from '../../../../test/fixture-dir.ts';
import { parseGenArgs } from '../../src/cli/gen-args.ts';
import type { GenArgs } from '../../src/cli/gen-args.ts';
import { runGenCommand, formatTimestamp, detectValidator } from '../../src/cli/gen.ts';
import { Buffer } from '../../src/cli/node-buffer.ts';
Expand Down Expand Up @@ -1082,6 +1083,17 @@ describe('gen route', () => {
expect(content).not.toContain('export const PATCH');
});

it('generates one handler per method in order of first occurrence', async () => {
await runGenCommand(TMP, parseGenArgs(['route', 'api/items', '--methods', 'get,GET,post']));

const content = read('routes/api/items.ts');
const handlers = Array.from(
content.matchAll(/^export const (\w+) = defineHandler/gm),
(match) => match[1],
);
expect(handlers).toEqual(['GET', 'POST']);
});

it('generates PUT and PATCH methods', async () => {
await runGenCommand(TMP, {
subcommand: 'route',
Expand Down