fix: test phone verification flakiness

This commit is contained in:
loks0n
2024-10-15 19:17:36 +01:00
parent a49c3a33f0
commit 9a8b4187b0
2 changed files with 15 additions and 5 deletions
@@ -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';
@@ -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
]);
}