@@ -2,10 +2,10 @@ import { beforeEach, expect, test } from 'bun:test'
22
33const urlMap = {
44 foo : {
5- getUsers : { method : 'GET' as const , url : '/users' } ,
6- createUser : { method : 'POST' as const , url : '/users' } ,
7- updateUser : { method : 'PUT' as const , url : '/users/{id}' } ,
8- deleteUser : { method : 'DELETE' as const , url : '/users/{id}' } ,
5+ getUsers : { GET : { url : '/users' } } ,
6+ createUser : { POST : { url : '/users' } } ,
7+ updateUser : { PUT : { url : '/users/{id}' } } ,
8+ deleteUser : { DELETE : { url : '/users/{id}' } } ,
99 } ,
1010}
1111
@@ -15,41 +15,52 @@ beforeEach(() => {
1515const random = Math . random ( )
1616
1717test . each ( [
18- [ 'getUsers' , '/users' , JSON . stringify ( urlMap ) ] ,
19- [ 'createUser' , '/users' , JSON . stringify ( urlMap ) ] ,
20- [ 'updateUser' , '/users/{id}' , JSON . stringify ( urlMap ) ] ,
21- [ 'deleteUser' , '/users/{id}' , JSON . stringify ( urlMap ) ] ,
22- ] as const ) ( 'getApiEndpointInfo returns url for existing key: %s -> %s' , async ( key , expected , envValue ) => {
18+ [ 'getUsers' , '/users' , 'GET' , JSON . stringify ( urlMap ) ] ,
19+ [ 'createUser' , '/users' , 'POST' , JSON . stringify ( urlMap ) ] ,
20+ [ 'updateUser' , '/users/{id}' , 'PUT' , JSON . stringify ( urlMap ) ] ,
21+ [ 'deleteUser' , '/users/{id}' , 'DELETE' , JSON . stringify ( urlMap ) ] ,
22+ ] as const ) ( 'getApiEndpointInfo returns url for existing key: %s -> %s' , async ( key , expected , method , envValue ) => {
2323 process . env . DEVUP_API_URL_MAP = envValue
2424 // Add query parameter to bypass module cache and reload
2525 const { getApiEndpointInfo } = await import ( `../url-map?t=${ random } ` )
26- expect ( getApiEndpointInfo ( key , 'foo' ) ?. url ) . toBe ( expected )
26+ expect ( getApiEndpointInfo ( key , 'foo' , method ) ?. url ) . toBe ( expected )
2727} )
2828
2929test . each ( [
30- [ 'nonExistentKey' , 'nonExistentKey' , JSON . stringify ( urlMap ) ] ,
31- [ 'unknown' , 'unknown' , JSON . stringify ( urlMap ) ] ,
32- [ '' , '' , JSON . stringify ( urlMap ) ] ,
33- [ '/users' , '/users' , JSON . stringify ( urlMap ) ] ,
34- ] as const ) ( 'getApiEndpointInfo returns key itself when key does not exist: %s -> %s' , async ( key , expected , envValue ) => {
30+ [ 'nonExistentKey' , 'nonExistentKey' , 'GET' , JSON . stringify ( urlMap ) ] ,
31+ [ 'unknown' , 'unknown' , 'GET' , JSON . stringify ( urlMap ) ] ,
32+ [ '' , '' , 'GET' , JSON . stringify ( urlMap ) ] ,
33+ [ '/users' , '/users' , 'GET' , JSON . stringify ( urlMap ) ] ,
34+ ] as const ) ( 'getApiEndpointInfo returns key itself when key does not exist: %s -> %s' , async ( key , expected , method , envValue ) => {
3535 process . env . DEVUP_API_URL_MAP = envValue
3636 const { getApiEndpointInfo } = await import ( `../url-map?t=${ random } ` )
37- expect ( getApiEndpointInfo ( key , 'foo' ) . url ) . toBe ( expected )
37+ expect ( getApiEndpointInfo ( key , 'foo' , method ) . url ) . toBe ( expected )
3838} )
3939
4040test . each ( [
41- [ 'getUsers' , { method : 'GET' , url : '/users' } , JSON . stringify ( urlMap ) ] ,
42- [ 'createUser' , { method : 'POST' , url : '/users' } , JSON . stringify ( urlMap ) ] ,
43- [ 'updateUser' , { method : 'PUT' , url : '/users/{id}' } , JSON . stringify ( urlMap ) ] ,
41+ [ 'getUsers' , { method : 'GET' , url : '/users' } , 'GET' , JSON . stringify ( urlMap ) ] ,
42+ [
43+ 'createUser' ,
44+ { method : 'POST' , url : '/users' } ,
45+ 'POST' ,
46+ JSON . stringify ( urlMap ) ,
47+ ] ,
48+ [
49+ 'updateUser' ,
50+ { method : 'PUT' , url : '/users/{id}' } ,
51+ 'PUT' ,
52+ JSON . stringify ( urlMap ) ,
53+ ] ,
4454 [
4555 'deleteUser' ,
4656 { method : 'DELETE' , url : '/users/{id}' } ,
57+ 'DELETE' ,
4758 JSON . stringify ( urlMap ) ,
4859 ] ,
49- ] as const ) ( 'getApiEndpointInfo returns UrlMapValue for existing key: %s -> %s' , async ( key , expected , envValue ) => {
60+ ] as const ) ( 'getApiEndpointInfo returns UrlMapValue for existing key: %s -> %s' , async ( key , expected , method , envValue ) => {
5061 process . env . DEVUP_API_URL_MAP = envValue
5162 const { getApiEndpointInfo } = await import ( `../url-map?t=${ random } ` )
52- expect ( getApiEndpointInfo ( key , 'foo' ) ) . toEqual ( expected )
63+ expect ( getApiEndpointInfo ( key , 'foo' , method ) ) . toEqual ( expected )
5364} )
5465
5566test . each ( [
0 commit comments