-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow query params in $url method
Close #25
- Loading branch information
1 parent
308e3c9
commit 18aacee
Showing
5 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@tuyau/client': patch | ||
--- | ||
|
||
Query params are now allowed when building an URL with `$url`. See https://github.com/Julien-R44/tuyau/issues/25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -418,6 +418,36 @@ test.group('Client | Runtime', () => { | |
assert.deepEqual(tuyau.users({ id: '1' }).$url(), 'http://localhost:3333/users/1') | ||
}) | ||
|
||
test('generate url with query parameters', async ({ assert }) => { | ||
const tuyau = createTuyau<{ | ||
routes: [] | ||
definition: { | ||
users: { | ||
'$url': {} | ||
'$get': { | ||
request: { email: string } | ||
response: { 200: Simplify<Serialize<{ token: string }>> } | ||
} | ||
':id': { | ||
$url: {} | ||
$get: { | ||
request: { email: string } | ||
response: { 200: Simplify<Serialize<{ token: string }>> } | ||
} | ||
} | ||
} | ||
} | ||
}>({ baseUrl: 'http://localhost:3333' }) | ||
|
||
const result = tuyau.users.$url({ query: { email: '[email protected]', bar: ['baz', 'qux'] } }) | ||
assert.deepEqual(result, 'http://localhost:3333/users?email=foo%40ok.com&bar[]=baz&bar[]=qux') | ||
assert.deepEqual(tuyau.users({ id: '1' }).$url(), 'http://localhost:3333/users/1') | ||
assert.deepEqual( | ||
tuyau.users({ id: '1' }).$url({ query: { foo: 'ok' } }), | ||
'http://localhost:3333/users/1?foo=ok', | ||
) | ||
}) | ||
|
||
test('upload file pass the right content type', async () => { | ||
const tuyau = createTuyau<{ | ||
routes: [] | ||
|