|
1 | 1 | import { expect, test } from 'bun:test' |
2 | | -import { getApiEndpoint, isPlainObject } from '../utils' |
| 2 | +import { getApiEndpoint, getQueryString, isPlainObject } from '../utils' |
3 | 3 |
|
4 | 4 | test.each([ |
5 | 5 | [{}, true], |
@@ -106,3 +106,57 @@ test.each([ |
106 | 106 | ])('getApiEndpoint: baseUrl=%s, path=%s, params=%s -> %s', (baseUrl, path, params, expected) => { |
107 | 107 | expect(getApiEndpoint(baseUrl, path, params)).toBe(expected) |
108 | 108 | }) |
| 109 | + |
| 110 | +test.each([ |
| 111 | + ['a=1&b=2', 'a=1&b=2'], |
| 112 | + ['', ''], |
| 113 | + ['key=value&test=123', 'key=value&test=123'], |
| 114 | + ['x=1&y=2&z=3', 'x=1&y=2&z=3'], |
| 115 | + [{ a: '1', b: '2' }, 'a=1&b=2'], |
| 116 | + [{}, ''], |
| 117 | + [{ key: 'value', test: '123' }, 'key=value&test=123'], |
| 118 | + [{ x: '1', y: '2', z: '3' }, 'x=1&y=2&z=3'], |
| 119 | + [{ a: 1, b: 2 }, 'a=1&b=2'], |
| 120 | + [{ a: '1', b: 2, c: 'test' }, 'a=1&b=2&c=test'], |
| 121 | + [{ a: ['1', '2', '3'] }, 'a=1&a=2&a=3'], |
| 122 | + [{ a: [1, 2, 3] }, 'a=1&a=2&a=3'], |
| 123 | + [{ a: [1, '2', 3] }, 'a=1&a=2&a=3'], |
| 124 | + [new URLSearchParams('a=1&b=2'), 'a=1&b=2'], |
| 125 | + [new URLSearchParams(''), ''], |
| 126 | + [new URLSearchParams('key=value&test=123'), 'key=value&test=123'], |
| 127 | + [ |
| 128 | + [ |
| 129 | + ['a', '1'], |
| 130 | + ['b', '2'], |
| 131 | + ] as [string, string][], |
| 132 | + 'a=1&b=2', |
| 133 | + ], |
| 134 | + [ |
| 135 | + [ |
| 136 | + ['key', 'value'], |
| 137 | + ['test', '123'], |
| 138 | + ] as [string, string][], |
| 139 | + 'key=value&test=123', |
| 140 | + ], |
| 141 | + [ |
| 142 | + [ |
| 143 | + ['x', '1'], |
| 144 | + ['y', '2'], |
| 145 | + ['z', '3'], |
| 146 | + ] as [string, string][], |
| 147 | + 'x=1&y=2&z=3', |
| 148 | + ], |
| 149 | + [ |
| 150 | + [ |
| 151 | + ['x', '1'], |
| 152 | + ['x', '2'], |
| 153 | + ['x', '3'], |
| 154 | + ] as [string, string][], |
| 155 | + 'x=1&x=2&x=3', |
| 156 | + ], |
| 157 | +])('getQueryString: %s query -> "%s"', (query, expected) => { |
| 158 | + const result = getQueryString( |
| 159 | + query as NonNullable<Parameters<typeof getQueryString>[0]>, |
| 160 | + ) |
| 161 | + expect(result.toString()).toBe(expected) |
| 162 | +}) |
0 commit comments