diff --git a/app/Service/AffixGroup/AffixGroupEaseTierService.php b/app/Service/AffixGroup/AffixGroupEaseTierService.php index 372c0cbf0..2d3030007 100644 --- a/app/Service/AffixGroup/AffixGroupEaseTierService.php +++ b/app/Service/AffixGroup/AffixGroupEaseTierService.php @@ -9,6 +9,7 @@ use App\Models\Dungeon; use App\Service\AffixGroup\Logging\AffixGroupEaseTierServiceLoggingInterface; use App\Service\Season\SeasonServiceInterface; +use Carbon\Exceptions\InvalidFormatException; use Illuminate\Support\Carbon; use Illuminate\Support\Collection; @@ -72,7 +73,13 @@ public function parseTierList(array $tierListsResponse): ?AffixGroupEaseTierPull $result = null; $tiersHash = $this->getTiersHash($tierListsResponse, array_flip(self::DUNGEON_NAME_MAPPING)); - $lastUpdatedAt = Carbon::createFromFormat(self::DATE_TIME_FORMAT, $tierListsResponse['lastUpdated']); + try { + $lastUpdatedAt = Carbon::createFromFormat(self::DATE_TIME_FORMAT, $tierListsResponse['lastUpdated']); + } catch (InvalidFormatException $exception) { + $this->log->parseTierListInvalidLastUpdated($exception, $tierListsResponse['lastUpdated']); + + return null; + } if ($lastEaseTierPull === null || $lastEaseTierPull->created_at->isBefore($lastUpdatedAt) || diff --git a/app/Service/AffixGroup/Logging/AffixGroupEaseTierServiceLogging.php b/app/Service/AffixGroup/Logging/AffixGroupEaseTierServiceLogging.php index 58c21698c..c341a8f05 100644 --- a/app/Service/AffixGroup/Logging/AffixGroupEaseTierServiceLogging.php +++ b/app/Service/AffixGroup/Logging/AffixGroupEaseTierServiceLogging.php @@ -3,6 +3,7 @@ namespace App\Service\AffixGroup\Logging; use App\Logging\RollbarStructuredLogging; +use Exception; class AffixGroupEaseTierServiceLogging extends RollbarStructuredLogging implements AffixGroupEaseTierServiceLoggingInterface { @@ -11,6 +12,11 @@ public function parseTierListUnknownAffixGroup(string $affixGroupString): void $this->error(__METHOD__, get_defined_vars()); } + public function parseTierListInvalidLastUpdated(Exception $exception, string $lastUpdated): void + { + $this->error(__METHOD__, get_defined_vars()); + } + public function parseTierListParseTierStart(string $affixGroupString, string $tier, int $count): void { $this->start(__METHOD__, get_defined_vars()); diff --git a/app/Service/AffixGroup/Logging/AffixGroupEaseTierServiceLoggingInterface.php b/app/Service/AffixGroup/Logging/AffixGroupEaseTierServiceLoggingInterface.php index b771011dd..f99588c13 100644 --- a/app/Service/AffixGroup/Logging/AffixGroupEaseTierServiceLoggingInterface.php +++ b/app/Service/AffixGroup/Logging/AffixGroupEaseTierServiceLoggingInterface.php @@ -2,10 +2,14 @@ namespace App\Service\AffixGroup\Logging; +use Exception; + interface AffixGroupEaseTierServiceLoggingInterface { public function parseTierListUnknownAffixGroup(string $affixGroupString): void; + public function parseTierListInvalidLastUpdated(Exception $exception, string $lastUpdated): void; + public function parseTierListParseTierStart(string $affixGroupString, string $tier, int $count): void; public function parseTierListUnknownDungeon(string $dungeonName): void; diff --git a/tests/Feature/App/Service/AffixGroup/AffixGroupEaseTierServiceTest.php b/tests/Feature/App/Service/AffixGroup/AffixGroupEaseTierServiceTest.php index 7fc5c1048..0b9de69be 100644 --- a/tests/Feature/App/Service/AffixGroup/AffixGroupEaseTierServiceTest.php +++ b/tests/Feature/App/Service/AffixGroup/AffixGroupEaseTierServiceTest.php @@ -20,7 +20,7 @@ final class AffixGroupEaseTierServiceTest extends PublicTestCase * @throws Throwable */ #[Test] - #[Group('AffixGroupEaseTierService2')] + #[Group('AffixGroupEaseTierService')] public function parseTierList_GivenCorrectResponseWithNoExistingPulls_ShouldCreateNewPull(): void { // Arrange @@ -188,6 +188,33 @@ public function parseTierList_GivenResponseWithDifferentAffixes_ShouldCreateNewP $this->assertNotEquals($previousAffixGroupEaseTierPull->tiers_hash, $result->tiers_hash); } + /** + * @throws Exception + */ + #[Test] + #[Group('AffixGroupEaseTierService')] + public function parseTierList_GivenResponseWithInvalidLastUpdated_ShouldLogUnknownLastUpdatedError(): void + { + // Arrange + $responseDifferentAffix = $this->getResponse('response_invalid_last_updated'); + + $log = LoggingFixtures::createAffixGroupEaseTierServiceLogging($this); + $affixGroupEaseTierService = ServiceFixtures::getAffixGroupEaseTierServiceMock( + $this, + null, + $log + ); + + $log->expects($this->once()) + ->method('parseTierListInvalidLastUpdated'); + + // Act + $result = $affixGroupEaseTierService->parseTierList($responseDifferentAffix); + + // Assert + $this->assertNull($result); + } + /** * @throws Exception */ diff --git a/tests/Feature/App/Service/AffixGroup/Fixtures/response.json b/tests/Feature/App/Service/AffixGroup/Fixtures/response.json index 22133e16a..6bbdda330 100644 --- a/tests/Feature/App/Service/AffixGroup/Fixtures/response.json +++ b/tests/Feature/App/Service/AffixGroup/Fixtures/response.json @@ -81,5 +81,6 @@ ] } ] - } + }, + "lastUpdated": "2024-06-05T12:00:00Z" } diff --git a/tests/Feature/App/Service/AffixGroup/Fixtures/response_different_affix.json b/tests/Feature/App/Service/AffixGroup/Fixtures/response_different_affix.json index d65765fd2..559547154 100644 --- a/tests/Feature/App/Service/AffixGroup/Fixtures/response_different_affix.json +++ b/tests/Feature/App/Service/AffixGroup/Fixtures/response_different_affix.json @@ -81,5 +81,6 @@ ] } ] - } + }, + "lastUpdated": "2024-06-05T12:00:00Z" } diff --git a/tests/Feature/App/Service/AffixGroup/Fixtures/response_invalid_last_updated.json b/tests/Feature/App/Service/AffixGroup/Fixtures/response_invalid_last_updated.json new file mode 100644 index 000000000..8a8814e7b --- /dev/null +++ b/tests/Feature/App/Service/AffixGroup/Fixtures/response_invalid_last_updated.json @@ -0,0 +1,86 @@ +{ + "difficulty": { + "slug": "20" + }, + "affixes": { + "slug": "this-week" + }, + "encounterTierList": { + "title": "Dungeon Ease Tier List for +20 to +32 Mythic+", + "label": "Fortified, Entangling, Bolstering", + "metrics": [ + { + "value": "score", + "label": "Mythic+ Score" + } + ], + "tierLists": [ + { + "metric": "score", + "tiers": [ + { + "tier": "S", + "entries": [ + { + "id": 61501, + "name": "Black Rook Hold", + "url": "/wow/tier-list/dps-rankings/mythic-plus/20/black-rook-hold/this-week" + } + ] + }, + { + "tier": "A", + "entries": [ + { + "id": 61763, + "name": "Atal'Dazar", + "url": "/wow/tier-list/dps-rankings/mythic-plus/20/ataldazar/this-week" + }, + { + "id": 12579, + "name": "Galakrond's Fall", + "url": "/wow/tier-list/dps-rankings/mythic-plus/20/galakronds-fall/this-week" + }, + { + "id": 61862, + "name": "Waycrest Manor", + "url": "/wow/tier-list/dps-rankings/mythic-plus/20/waycrest-manor/this-week" + } + ] + }, + { + "tier": "B", + "entries": [ + { + "id": 61466, + "name": "Darkheart Thicket", + "url": "/wow/tier-list/dps-rankings/mythic-plus/20/darkheart-thicket/this-week" + } + ] + }, + { + "tier": "C", + "entries": [ + { + "id": 10643, + "name": "Wrathion's Expedition", + "url": "/wow/tier-list/dps-rankings/mythic-plus/20/wrathions-expedition/this-week" + }, + { + "id": 12580, + "name": "Murozond's Rise", + "url": "/wow/tier-list/dps-rankings/mythic-plus/20/murozonds-rise/this-week" + }, + { + "id": 61279, + "name": "Everbloom", + "url": "/wow/tier-list/dps-rankings/mythic-plus/20/everbloom/this-week" + } + ] + } + ] + } + ] + }, + "lastUpdated": "some incorrect string" +} diff --git a/tests/Feature/App/Service/AffixGroup/Fixtures/response_unknown_affix.json b/tests/Feature/App/Service/AffixGroup/Fixtures/response_unknown_affix.json index 5210016bc..885f4400d 100644 --- a/tests/Feature/App/Service/AffixGroup/Fixtures/response_unknown_affix.json +++ b/tests/Feature/App/Service/AffixGroup/Fixtures/response_unknown_affix.json @@ -81,5 +81,6 @@ ] } ] - } + }, + "lastUpdated": "2024-06-05T12:00:00Z" } diff --git a/tests/Feature/App/Service/AffixGroup/Fixtures/response_unknown_dungeon.json b/tests/Feature/App/Service/AffixGroup/Fixtures/response_unknown_dungeon.json index 6e0870829..08a14a338 100644 --- a/tests/Feature/App/Service/AffixGroup/Fixtures/response_unknown_dungeon.json +++ b/tests/Feature/App/Service/AffixGroup/Fixtures/response_unknown_dungeon.json @@ -81,5 +81,6 @@ ] } ] - } + }, + "lastUpdated": "2024-06-05T12:00:00Z" }