|
| 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