1- import fetchMock , { enableFetchMocks } from 'jest-fetch-mock' ;
2- import { MediaDbPluginSettings } from 'src/settings/Settings' ;
3- import { LocGovAPI } from '../api/apis/LocGovAPI' ;
4- import { MALAPI } from '../api/apis/MALAPI' ;
5- import { MusicBrainzAPI } from '../api/apis/MusicBrainzAPI' ;
6- import { OMDbAPI } from '../api/apis/OMDbAPI' ;
7- import { SteamAPI } from '../api/apis/SteamAPI' ;
8- import { WikipediaAPI } from '../api/apis/WikipediaAPI' ;
1+ import fetchMock , { enableFetchMocks } from 'jest-fetch-mock' ;
2+ import { MediaDbPluginSettings } from 'src/settings/Settings' ;
3+ import { LocGovAPI } from '../api/apis/LocGovAPI' ;
4+ import { MALAPI } from '../api/apis/MALAPI' ;
5+ import { MusicBrainzAPI } from '../api/apis/MusicBrainzAPI' ;
6+ import { OMDbAPI } from '../api/apis/OMDbAPI' ;
7+ import { SteamAPI } from '../api/apis/SteamAPI' ;
8+ import { WikipediaAPI } from '../api/apis/WikipediaAPI' ;
99import MediaDbPlugin from '../main' ;
10- import { setMALResponseMock , setMusicBrainzResponseMock , setOMDbResponseMock , setSteamResponseMock , setWikipediaResponseMock } from " ./mockHelpers" ;
11- import MALMockMovie from " ./ResponseMocks/MALMockMovie.json" ;
12- import MusicBrainzResponseMock from " ./ResponseMocks/MusicBrainzMockResponse.json" ;
13- import OMDBMockMovie from " ./ResponseMocks/OMDBMockResponse.json" ;
14- import SteamAPIResponseMock from " ./ResponseMocks/SteamAPIMockResponse.json" ;
15- import WikipediaMockResponse from " ./ResponseMocks/WikipediaMockResponse.json" ;
10+ import { setMALResponseMock , setMusicBrainzResponseMock , setOMDbResponseMock , setSteamResponseMock , setWikipediaResponseMock } from ' ./mockHelpers' ;
11+ import MALMockMovie from ' ./ResponseMocks/MALMockMovie.json' ;
12+ import MusicBrainzResponseMock from ' ./ResponseMocks/MusicBrainzMockResponse.json' ;
13+ import OMDBMockMovie from ' ./ResponseMocks/OMDBMockResponse.json' ;
14+ import SteamAPIResponseMock from ' ./ResponseMocks/SteamAPIMockResponse.json' ;
15+ import WikipediaMockResponse from ' ./ResponseMocks/WikipediaMockResponse.json' ;
1616
1717enableFetchMocks ( ) ;
1818export let apiMock : OMDbAPI | MALAPI | LocGovAPI | MusicBrainzAPI | SteamAPI | WikipediaAPI ;
1919
2020describe . each (
2121 [
22- { name : OMDbAPI } ,
23- { name : MALAPI } ,
24- { name : LocGovAPI } ,
25- { name : MusicBrainzAPI } ,
26- { name : SteamAPI } ,
27- { name : WikipediaAPI }
28- ]
29- ) ( '$name.name' , ( { name : parameterizedApi } ) => {
22+ { name : OMDbAPI } ,
23+ { name : MALAPI } ,
24+ { name : LocGovAPI } ,
25+ { name : MusicBrainzAPI } ,
26+ { name : SteamAPI } ,
27+ { name : WikipediaAPI } ,
28+ ] ,
29+ ) ( '$name.name' , ( { name : parameterizedApi } ) => {
3030 beforeAll ( ( ) => {
3131 let settingsMock : MediaDbPluginSettings = { } as MediaDbPluginSettings ;
3232 let pluginMock = { } as MediaDbPlugin ;
3333 pluginMock . settings = settingsMock ;
3434 // TODO: add fake API key?
3535 apiMock = new parameterizedApi ( pluginMock ) ;
36- } )
36+ } ) ;
3737
3838 beforeEach ( ( ) => {
3939 fetchMock . resetMocks ( ) ;
40- } )
40+ } ) ;
4141
42- test ( " searchByTitle behavior when API returns garbage data" , async ( ) => {
42+ test ( ' searchByTitle behavior when API returns garbage data' , async ( ) => {
4343 const garbageResponse = JSON . stringify ( {
44- data : " string"
44+ data : ' string' ,
4545 } ) ;
46- fetchMock . mockResponseOnce ( garbageResponse )
47- await expect ( apiMock . searchByTitle ( " sample" ) ) . resolves . toEqual ( [ ] ) ;
46+ fetchMock . mockResponseOnce ( garbageResponse ) ;
47+ await expect ( apiMock . searchByTitle ( ' sample' ) ) . resolves . toEqual ( [ ] ) ;
4848 // }
4949 expect ( fetch ) . toHaveBeenCalledTimes ( 1 ) ;
5050 } ) ;
5151
52- test ( " searchByTitle behavior when requestUrl/fetch returns 401" , async ( ) => {
52+ test ( ' searchByTitle behavior when requestUrl/fetch returns 401' , async ( ) => {
5353 let sampleResponse = {
54- data : " string"
54+ data : ' string' ,
5555 } ;
56- fetchMock . mockResponse ( JSON . stringify ( sampleResponse ) , { status : 401 } ) ;
56+ fetchMock . mockResponse ( JSON . stringify ( sampleResponse ) , { status : 401 } ) ;
5757 // TODO: Check API name and fix message
5858 // TODO: Externalize string
59- await expect ( apiMock . searchByTitle ( " sample" ) ) . rejects . toThrow ( `MDB | Received status code ${ 401 } from an API.` ) ;
59+ await expect ( apiMock . searchByTitle ( ' sample' ) ) . rejects . toThrow ( `MDB | Received status code ${ 401 } from an API.` ) ;
6060 expect ( fetchMock ) . toHaveBeenCalledTimes ( 1 ) ;
6161 } ) ;
6262
63- test ( " searchByTitle behavior when requestUrl/fetch returns 403" , async ( ) => {
63+ test ( ' searchByTitle behavior when requestUrl/fetch returns 403' , async ( ) => {
6464 let sampleResponse = {
65- data : " string"
65+ data : ' string' ,
6666 } ;
67- fetchMock . mockResponse ( JSON . stringify ( sampleResponse ) , { status : 403 } ) ;
67+ fetchMock . mockResponse ( JSON . stringify ( sampleResponse ) , { status : 403 } ) ;
6868 // TODO: Check API name and fix message
6969 // TODO: Externalize string/import?
70- await expect ( apiMock . searchByTitle ( " sample" ) ) . rejects . toThrow ( `MDB | Received status code ${ 403 } from an API.` ) ;
70+ await expect ( apiMock . searchByTitle ( ' sample' ) ) . rejects . toThrow ( `MDB | Received status code ${ 403 } from an API.` ) ;
7171 expect ( fetchMock ) . toHaveBeenCalledTimes ( 1 ) ;
7272 } ) ;
7373
74- test ( " searchByTitle behavior when requestUrl/fetch returns 200" , async ( ) => {
74+ test ( ' searchByTitle behavior when requestUrl/fetch returns 200' , async ( ) => {
7575 let sampleResponse ;
7676 let ret ;
7777 switch ( parameterizedApi ) {
@@ -101,10 +101,10 @@ describe.each(
101101 default :
102102 throw Error ( ) ;
103103 }
104- fetchMock . mockResponse ( JSON . stringify ( sampleResponse ) , { status : 200 } ) ;
104+ fetchMock . mockResponse ( JSON . stringify ( sampleResponse ) , { status : 200 } ) ;
105105 // TODO: Check API name and fix message
106106 // TODO: Externalize string
107- await expect ( apiMock . searchByTitle ( " Hooking Season Playtest" ) ) . resolves . toEqual ( ret ) ;
107+ await expect ( apiMock . searchByTitle ( ' Hooking Season Playtest' ) ) . resolves . toEqual ( ret ) ;
108108 expect ( fetchMock ) . toHaveBeenCalledTimes ( 1 ) ;
109109 } ) ;
110- } )
110+ } ) ;
0 commit comments