Skip to content

Commit 709ec69

Browse files
committed
Write test code
1 parent b2efd4e commit 709ec69

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { expect, test } from 'bun:test'
2+
import * as indexModule from '../index'
3+
4+
test('index.ts exports', () => {
5+
expect({ ...indexModule }).toEqual({
6+
createUrlMap: expect.any(Function),
7+
generateInterface: expect.any(Function),
8+
})
9+
})
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { expect, test } from 'bun:test'
2+
import { wrapInterfaceKeyGuard } from '../wrap-interface-key-guard'
3+
4+
test.each([
5+
['getUsers', 'getUsers'],
6+
['createUser', 'createUser'],
7+
['updateUser', 'updateUser'],
8+
['deleteUser', 'deleteUser'],
9+
['testKey', 'testKey'],
10+
['camelCase', 'camelCase'],
11+
['snake_case', 'snake_case'],
12+
['PascalCase', 'PascalCase'],
13+
] as const)('wrapInterfaceKeyGuard returns key as-is when no slash: %s -> %s', (key, expected) => {
14+
expect(wrapInterfaceKeyGuard(key)).toBe(expected)
15+
})
16+
17+
test.each([
18+
['/users', '[`/users`]'],
19+
['/users/{id}', '[`/users/{id}`]'],
20+
['/api/v1/users', '[`/api/v1/users`]'],
21+
['/users/{userId}/posts/{postId}', '[`/users/{userId}/posts/{postId}`]'],
22+
['/api/v1/users/{id}/profile', '[`/api/v1/users/{id}/profile`]'],
23+
] as const)('wrapInterfaceKeyGuard wraps key with backticks when slash present: %s -> %s', (key, expected) => {
24+
expect(wrapInterfaceKeyGuard(key)).toBe(expected)
25+
})
26+
27+
test.each([
28+
['', ''],
29+
['/', '[`/`]'],
30+
['//', '[`//`]'],
31+
['///', '[`///`]'],
32+
] as const)('wrapInterfaceKeyGuard handles edge cases: %s -> %s', (key, expected) => {
33+
expect(wrapInterfaceKeyGuard(key)).toBe(expected)
34+
})
35+
36+
test.each([
37+
['users/123', '[`users/123`]'],
38+
['test/path/here', '[`test/path/here`]'],
39+
['a/b/c/d', '[`a/b/c/d`]'],
40+
] as const)('wrapInterfaceKeyGuard wraps key with multiple slashes: %s -> %s', (key, expected) => {
41+
expect(wrapInterfaceKeyGuard(key)).toBe(expected)
42+
})

0 commit comments

Comments
 (0)