diff --git a/src/Requests/GetRecentlyPlayedGamesRequest.php b/src/Requests/GetRecentlyPlayedGamesRequest.php index 678bc55..9f80639 100644 --- a/src/Requests/GetRecentlyPlayedGamesRequest.php +++ b/src/Requests/GetRecentlyPlayedGamesRequest.php @@ -37,6 +37,11 @@ public function defaultQuery(): array public function createDtoFromResponse(Response $response): Collection { - return new Collection(RecentlyPlayedApp::collect($response->json('response.games'))); + $games = $response->json('response.games'); + if ($games !== null) { + return new Collection(RecentlyPlayedApp::collect($games)); + } else { + return new Collection; + } } } diff --git a/tests/Datasets/users.php b/tests/Datasets/users.php index 3abfb15..669f19a 100644 --- a/tests/Datasets/users.php +++ b/tests/Datasets/users.php @@ -3,3 +3,7 @@ dataset('userids', function (): iterable { yield 'Gummibeer' => 76561198061912622; }); + +dataset('privateuserids', function (): iterable { + yield 'Rabscuttle' => 76561197960287930; +}); diff --git a/tests/Feature/Requests/GetRecentlyPlayedGamesRequestTest.php b/tests/Feature/Requests/GetRecentlyPlayedGamesRequestTest.php index b62e37b..9db9263 100644 --- a/tests/Feature/Requests/GetRecentlyPlayedGamesRequestTest.php +++ b/tests/Feature/Requests/GetRecentlyPlayedGamesRequestTest.php @@ -10,3 +10,10 @@ Assert::assertContainsOnlyInstancesOf(RecentlyPlayedApp::class, $apps); })->with('userids'); + +it('returns an empty collection', function (string $steamid): void { + $apps = app(SteamConnector::class)->getRecentlyPlayedGames(steamid: $steamid); + + Assert::assertEmpty($apps); + +})->with('privateuserids'); diff --git a/tests/Fixtures/Saloon/api.steampowered.com/GET/IPlayerService/GetRecentlyPlayedGames/v1/steamid=76561197960287930.json b/tests/Fixtures/Saloon/api.steampowered.com/GET/IPlayerService/GetRecentlyPlayedGames/v1/steamid=76561197960287930.json new file mode 100644 index 0000000..5bca6ff --- /dev/null +++ b/tests/Fixtures/Saloon/api.steampowered.com/GET/IPlayerService/GetRecentlyPlayedGames/v1/steamid=76561197960287930.json @@ -0,0 +1,14 @@ +{ + "statusCode": 200, + "headers": { + "Server": "nginx", + "Content-Type": "application\/json; charset=UTF-8", + "X-eresult": "15", + "Expires": "Sat, 07 Feb 2026 23:24:13 GMT", + "Date": "Sat, 07 Feb 2026 23:24:13 GMT", + "Content-Length": "15", + "Connection": "keep-alive" + }, + "data": "{\"response\":{}}", + "context": [] +} \ No newline at end of file