WIP
This commit is contained in:
parent
79936b88d0
commit
7a58814c61
45
tests/e2e/General/UsageTest.php
Normal file
45
tests/e2e/General/UsageTest.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\SideServer;
|
||||
|
||||
class UsageTest extends Scope {
|
||||
use ProjectCustom;
|
||||
use SideServer;
|
||||
|
||||
protected array $headers = [];
|
||||
protected array $project;
|
||||
|
||||
protected int $usersCount = 0;
|
||||
protected int $requestsCount = 0;
|
||||
|
||||
protected function setUp(): void {
|
||||
$this->project = $this->getProject(true);
|
||||
$this->headers['x-appwrite-project'] = $this->project['$id'];
|
||||
$this->headers['x-appwrite-key'] = $this->project['apiKey'];
|
||||
$this->headers['content-type'] = 'application/json';
|
||||
|
||||
}
|
||||
|
||||
public function testUsersStats(): void
|
||||
{
|
||||
|
||||
for($i = 0; $i<10; $i++) {
|
||||
$email = uniqid() . 'user@usage.test';
|
||||
$password = 'password';
|
||||
$name = uniqid() . 'User';
|
||||
$user = $this->client->call(Client::METHOD_POST, '/users', $this->headers, [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
]);
|
||||
$this->usersCount++;
|
||||
$this->requestsCount++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -12,11 +12,12 @@ trait ProjectCustom
|
|||
protected static $project = [];
|
||||
|
||||
/**
|
||||
* @param bool $fresh
|
||||
* @return array
|
||||
*/
|
||||
public function getProject(): array
|
||||
public function getProject(bool $fresh = false): array
|
||||
{
|
||||
if (!empty(self::$project)) {
|
||||
if (!empty(self::$project) && !$fresh) {
|
||||
return self::$project;
|
||||
}
|
||||
|
||||
|
@ -115,13 +116,17 @@ trait ProjectCustom
|
|||
$this->assertEquals(201, $webhook['headers']['status-code']);
|
||||
$this->assertNotEmpty($webhook['body']);
|
||||
|
||||
self::$project = [
|
||||
$project = [
|
||||
'$id' => $project['body']['$id'],
|
||||
'name' => $project['body']['name'],
|
||||
'apiKey' => $key['body']['secret'],
|
||||
'webhookId' => $webhook['body']['$id'],
|
||||
'signatureKey' => $webhook['body']['signatureKey'],
|
||||
];
|
||||
if($fresh) {
|
||||
return $project;
|
||||
}
|
||||
self::$project = $project;
|
||||
|
||||
return self::$project;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue