Skip to content

Commit

Permalink
#2278 Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wotuu committed Jun 6, 2024
1 parent aed1203 commit bfba187
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 6 deletions.
9 changes: 8 additions & 1 deletion app/Service/AffixGroup/AffixGroupEaseTierService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Service\AffixGroup\Logging;

use App\Logging\RollbarStructuredLogging;
use Exception;

class AffixGroupEaseTierServiceLogging extends RollbarStructuredLogging implements AffixGroupEaseTierServiceLoggingInterface
{
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class AffixGroupEaseTierServiceTest extends PublicTestCase
* @throws Throwable
*/
#[Test]
#[Group('AffixGroupEaseTierService2')]
#[Group('AffixGroupEaseTierService')]
public function parseTierList_GivenCorrectResponseWithNoExistingPulls_ShouldCreateNewPull(): void
{
// Arrange
Expand Down Expand Up @@ -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
*/
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/App/Service/AffixGroup/Fixtures/response.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@
]
}
]
}
},
"lastUpdated": "2024-06-05T12:00:00Z"
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@
]
}
]
}
},
"lastUpdated": "2024-06-05T12:00:00Z"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@
]
}
]
}
},
"lastUpdated": "2024-06-05T12:00:00Z"
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@
]
}
]
}
},
"lastUpdated": "2024-06-05T12:00:00Z"
}

0 comments on commit bfba187

Please sign in to comment.