From 9a8b4187b07bec551a070edefdedb35f14fe1056 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:50:27 +0100 Subject: [PATCH] fix: test phone verification flakiness --- tests/e2e/Services/Account/AccountBase.php | 3 +++ .../Account/AccountCustomClientTest.php | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 2d72625121..9a8cd4ebc2 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -2,12 +2,15 @@ namespace Tests\E2E\Services\Account; +use Appwrite\Tests\Async; use Tests\E2E\Client; use Utopia\Database\Helpers\ID; use Utopia\Database\Validator\Datetime as DatetimeValidator; trait AccountBase { + use Async; + public function testCreateAccount(): array { $email = uniqid() . 'user@localhost.test'; diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index 244f84b161..774147d83b 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -2339,7 +2339,6 @@ class AccountCustomClientTest extends Scope /** * @depends testUpdatePhone */ - #[Retry(count: 3)] public function testPhoneVerification(array $data): array { $session = $data['session'] ?? ''; @@ -2359,13 +2358,21 @@ class AccountCustomClientTest extends Scope $this->assertEmpty($response['body']['secret']); $this->assertTrue((new DatetimeValidator())->isValid($response['body']['expire'])); - $smsRequest = $this->getLastRequest(); + $token = null; + + $this->assertEventually(function () use (&$token) { + $request = json_decode(file_get_contents('http://request-catcher:5000/__last_request__'), true); + + $body = json_decode($request['data'], true); + $this->assertArrayHasKey('message', $body); + + $token = substr($body['message'], 0, 6); + $this->assertNotEmpty($token); + }, 10000, 500); - $message = $smsRequest['data']['message']; - $token = substr($message, 0, 6); return \array_merge($data, [ - 'token' => \substr($smsRequest['data']['message'], 0, 6) + 'token' => $token ]); }