@@ -64,7 +64,7 @@ test.each([
6464] as const ) ( 'getApiEndpointInfo returns default for non-existent key: %s -> %s' , async ( key , expected , envValue ) => {
6565 process . env . DEVUP_API_URL_MAP = envValue
6666 const { getApiEndpointInfo } = await import ( `../url-map` )
67- expect ( getApiEndpointInfo ( key , '' ) ) . toEqual ( expected )
67+ expect ( getApiEndpointInfo ( key , '' , 'GET' ) ) . toEqual ( expected )
6868} )
6969
7070test . each ( [
@@ -73,7 +73,7 @@ test.each([
7373] as const ) ( 'getApiEndpointInfo works with empty URL map: %s -> %s' , async ( key , expected , envValue ) => {
7474 process . env . DEVUP_API_URL_MAP = envValue
7575 const { getApiEndpointInfo } = await import ( `../url-map?t=${ random } ` )
76- expect ( getApiEndpointInfo ( key , 'foo' ) . url ) . toBe ( expected )
76+ expect ( getApiEndpointInfo ( key , 'foo' , 'GET' ) . url ) . toBe ( expected )
7777} )
7878
7979test . each ( [
@@ -82,7 +82,19 @@ test.each([
8282] as const ) ( 'getApiEndpointInfo works with empty URL map: %s -> %s' , async ( key , expected , envValue ) => {
8383 process . env . DEVUP_API_URL_MAP = envValue
8484 const { getApiEndpointInfo } = await import ( `../url-map?t=${ random } ` )
85- expect ( getApiEndpointInfo ( key , 'foo' ) ) . toEqual ( expected )
85+ expect ( getApiEndpointInfo ( key , 'foo' , 'GET' ) ) . toEqual ( expected )
86+ } )
87+
88+ test . each ( [
89+ [ [ 'GET' , 'anyKey' ] , '{}' ] ,
90+ [ [ 'POST' , 'anyKey' ] , '{}' ] ,
91+ [ [ 'PUT' , 'anyKey' ] , '{}' ] ,
92+ [ [ 'DELETE' , 'anyKey' ] , '{}' ] ,
93+ [ [ 'PATCH' , 'anyKey' ] , '{}' ] ,
94+ ] as const ) ( 'getApiEndpointInfo works with empty URL map: %s -> %s' , async ( key , envValue ) => {
95+ process . env . DEVUP_API_URL_MAP = envValue
96+ const { getApiEndpointInfo } = await import ( `../url-map?t=${ random } ` )
97+ expect ( getApiEndpointInfo ( key [ 1 ] , 'foo' , key [ 0 ] ) . method ) . toEqual ( key [ 0 ] )
8698} )
8799
88100test . each ( [
@@ -91,7 +103,7 @@ test.each([
91103] as const ) ( 'getApiEndpointInfo works when DEVUP_API_URL_MAP is not set: %s -> %s' , async ( key , expected ) => {
92104 delete process . env . DEVUP_API_URL_MAP
93105 const { getApiEndpointInfo } = await import ( `../url-map?t=${ random } ` )
94- expect ( getApiEndpointInfo ( key , 'foo' ) . url ) . toBe ( expected )
106+ expect ( getApiEndpointInfo ( key , 'foo' , 'GET' ) . url ) . toBe ( expected )
95107} )
96108
97109test . each ( [
@@ -100,145 +112,5 @@ test.each([
100112] as const ) ( 'getApiEndpointInfo works when DEVUP_API_URL_MAP is not set: %s -> %s' , async ( key , expected ) => {
101113 delete process . env . DEVUP_API_URL_MAP
102114 const { getApiEndpointInfo } = await import ( `../url-map?t=${ random } ` )
103- expect ( getApiEndpointInfo ( key , 'foo' ) . url ) . toBe ( expected )
115+ expect ( getApiEndpointInfo ( key , 'foo' , 'GET' ) . url ) . toBe ( expected )
104116} )
105-
106- // test.each([
107- // ['anyKey', { method: 'GET', url: 'anyKey' }],
108- // ['test', { method: 'GET', url: 'test' }],
109- // ] as const)('getApiEndpointInfo works when DEVUP_API_URL_MAP is not set: %s -> %s', async (key, expected) => {
110- // delete process.env.DEVUP_API_URL_MAP
111- // const { getApiEndpointInfo } = await import(`../url-map?t=1`)
112- // expect(getApiEndpointInfo(key, 'foo')).toEqual(expected)
113- // })
114-
115- // test('getApiEndpointInfo handles key that exists but url property is missing', async () => {
116- // const urlMapWithoutUrl = {
117- // testKey: { method: 'GET' as const },
118- // }
119- // process.env.DEVUP_API_URL_MAP = JSON.stringify(urlMapWithoutUrl)
120- // const { getApiEndpointInfo } = await import(
121- // `../url-map`
122- // )
123- // // When url property is missing, optional chaining returns undefined, so key is returned
124- // expect(getApiEndpointInfo('testKey', 'foo').url).toBe('testKey')
125- // })
126-
127- // test('DEVUP_API_URL_MAP constant is exported and accessible', async () => {
128- // const testUrlMap = {
129- // '': { testKey: { method: 'GET' as const, url: '/test' } },
130- // }
131- // process.env.DEVUP_API_URL_MAP = JSON.stringify(testUrlMap)
132- // const urlMapModule = await import(
133- // `../url-map`
134- // )
135- // expect(urlMapModule).toHaveProperty('DEVUP_API_URL_MAP')
136- // expect(typeof urlMapModule.DEVUP_API_URL_MAP).toBe('object')
137- // // Directly access the constant to ensure it's covered
138- // const urlMap = urlMapModule.DEVUP_API_URL_MAP
139- // expect(urlMap).toEqual(testUrlMap)
140- // // Verify it's used by getApiEndpointInfo function
141- // expect(urlMapModule.getApiEndpointInfo('testKey', 'foo').url).toBe('/test')
142- // })
143-
144- // test('DEVUP_API_URL_MAP uses fallback when env var is undefined', async () => {
145- // delete process.env.DEVUP_API_URL_MAP
146- // const urlMapModule = await import(
147- // `../url-map`
148- // )
149- // // Directly access the constant to ensure the fallback path is covered
150- // const urlMap = urlMapModule.DEVUP_API_URL_MAP
151- // expect(urlMap).toEqual({})
152- // expect(urlMapModule.getApiEndpointInfo('anyKey', 'foo').url).toBe('anyKey')
153- // // Explicitly call getApiEndpointInfo to ensure it's covered
154- // const result = urlMapModule.getApiEndpointInfo('anyKey', 'foo')
155- // expect(result).toEqual({
156- // method: 'GET',
157- // url: 'anyKey',
158- // })
159- // // Also test that the function exists and is callable
160- // expect(typeof urlMapModule.getApiEndpointInfo).toBe('function')
161- // })
162-
163- // test('DEVUP_API_URL_MAP uses fallback when env var is empty string', async () => {
164- // process.env.DEVUP_API_URL_MAP = ''
165- // const urlMapModule = await import(
166- // `../url-map`
167- // )
168- // // Directly access the constant to ensure the fallback path is covered
169- // const urlMap = urlMapModule.DEVUP_API_URL_MAP
170- // expect(urlMap).toEqual({})
171- // expect(urlMapModule.getApiEndpointInfo('anyKey', 'foo').url).toBe('anyKey')
172- // expect(urlMapModule.getApiEndpointInfo('anyKey', 'foo')).toEqual({
173- // method: 'GET',
174- // url: 'anyKey',
175- // })
176- // })
177-
178- // test('getApiEndpointInfo handles key where DEVUP_API_URL_MAP[key] exists but url is undefined', async () => {
179- // const urlMapWithUndefinedUrl = {
180- // testKey: { method: 'GET' as const },
181- // }
182- // process.env.DEVUP_API_URL_MAP = JSON.stringify(urlMapWithUndefinedUrl)
183- // const { getApiEndpointInfo } = await import(
184- // `../url-map`
185- // )
186- // // When url property is missing, optional chaining returns undefined, so key is returned
187- // expect(getApiEndpointInfo('testKey', 'foo').url).toBe('testKey')
188- // })
189-
190- // test('getApiEndpointInfo handles key where DEVUP_API_URL_MAP[key] exists but url is null', async () => {
191- // const urlMapWithNullUrl = {
192- // testKey: { method: 'GET' as const, url: null as unknown as string },
193- // }
194- // process.env.DEVUP_API_URL_MAP = JSON.stringify(urlMapWithNullUrl)
195- // const { getApiEndpointInfo } = await import(
196- // `../url-map`
197- // )
198- // // When url is null, optional chaining returns null, so key is returned
199- // expect(getApiEndpointInfo('testKey', 'foo').url).toBe('testKey')
200- // })
201-
202- // test('getApiEndpointInfo handles key where DEVUP_API_URL_MAP[key] exists but url is empty string', async () => {
203- // const urlMapWithEmptyUrl = {
204- // testKey: { method: 'GET' as const, url: '' },
205- // }
206- // process.env.DEVUP_API_URL_MAP = JSON.stringify(urlMapWithEmptyUrl)
207- // const { getApiEndpointInfo } = await import(
208- // `../url-map`
209- // )
210- // // When url is empty string, it's falsy, so key is returned
211- // expect(getApiEndpointInfo('testKey', 'foo').url).toBe('testKey')
212- // })
213-
214- // test('getApiEndpointInfo returns default when key does not exist in map (explicit coverage for line 10)', async () => {
215- // const urlMap = { existingKey: { method: 'POST' as const, url: '/existing' } }
216- // process.env.DEVUP_API_URL_MAP = JSON.stringify(urlMap)
217- // const { getApiEndpointInfo } = await import(
218- // `../url-map`
219- // )
220- // // Explicitly test the if(!result) branch to ensure line 10 is covered
221- // const result = getApiEndpointInfo('nonExistentKeyInMap', 'foo')
222- // expect(result).toEqual({ method: 'GET', url: 'nonExistentKeyInMap' })
223- // expect(result.method).toBe('GET')
224- // expect(result.url).toBe('nonExistentKeyInMap')
225- // })
226-
227- // test('getApiEndpointInfo returns result when key exists with url (explicit coverage for lines 12-13)', async () => {
228- // const urlMap = {
229- // '': {
230- // testKey: { method: 'PUT' as const, url: '/test/url' },
231- // },
232- // }
233- // process.env.DEVUP_API_URL_MAP = JSON.stringify(urlMap)
234- // const { getApiEndpointInfo } = await import(
235- // `../url-map?t=${Date.now()+Math.random()}`
236- // )
237- // // Explicitly test the result.url ||= key and return result path (lines 12-13)
238- // const result = getApiEndpointInfo('testKey', 'foo')
239- // expect(result).toEqual({ method: 'PUT', url: '/test/url' })
240- // expect(result.method).toBe('PUT')
241- // expect(result.url).toBe('/test/url')
242- // // Verify that url was not changed (since it already exists)
243- // expect(result.url).not.toBe('testKey')
244- // })
0 commit comments