1
0
Fork 0
mirror of synced 2024-06-01 18:39:57 +12:00
This commit is contained in:
Damodar Lohani 2022-06-30 04:27:11 +00:00
parent 79936b88d0
commit 7a58814c61
2 changed files with 53 additions and 3 deletions

View 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++;
}
}
}

View file

@ -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;
}