fix: use server-minted matchId in smoke test actions
This commit is contained in:
@@ -15,7 +15,6 @@ use PHPUnit\Framework\TestCase;
|
||||
final class PostMatchActionSmokeTest extends TestCase
|
||||
{
|
||||
private const SECRET = 'e2e-smoke-secret';
|
||||
private const MATCH_ID = '0123456789abcdef';
|
||||
private const BASE_URL = 'http://127.0.0.1:8765';
|
||||
private const CSRF_COOKIE_NAME = '__csrf';
|
||||
|
||||
@@ -60,14 +59,15 @@ final class PostMatchActionSmokeTest extends TestCase
|
||||
$matchId = $startResponse['body']['matchId'] ?? null;
|
||||
$turnToken = $startResponse['body']['turnToken'] ?? null;
|
||||
self::assertIsArray($match);
|
||||
self::assertSame(self::MATCH_ID, $matchId);
|
||||
self::assertIsString($matchId);
|
||||
self::assertMatchesRegularExpression('/^[a-f0-9]{16,}$/', $matchId);
|
||||
self::assertMatchesRegularExpression('/^[a-f0-9]{32}$/', $turnToken);
|
||||
|
||||
for ($i = 0; $i < 200; $i += 1) {
|
||||
if (!empty($match['winnerTeamId'])) {
|
||||
break;
|
||||
}
|
||||
$action = $this->pickAction($match);
|
||||
$action = $this->pickAction($match, $matchId);
|
||||
$response = $this->postJson("/matches/current/{$action['verb']}", $action['body']);
|
||||
$errMsg = "Step {$i} verb={$action['verb']} failed: " . ($response['body']['error'] ?? '');
|
||||
self::assertSame(200, $response['status'], $errMsg);
|
||||
@@ -83,10 +83,11 @@ final class PostMatchActionSmokeTest extends TestCase
|
||||
$startResponse = $this->postJson('/scenarios/skirmish/start', $scenario);
|
||||
self::assertSame(200, $startResponse['status']);
|
||||
$match = $startResponse['body']['match'];
|
||||
$staleToken = TurnToken::issue(self::SECRET, self::MATCH_ID, 'alpha', 99, 0);
|
||||
$matchId = $startResponse['body']['matchId'];
|
||||
$staleToken = TurnToken::issue(self::SECRET, $matchId, 'alpha', 99, 0);
|
||||
|
||||
$response = $this->postJson('/matches/current/end-turn', [
|
||||
'matchId' => self::MATCH_ID,
|
||||
'matchId' => $matchId,
|
||||
'match' => $match,
|
||||
], $staleToken);
|
||||
|
||||
@@ -217,7 +218,7 @@ final class PostMatchActionSmokeTest extends TestCase
|
||||
$headers[] = 'X-Turn-Token: ' . $turnToken;
|
||||
} elseif (isset($body['match'])) {
|
||||
$match = $body['match'];
|
||||
$matchId = (string) ($body['matchId'] ?? self::MATCH_ID);
|
||||
$matchId = (string) ($body['matchId'] ?? '');
|
||||
$turnToken = TurnToken::issue(
|
||||
self::SECRET,
|
||||
$matchId,
|
||||
@@ -254,9 +255,10 @@ final class PostMatchActionSmokeTest extends TestCase
|
||||
* - if no enemy is reachable this turn, end the turn.
|
||||
*
|
||||
* @param array<string, mixed> $match
|
||||
* @param string $matchId
|
||||
* @return array{verb: string, body: array<string, mixed>}
|
||||
*/
|
||||
private function pickAction(array $match): array
|
||||
private function pickAction(array $match, string $matchId): array
|
||||
{
|
||||
$units = $match['units'];
|
||||
$active = $match['activeTeamId'];
|
||||
@@ -275,7 +277,7 @@ final class PostMatchActionSmokeTest extends TestCase
|
||||
return [
|
||||
'verb' => 'attack',
|
||||
'body' => [
|
||||
'matchId' => self::MATCH_ID,
|
||||
'matchId' => $matchId,
|
||||
'match' => $match,
|
||||
'attackerId' => $unit['id'],
|
||||
'targetId' => $other['id'],
|
||||
@@ -345,7 +347,7 @@ final class PostMatchActionSmokeTest extends TestCase
|
||||
return [
|
||||
'verb' => 'move',
|
||||
'body' => [
|
||||
'matchId' => self::MATCH_ID,
|
||||
'matchId' => $matchId,
|
||||
'match' => $match,
|
||||
'unitId' => $unit['id'],
|
||||
'x' => $c['x'],
|
||||
@@ -358,7 +360,7 @@ final class PostMatchActionSmokeTest extends TestCase
|
||||
return [
|
||||
'verb' => 'end-turn',
|
||||
'body' => [
|
||||
'matchId' => self::MATCH_ID,
|
||||
'matchId' => $matchId,
|
||||
'match' => $match,
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user