diff --git a/src/__tests__/api.test.ts b/src/__tests__/api.test.ts index f05f60c0e..71f80071a 100644 --- a/src/__tests__/api.test.ts +++ b/src/__tests__/api.test.ts @@ -9,7 +9,7 @@ import { mocked } from 'ts-jest/utils'; import { Api, AUTHORIZATION_HEADER } from '..'; import { SERVER_URL, TEST_CLIENT, TEST_DEVICE } from '../__helpers__/common'; -import { ActivityLogApi, ApiKeyApi, ArtistsApi, AudioApi, BrandingApi, ChannelsApi, CollectionApi, ConfigurationApi, DashboardApi, DevicesApi, DisplayPreferencesApi, DlnaApi, DlnaServerApi, DynamicHlsApi, EnvironmentApi, FilterApi, GenresApi, HlsSegmentApi, ImageApi, ImageByNameApi, ImageType, InstantMixApi, ItemLookupApi, ItemRefreshApi, ItemsApi, ItemUpdateApi, LibraryApi, LibraryStructureApi, LiveTvApi, LocalizationApi, MediaInfoApi, MoviesApi, MusicGenresApi, NotificationsApi, PackageApi, PersonsApi, PlaylistsApi, PlaystateApi, PluginsApi, QuickConnectApi, RemoteImageApi, ScheduledTasksApi, SearchApi, SessionApi, StartupApi, StudiosApi, SubtitleApi, SuggestionsApi, SyncPlayApi, SystemApi, TimeSyncApi, TrailersApi, TvShowsApi, UniversalAudioApi, UserApi, UserLibraryApi, UserViewsApi, VideoAttachmentsApi, VideoHlsApi, VideosApi, YearsApi } from '../generated-client'; +import { ImageType } from '../generated-client/models'; import { getAuthorizationHeader } from '../utils'; jest.mock('axios', () => ({ @@ -79,69 +79,4 @@ describe('Api', () => { expect(api.getItemImageUrl('TEST', ImageType.Backdrop, { fillWidth: 100, fillHeight: 100 })) .toBe('https://example.com/Items/TEST/Images/Backdrop?fillWidth=100&fillHeight=100'); }); - - it('should return api instances', () => { - const api = new Api(SERVER_URL, TEST_CLIENT, TEST_DEVICE); - - expect(api.activityLogApi).toBeInstanceOf(ActivityLogApi); - expect(api.apiKeyApi).toBeInstanceOf(ApiKeyApi); - expect(api.artistsApi).toBeInstanceOf(ArtistsApi); - expect(api.audioApi).toBeInstanceOf(AudioApi); - expect(api.brandingApi).toBeInstanceOf(BrandingApi); - expect(api.channelsApi).toBeInstanceOf(ChannelsApi); - expect(api.collectionApi).toBeInstanceOf(CollectionApi); - expect(api.configurationApi).toBeInstanceOf(ConfigurationApi); - expect(api.dashboardApi).toBeInstanceOf(DashboardApi); - expect(api.devicesApi).toBeInstanceOf(DevicesApi); - expect(api.displayPreferencesApi).toBeInstanceOf(DisplayPreferencesApi); - expect(api.dlnaApi).toBeInstanceOf(DlnaApi); - expect(api.dlnaServerApi).toBeInstanceOf(DlnaServerApi); - expect(api.dynamicHlsApi).toBeInstanceOf(DynamicHlsApi); - expect(api.environmentApi).toBeInstanceOf(EnvironmentApi); - expect(api.filterApi).toBeInstanceOf(FilterApi); - expect(api.genresApi).toBeInstanceOf(GenresApi); - expect(api.hlsSegmentApi).toBeInstanceOf(HlsSegmentApi); - expect(api.imageApi).toBeInstanceOf(ImageApi); - expect(api.imageByNameApi).toBeInstanceOf(ImageByNameApi); - expect(api.instantMixApi).toBeInstanceOf(InstantMixApi); - expect(api.itemLookupApi).toBeInstanceOf(ItemLookupApi); - expect(api.itemRefreshApi).toBeInstanceOf(ItemRefreshApi); - expect(api.itemUpdateApi).toBeInstanceOf(ItemUpdateApi); - expect(api.itemsApi).toBeInstanceOf(ItemsApi); - expect(api.libraryApi).toBeInstanceOf(LibraryApi); - expect(api.libraryStructureApi).toBeInstanceOf(LibraryStructureApi); - expect(api.liveTvApi).toBeInstanceOf(LiveTvApi); - expect(api.localizationApi).toBeInstanceOf(LocalizationApi); - expect(api.mediaInfoApi).toBeInstanceOf(MediaInfoApi); - expect(api.moviesApi).toBeInstanceOf(MoviesApi); - expect(api.musicGenresApi).toBeInstanceOf(MusicGenresApi); - expect(api.notificationsApi).toBeInstanceOf(NotificationsApi); - expect(api.packageApi).toBeInstanceOf(PackageApi); - expect(api.personsApi).toBeInstanceOf(PersonsApi); - expect(api.playlistsApi).toBeInstanceOf(PlaylistsApi); - expect(api.playstateApi).toBeInstanceOf(PlaystateApi); - expect(api.pluginsApi).toBeInstanceOf(PluginsApi); - expect(api.quickConnectApi).toBeInstanceOf(QuickConnectApi); - expect(api.remoteImageApi).toBeInstanceOf(RemoteImageApi); - expect(api.scheduledTasksApi).toBeInstanceOf(ScheduledTasksApi); - expect(api.searchApi).toBeInstanceOf(SearchApi); - expect(api.sessionApi).toBeInstanceOf(SessionApi); - expect(api.startupApi).toBeInstanceOf(StartupApi); - expect(api.studiosApi).toBeInstanceOf(StudiosApi); - expect(api.subtitleApi).toBeInstanceOf(SubtitleApi); - expect(api.suggestionsApi).toBeInstanceOf(SuggestionsApi); - expect(api.syncPlayApi).toBeInstanceOf(SyncPlayApi); - expect(api.systemApi).toBeInstanceOf(SystemApi); - expect(api.timeSyncApi).toBeInstanceOf(TimeSyncApi); - expect(api.trailersApi).toBeInstanceOf(TrailersApi); - expect(api.tvShowsApi).toBeInstanceOf(TvShowsApi); - expect(api.universalAudioApi).toBeInstanceOf(UniversalAudioApi); - expect(api.userApi).toBeInstanceOf(UserApi); - expect(api.userLibraryApi).toBeInstanceOf(UserLibraryApi); - expect(api.userViewsApi).toBeInstanceOf(UserViewsApi); - expect(api.videoAttachmentsApi).toBeInstanceOf(VideoAttachmentsApi); - expect(api.videoHlsApi).toBeInstanceOf(VideoHlsApi); - expect(api.videosApi).toBeInstanceOf(VideosApi); - expect(api.yearsApi).toBeInstanceOf(YearsApi); - }); }); diff --git a/src/utils/api/__tests__/api.test.ts b/src/utils/api/__tests__/api.test.ts new file mode 100644 index 000000000..35df27443 --- /dev/null +++ b/src/utils/api/__tests__/api.test.ts @@ -0,0 +1,142 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import { SERVER_URL, TEST_CLIENT, TEST_DEVICE } from '../../../__helpers__/common'; + +import { Api } from '../../../api'; +import { ActivityLogApi, ApiKeyApi, ArtistsApi, AudioApi, BrandingApi, ChannelsApi, CollectionApi, ConfigurationApi, DashboardApi, DevicesApi, DisplayPreferencesApi, DlnaApi, DlnaServerApi, DynamicHlsApi, EnvironmentApi, FilterApi, GenresApi, HlsSegmentApi, ImageApi, ImageByNameApi, InstantMixApi, ItemLookupApi, ItemRefreshApi, ItemsApi, ItemUpdateApi, LibraryApi, LibraryStructureApi, LiveTvApi, LocalizationApi, MediaInfoApi, MoviesApi, MusicGenresApi, NotificationsApi, PackageApi, PersonsApi, PlaylistsApi, PlaystateApi, PluginsApi, QuickConnectApi, RemoteImageApi, ScheduledTasksApi, SearchApi, SessionApi, StartupApi, StudiosApi, SubtitleApi, SuggestionsApi, SyncPlayApi, SystemApi, TimeSyncApi, TrailersApi, TvShowsApi, UniversalAudioApi, UserApi, UserLibraryApi, UserViewsApi, VideoAttachmentsApi, VideoHlsApi, VideosApi, YearsApi } from '../../../generated-client/api'; +import { getActivityLogApi } from '../activity-log-api'; +import { getApiKeyApi } from '../api-key-api'; +import { getArtistsApi } from '../artists-api'; +import { getAudioApi } from '../audio-api'; +import { getBrandingApi } from '../branding-api'; +import { getChannelsApi } from '../channels-api'; +import { getCollectionApi } from '../collection-api'; +import { getConfigurationApi } from '../configuration-api'; +import { getDashboardApi } from '../dashboard-api'; +import { getDevicesApi } from '../devices-api'; +import { getDisplayPreferencesApi } from '../display-preferences-api'; +import { getDlnaApi } from '../dlna-api'; +import { getDlnaServerApi } from '../dlna-server-api'; +import { getDynamicHlsApi } from '../dynamic-hls-api'; +import { getEnvironmentApi } from '../environment-api'; +import { getFilterApi } from '../filter-api'; +import { getGenresApi } from '../genres-api'; +import { getHlsSegmentApi } from '../hls-segment-api'; +import { getImageApi } from '../image-api'; +import { getImageByNameApi } from '../image-by-name-api'; +import { getInstantMixApi } from '../instant-mix-api'; +import { getItemLookupApi } from '../item-lookup-api'; +import { getItemRefreshApi } from '../item-refresh-api'; +import { getItemUpdateApi } from '../item-update-api'; +import { getItemsApi } from '../items-api'; +import { getLibraryApi } from '../library-api'; +import { getLibraryStructureApi } from '../library-structure-api'; +import { getLiveTvApi } from '../live-tv-api'; +import { getLocalizationApi } from '../localization-api'; +import { getMediaInfoApi } from '../media-info-api'; +import { getMoviesApi } from '../movies-api'; +import { getMusicGenresApi } from '../music-genres-api'; +import { getNotificationsApi } from '../notifications-api'; +import { getPackageApi } from '../package-api'; +import { getPersonsApi } from '../persons-api'; +import { getPlaylistsApi } from '../playlists-api'; +import { getPlaystateApi } from '../playstate-api'; +import { getPluginsApi } from '../plugins-api'; +import { getQuickConnectApi } from '../quick-connect-api'; +import { getRemoteImageApi } from '../remote-image-api'; +import { getScheduledTasksApi } from '../scheduled-tasks-api'; +import { getSearchApi } from '../search-api'; +import { getSessionApi } from '../session-api'; +import { getStartupApi } from '../startup-api'; +import { getStudiosApi } from '../studios-api'; +import { getSubtitleApi } from '../subtitle-api'; +import { getSuggestionsApi } from '../suggestions-api'; +import { getSyncPlayApi } from '../sync-play-api'; +import { getSystemApi } from '../system-api'; +import { getTimeSyncApi } from '../time-sync-api'; +import { getTrailersApi } from '../trailers-api'; +import { getTvShowsApi } from '../tv-shows-api'; +import { getUniversalAudioApi } from '../universal-audio-api'; +import { getUserApi } from '../user-api'; +import { getUserLibraryApi } from '../user-library-api'; +import { getUserViewsApi } from '../user-views-api'; +import { getVideoAttachmentsApi } from '../video-attachments-api'; +import { getVideoHlsApi } from '../video-hls-api'; +import { getVideosApi } from '../videos-api'; +import { getYearsApi } from '../years-api'; + +/** + * Api helper function tests. + * + * @group unit/utils/api + */ +describe('Api Utilities', () => { + it('get api functions should return api instances', () => { + const api = new Api(SERVER_URL, TEST_CLIENT, TEST_DEVICE); + + expect(getActivityLogApi(api)).toBeInstanceOf(ActivityLogApi); + expect(getApiKeyApi(api)).toBeInstanceOf(ApiKeyApi); + expect(getArtistsApi(api)).toBeInstanceOf(ArtistsApi); + expect(getAudioApi(api)).toBeInstanceOf(AudioApi); + expect(getBrandingApi(api)).toBeInstanceOf(BrandingApi); + expect(getChannelsApi(api)).toBeInstanceOf(ChannelsApi); + expect(getCollectionApi(api)).toBeInstanceOf(CollectionApi); + expect(getConfigurationApi(api)).toBeInstanceOf(ConfigurationApi); + expect(getDashboardApi(api)).toBeInstanceOf(DashboardApi); + expect(getDevicesApi(api)).toBeInstanceOf(DevicesApi); + expect(getDisplayPreferencesApi(api)).toBeInstanceOf(DisplayPreferencesApi); + expect(getDlnaApi(api)).toBeInstanceOf(DlnaApi); + expect(getDlnaServerApi(api)).toBeInstanceOf(DlnaServerApi); + expect(getDynamicHlsApi(api)).toBeInstanceOf(DynamicHlsApi); + expect(getEnvironmentApi(api)).toBeInstanceOf(EnvironmentApi); + expect(getFilterApi(api)).toBeInstanceOf(FilterApi); + expect(getGenresApi(api)).toBeInstanceOf(GenresApi); + expect(getHlsSegmentApi(api)).toBeInstanceOf(HlsSegmentApi); + expect(getImageApi(api)).toBeInstanceOf(ImageApi); + expect(getImageByNameApi(api)).toBeInstanceOf(ImageByNameApi); + expect(getInstantMixApi(api)).toBeInstanceOf(InstantMixApi); + expect(getItemLookupApi(api)).toBeInstanceOf(ItemLookupApi); + expect(getItemRefreshApi(api)).toBeInstanceOf(ItemRefreshApi); + expect(getItemUpdateApi(api)).toBeInstanceOf(ItemUpdateApi); + expect(getItemsApi(api)).toBeInstanceOf(ItemsApi); + expect(getLibraryApi(api)).toBeInstanceOf(LibraryApi); + expect(getLibraryStructureApi(api)).toBeInstanceOf(LibraryStructureApi); + expect(getLiveTvApi(api)).toBeInstanceOf(LiveTvApi); + expect(getLocalizationApi(api)).toBeInstanceOf(LocalizationApi); + expect(getMediaInfoApi(api)).toBeInstanceOf(MediaInfoApi); + expect(getMoviesApi(api)).toBeInstanceOf(MoviesApi); + expect(getMusicGenresApi(api)).toBeInstanceOf(MusicGenresApi); + expect(getNotificationsApi(api)).toBeInstanceOf(NotificationsApi); + expect(getPackageApi(api)).toBeInstanceOf(PackageApi); + expect(getPersonsApi(api)).toBeInstanceOf(PersonsApi); + expect(getPlaylistsApi(api)).toBeInstanceOf(PlaylistsApi); + expect(getPlaystateApi(api)).toBeInstanceOf(PlaystateApi); + expect(getPluginsApi(api)).toBeInstanceOf(PluginsApi); + expect(getQuickConnectApi(api)).toBeInstanceOf(QuickConnectApi); + expect(getRemoteImageApi(api)).toBeInstanceOf(RemoteImageApi); + expect(getScheduledTasksApi(api)).toBeInstanceOf(ScheduledTasksApi); + expect(getSearchApi(api)).toBeInstanceOf(SearchApi); + expect(getSessionApi(api)).toBeInstanceOf(SessionApi); + expect(getStartupApi(api)).toBeInstanceOf(StartupApi); + expect(getStudiosApi(api)).toBeInstanceOf(StudiosApi); + expect(getSubtitleApi(api)).toBeInstanceOf(SubtitleApi); + expect(getSuggestionsApi(api)).toBeInstanceOf(SuggestionsApi); + expect(getSyncPlayApi(api)).toBeInstanceOf(SyncPlayApi); + expect(getSystemApi(api)).toBeInstanceOf(SystemApi); + expect(getTimeSyncApi(api)).toBeInstanceOf(TimeSyncApi); + expect(getTrailersApi(api)).toBeInstanceOf(TrailersApi); + expect(getTvShowsApi(api)).toBeInstanceOf(TvShowsApi); + expect(getUniversalAudioApi(api)).toBeInstanceOf(UniversalAudioApi); + expect(getUserApi(api)).toBeInstanceOf(UserApi); + expect(getUserLibraryApi(api)).toBeInstanceOf(UserLibraryApi); + expect(getUserViewsApi(api)).toBeInstanceOf(UserViewsApi); + expect(getVideoAttachmentsApi(api)).toBeInstanceOf(VideoAttachmentsApi); + expect(getVideoHlsApi(api)).toBeInstanceOf(VideoHlsApi); + expect(getVideosApi(api)).toBeInstanceOf(VideosApi); + expect(getYearsApi(api)).toBeInstanceOf(YearsApi); + }); +});