diff --git a/.vscode/settings.json b/.vscode/settings.json index ba19376c..a49fe89e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,7 +3,7 @@ "licenser.license": "Custom", "licenser.useSingleLineStyle": false, "editor.codeActionsOnSave": { - "source.fixAll.eslint": "explicit" + "source.fixAll.eslint": true }, "eslint.format.enable": true, "editor.formatOnSave": false diff --git a/src/__tests__/api.test.ts b/src/__tests__/api.test.ts index b6b23afc..338f6fdb 100644 --- a/src/__tests__/api.test.ts +++ b/src/__tests__/api.test.ts @@ -9,9 +9,18 @@ import { vi, describe, expect, it, afterEach } from 'vitest'; import { Api, AUTHORIZATION_HEADER } from '..'; import { SERVER_URL, TEST_CLIENT, TEST_DEVICE } from '../__helpers__/common'; +import { ImageType } from '../generated-client/models'; import { getAuthorizationHeader } from '../utils'; -vi.mock('axios'); +vi.mock('axios', async () => { + const actual = await vi.importActual('axios'); + return { + default: { + getUri: actual.getUri, + request: vi.fn() + } + } +}) const TEST_ACCESS_TOKEN = 'TEST-ACCESS-TOKEN'; /** @@ -48,8 +57,8 @@ describe('Api', () => { }); it('should logout and update state', async () => { - const api = new Api(SERVER_URL, TEST_CLIENT, TEST_DEVICE, TEST_ACCESS_TOKEN); const requestSpy = vi.spyOn(axios, 'request'); + const api = new Api(SERVER_URL, TEST_CLIENT, TEST_DEVICE, TEST_ACCESS_TOKEN); expect(api.accessToken).toBe(TEST_ACCESS_TOKEN); @@ -71,4 +80,12 @@ describe('Api', () => { const api = new Api(SERVER_URL, TEST_CLIENT, TEST_DEVICE); expect(api.basePath).toBe(SERVER_URL); }); + + it('should return an item image url', () => { + vi.restoreAllMocks(); + const api = new Api(SERVER_URL, TEST_CLIENT, TEST_DEVICE); + expect(api.getItemImageUrl('TEST')).toBe('https://example.com/Items/TEST/Images/Primary'); + expect(api.getItemImageUrl('TEST', ImageType.Backdrop, { fillWidth: 100, fillHeight: 100 })) + .toBe('https://example.com/Items/TEST/Images/Backdrop?fillWidth=100&fillHeight=100'); + }); }); diff --git a/src/discovery/__tests__/recommended-server-discovery.test.ts b/src/discovery/__tests__/recommended-server-discovery.test.ts index 5f8b3b9e..c0806eb7 100644 --- a/src/discovery/__tests__/recommended-server-discovery.test.ts +++ b/src/discovery/__tests__/recommended-server-discovery.test.ts @@ -102,7 +102,7 @@ describe('RecommendedServerDiscovery', () => { const requestSpy = vi.spyOn(axios, 'request'); requestSpy.mockImplementationOnce(() => { - vi.setSystemTime(now + 3001) + vi.setSystemTime(now + 3001); return Promise.resolve({ data: systemInfo }); }); const info = await serverDiscovery.fetchRecommendedServerInfo(ADDRESS);