mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 00:49:02 +00:00
Merge pull request #9954 from appwrite/spr/1.7.x/3865765d
tests: fix flaky account tests
This commit is contained in:
commit
7ed1d7bd37
2 changed files with 27 additions and 17 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Tests\E2E\Scopes;
|
||||
|
||||
use Appwrite\Tests\Async;
|
||||
use Appwrite\Tests\Retryable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\E2E\Client;
|
||||
|
|
@ -10,6 +11,7 @@ use Utopia\Database\Helpers\ID;
|
|||
abstract class Scope extends TestCase
|
||||
{
|
||||
use Retryable;
|
||||
use Async;
|
||||
|
||||
protected ?Client $client = null;
|
||||
protected string $endpoint = 'http://localhost/v1';
|
||||
|
|
@ -43,6 +45,18 @@ abstract class Scope extends TestCase
|
|||
return [];
|
||||
}
|
||||
|
||||
protected function assertLastRequest(callable $probe, $timeoutMs = 20_000, $waitMs = 500): array
|
||||
{
|
||||
$this->assertEventually(function () use (&$request, $probe) {
|
||||
$request = json_decode(file_get_contents('http://request-catcher:5000/__last_request__'), true);
|
||||
$request['data'] = json_decode($request['data'], true);
|
||||
|
||||
call_user_func($probe, $request);
|
||||
}, $timeoutMs, $waitMs);
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
protected function getLastRequest(): array
|
||||
{
|
||||
sleep(2);
|
||||
|
|
|
|||
|
|
@ -2034,7 +2034,6 @@ class AccountCustomClientTest extends Scope
|
|||
$this->assertEquals($response['body']['users'][0]['email'], $email);
|
||||
}
|
||||
|
||||
#[Retry(count: 2)]
|
||||
public function testCreatePhone(): array
|
||||
{
|
||||
$number = '+123456789';
|
||||
|
|
@ -2058,17 +2057,15 @@ class AccountCustomClientTest extends Scope
|
|||
|
||||
$userId = $response['body']['userId'];
|
||||
|
||||
\sleep(7);
|
||||
|
||||
$smsRequest = $this->getLastRequest();
|
||||
|
||||
$this->assertEquals('http://request-catcher:5000/mock-sms', $smsRequest['url']);
|
||||
$this->assertEquals('Appwrite Mock Message Sender', $smsRequest['headers']['User-Agent']);
|
||||
$this->assertEquals('username', $smsRequest['headers']['X-Username']);
|
||||
$this->assertEquals('password', $smsRequest['headers']['X-Key']);
|
||||
$this->assertEquals('POST', $smsRequest['method']);
|
||||
$this->assertEquals('+123456789', $smsRequest['data']['from']);
|
||||
$this->assertEquals($number, $smsRequest['data']['to']);
|
||||
$smsRequest = $this->assertLastRequest(function (array $request) use ($number) {
|
||||
$this->assertEquals('http://request-catcher:5000/mock-sms', $request['url']);
|
||||
$this->assertEquals('Appwrite Mock Message Sender', $request['headers']['User-Agent']);
|
||||
$this->assertEquals('username', $request['headers']['X-Username']);
|
||||
$this->assertEquals('password', $request['headers']['X-Key']);
|
||||
$this->assertEquals('POST', $request['method']);
|
||||
$this->assertEquals('+123456789', $request['data']['from']);
|
||||
$this->assertEquals($number, $request['data']['to']);
|
||||
});
|
||||
|
||||
$data['token'] = $smsRequest['data']['message'];
|
||||
$data['id'] = $userId;
|
||||
|
|
@ -2396,7 +2393,6 @@ class AccountCustomClientTest extends Scope
|
|||
/**
|
||||
* @depends testUpdatePhone
|
||||
*/
|
||||
#[Retry(count: 3)]
|
||||
public function testPhoneVerification(array $data): array
|
||||
{
|
||||
$session = $data['session'] ?? '';
|
||||
|
|
@ -2416,10 +2412,10 @@ class AccountCustomClientTest extends Scope
|
|||
$this->assertEmpty($response['body']['secret']);
|
||||
$this->assertTrue((new DatetimeValidator())->isValid($response['body']['expire']));
|
||||
|
||||
$smsRequest = $this->getLastRequest();
|
||||
|
||||
$message = $smsRequest['data']['message'];
|
||||
$token = substr($message, 0, 6);
|
||||
$smsRequest = $this->assertLastRequest(function ($request) {
|
||||
$this->assertArrayHasKey('data', $request);
|
||||
$this->assertArrayHasKey('message', $request['data']);
|
||||
});
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
|
|
|
|||
Loading…
Reference in a new issue