File size: 1,186 Bytes
1f21206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { afterEach, describe, expect, it, vi } from 'vitest'
import { getDefaultBaseUrl, setBaseUrl } from './client'
import { openTargetsApi } from './openTargets'

describe('openTargetsApi', () => {
  afterEach(() => {
    setBaseUrl(getDefaultBaseUrl())
    vi.restoreAllMocks()
  })

  it('normalizes relative icon URLs to the configured desktop server URL', async () => {
    const fetchMock = vi.spyOn(globalThis, 'fetch')
    fetchMock.mockResolvedValueOnce(new Response(JSON.stringify({
      platform: 'darwin',
      targets: [
        {
          id: 'vscode',
          kind: 'ide',
          label: 'VS Code',
          icon: 'vscode',
          iconUrl: '/api/open-targets/icons/vscode',
          platform: 'darwin',
        },
      ],
      primaryTargetId: 'vscode',
      cachedAt: 1,
      ttlMs: 30_000,
    }), {
      status: 200,
      headers: { 'Content-Type': 'application/json' },
    }))

    setBaseUrl('http://127.0.0.1:49237')

    await expect(openTargetsApi.list()).resolves.toMatchObject({
      targets: [
        {
          id: 'vscode',
          iconUrl: 'http://127.0.0.1:49237/api/open-targets/icons/vscode',
        },
      ],
    })
  })
})