44 AppleGamingWikiInfo ,
55 WikiInfo ,
66 PCGamingWikiInfo ,
7- ProtonDBCompatibilityInfo
7+ ProtonDBCompatibilityInfo ,
8+ SteamDeckComp ,
9+ SteamInfo
810} from 'common/types'
911import { wikiGameInfoStore } from '../electronStore'
1012import { getWikiGameInfo } from '../wiki_game_info'
@@ -13,16 +15,13 @@ import * as AppleGamingWiki from '../applegamingwiki/utils'
1315import * as HowLongToBeat from '../howlongtobeat/utils'
1416import * as GamesDB from '../gamesdb/utils'
1517import * as ProtonDB from '../protondb/utils'
18+ import * as SteamDeck from '../steamdeck/utils'
1619import { logError } from '../../logger/logger'
1720
1821jest . mock ( 'electron-store' )
1922jest . mock ( '../../logger/logfile' )
2023jest . mock ( '../../logger/logger' )
21- jest . mock ( '../../constants' , ( ) => {
22- return {
23- isMac : true
24- }
25- } )
24+ import * as mockConstants from '../../constants'
2625const currentTime = new Date ( )
2726jest . useFakeTimers ( ) . setSystemTime ( currentTime )
2827
@@ -43,8 +42,13 @@ describe('getWikiGameInfo', () => {
4342 const mockProtonDB = jest
4443 . spyOn ( ProtonDB , 'getInfoFromProtonDB' )
4544 . mockResolvedValue ( testProtonDBInfo )
45+ const mockSteamDeck = jest
46+ . spyOn ( SteamDeck , 'getSteamDeckComp' )
47+ . mockResolvedValue ( testSteamCompat )
4648
4749 wikiGameInfoStore . set ( 'The Witcher 3' , testExtraGameInfo )
50+ Object . defineProperty ( mockConstants , 'isMac' , { value : true } )
51+ Object . defineProperty ( mockConstants , 'isLinux' , { value : true } )
4852
4953 const result = await getWikiGameInfo ( 'The Witcher 3' , '1234' , 'gog' )
5054 expect ( result ) . toStrictEqual ( testExtraGameInfo )
@@ -53,12 +57,15 @@ describe('getWikiGameInfo', () => {
5357 expect ( mockHowLongToBeat ) . not . toBeCalled ( )
5458 expect ( mockGamesDB ) . not . toBeCalled ( )
5559 expect ( mockProtonDB ) . not . toBeCalled ( )
60+ expect ( mockSteamDeck ) . not . toBeCalled ( )
5661 } )
5762
5863 test ( 'cached data outdated' , async ( ) => {
5964 const oneMonthAgo = new Date ( testExtraGameInfo . timestampLastFetch )
6065 oneMonthAgo . setMonth ( oneMonthAgo . getMonth ( ) - 1 )
6166
67+ Object . defineProperty ( mockConstants , 'isMac' , { value : true } )
68+ Object . defineProperty ( mockConstants , 'isLinux' , { value : true } )
6269 const mockPCGamingWiki = jest
6370 . spyOn ( PCGamingWiki , 'getInfoFromPCGamingWiki' )
6471 . mockResolvedValue ( testPCGamingWikiInfo )
@@ -74,29 +81,119 @@ describe('getWikiGameInfo', () => {
7481 const mockProtonDB = jest
7582 . spyOn ( ProtonDB , 'getInfoFromProtonDB' )
7683 . mockResolvedValue ( testProtonDBInfo )
84+ const mockSteamDeck = jest
85+ . spyOn ( SteamDeck , 'getSteamDeckComp' )
86+ . mockResolvedValue ( testSteamCompat )
7787
7888 wikiGameInfoStore . set ( 'The Witcher 3' , {
7989 ...testExtraGameInfo ,
8090 timestampLastFetch : oneMonthAgo . toString ( )
8191 } )
8292
83- const result = await await getWikiGameInfo ( 'The Witcher 3' , '1234' , 'gog' )
93+ const result = await getWikiGameInfo ( 'The Witcher 3' , '1234' , 'gog' )
8494 expect ( result ) . toStrictEqual ( testExtraGameInfo )
8595 expect ( mockPCGamingWiki ) . toBeCalled ( )
8696 expect ( mockAppleGamingWiki ) . toBeCalled ( )
8797 expect ( mockHowLongToBeat ) . toBeCalled ( )
8898 expect ( mockGamesDB ) . toBeCalled ( )
8999 expect ( mockProtonDB ) . toBeCalled ( )
100+ expect ( mockProtonDB ) . toBeCalledWith ( '100' )
101+ expect ( mockSteamDeck ) . toBeCalled ( )
102+ expect ( mockSteamDeck ) . toBeCalledWith ( '100' )
90103 } )
91104
105+ test ( 'fallback to gamesdb steamID' , async ( ) => {
106+ const oneMonthAgo = new Date ( testExtraGameInfo . timestampLastFetch )
107+ oneMonthAgo . setMonth ( oneMonthAgo . getMonth ( ) - 1 )
108+
109+ Object . defineProperty ( mockConstants , 'isMac' , { value : true } )
110+ Object . defineProperty ( mockConstants , 'isLinux' , { value : true } )
111+ const mockPCGamingWiki = jest
112+ . spyOn ( PCGamingWiki , 'getInfoFromPCGamingWiki' )
113+ . mockResolvedValue ( { ...testPCGamingWikiInfo , steamID : '' } )
114+ const mockAppleGamingWiki = jest
115+ . spyOn ( AppleGamingWiki , 'getInfoFromAppleGamingWiki' )
116+ . mockResolvedValue ( testAppleGamingWikiInfo )
117+ const mockHowLongToBeat = jest
118+ . spyOn ( HowLongToBeat , 'getHowLongToBeat' )
119+ . mockResolvedValue ( testHowLongToBeat )
120+ const mockGamesDB = jest
121+ . spyOn ( GamesDB , 'getInfoFromGamesDB' )
122+ . mockResolvedValue ( testGamesDBInfo )
123+ const mockProtonDB = jest
124+ . spyOn ( ProtonDB , 'getInfoFromProtonDB' )
125+ . mockResolvedValue ( testProtonDBInfo )
126+ const mockSteamDeck = jest
127+ . spyOn ( SteamDeck , 'getSteamDeckComp' )
128+ . mockResolvedValue ( testSteamCompat )
129+
130+ wikiGameInfoStore . set ( 'The Witcher 3' , {
131+ ...testExtraGameInfo ,
132+ timestampLastFetch : oneMonthAgo . toString ( )
133+ } )
134+
135+ const result = await getWikiGameInfo ( 'The Witcher 3' , '1234' , 'gog' )
136+ expect ( result ) . toStrictEqual ( {
137+ ...testExtraGameInfo ,
138+ pcgamingwiki : { ...testPCGamingWikiInfo , steamID : '' }
139+ } )
140+ expect ( mockPCGamingWiki ) . toBeCalled ( )
141+ expect ( mockAppleGamingWiki ) . toBeCalled ( )
142+ expect ( mockHowLongToBeat ) . toBeCalled ( )
143+ expect ( mockGamesDB ) . toBeCalled ( )
144+ expect ( mockProtonDB ) . toBeCalled ( )
145+ expect ( mockProtonDB ) . toBeCalledWith ( '123' )
146+ expect ( mockSteamDeck ) . toBeCalled ( )
147+ expect ( mockSteamDeck ) . toBeCalledWith ( '123' )
148+ } )
149+
150+ test ( 'cached data outdated - not mac not linux' , async ( ) => {
151+ const oneMonthAgo = new Date ( testExtraGameInfo . timestampLastFetch )
152+ oneMonthAgo . setMonth ( oneMonthAgo . getMonth ( ) - 1 )
153+
154+ Object . defineProperty ( mockConstants , 'isMac' , { value : false } )
155+ Object . defineProperty ( mockConstants , 'isLinux' , { value : false } )
156+ const mockPCGamingWiki = jest
157+ . spyOn ( PCGamingWiki , 'getInfoFromPCGamingWiki' )
158+ . mockResolvedValue ( testPCGamingWikiInfo )
159+ const mockAppleGamingWiki = jest
160+ . spyOn ( AppleGamingWiki , 'getInfoFromAppleGamingWiki' )
161+ . mockResolvedValue ( testAppleGamingWikiInfo )
162+ const mockHowLongToBeat = jest
163+ . spyOn ( HowLongToBeat , 'getHowLongToBeat' )
164+ . mockResolvedValue ( testHowLongToBeat )
165+ const mockGamesDB = jest
166+ . spyOn ( GamesDB , 'getInfoFromGamesDB' )
167+ . mockResolvedValue ( testGamesDBInfo )
168+ const mockProtonDB = jest
169+ . spyOn ( ProtonDB , 'getInfoFromProtonDB' )
170+ . mockResolvedValue ( null )
171+ const mockSteamDeck = jest
172+ . spyOn ( SteamDeck , 'getSteamDeckComp' )
173+ . mockResolvedValue ( null )
174+
175+ wikiGameInfoStore . set ( 'The Witcher 3' , {
176+ ...testExtraGameInfo ,
177+ timestampLastFetch : oneMonthAgo . toString ( )
178+ } )
179+
180+ const result = await getWikiGameInfo ( 'The Witcher 3' , '1234' , 'gog' )
181+ expect ( result ) . toStrictEqual ( testExtraGameInfoNoMac )
182+ expect ( mockPCGamingWiki ) . toBeCalled ( )
183+ expect ( mockAppleGamingWiki ) . not . toBeCalled ( )
184+ expect ( mockHowLongToBeat ) . toBeCalled ( )
185+ expect ( mockGamesDB ) . toBeCalled ( )
186+ expect ( mockProtonDB ) . not . toBeCalled ( )
187+ expect ( mockSteamDeck ) . not . toBeCalled ( )
188+ } )
92189 test ( 'catches throws' , async ( ) => {
93190 jest
94191 . spyOn ( PCGamingWiki , 'getInfoFromPCGamingWiki' )
95192 . mockRejectedValueOnce ( new Error ( 'Failed' ) )
96193
97194 wikiGameInfoStore . clear ( )
98195
99- const result = await await getWikiGameInfo ( 'The Witcher 3' , '1234' , 'gog' )
196+ const result = await getWikiGameInfo ( 'The Witcher 3' , '1234' , 'gog' )
100197 expect ( result ) . toBeNull ( )
101198 expect ( logError ) . toBeCalledWith (
102199 [
@@ -154,11 +251,29 @@ const testProtonDBInfo = {
154251 level : 'platinum'
155252} as ProtonDBCompatibilityInfo
156253
254+ const testSteamCompat = {
255+ category : 1
256+ } as SteamDeckComp
257+
258+ const testSteamInfo = {
259+ compatibilityLevel : testProtonDBInfo . level ,
260+ steamDeckCatagory : testSteamCompat . category
261+ } as SteamInfo
262+
157263const testExtraGameInfo = {
158264 timestampLastFetch : currentTime . toString ( ) ,
159265 pcgamingwiki : testPCGamingWikiInfo ,
160266 applegamingwiki : testAppleGamingWikiInfo ,
161267 howlongtobeat : testHowLongToBeat ,
162268 gamesdb : testGamesDBInfo ,
163- protondb : testProtonDBInfo
269+ steamInfo : testSteamInfo
270+ } as WikiInfo
271+
272+ const testExtraGameInfoNoMac = {
273+ timestampLastFetch : currentTime . toString ( ) ,
274+ pcgamingwiki : testPCGamingWikiInfo ,
275+ applegamingwiki : null ,
276+ howlongtobeat : testHowLongToBeat ,
277+ gamesdb : testGamesDBInfo ,
278+ steamInfo : null
164279} as WikiInfo
0 commit comments