initial e2e test for usage stats
This commit is contained in:
parent
7a58814c61
commit
02f45abcb9
2
.env
2
.env
|
@ -75,7 +75,7 @@ _APP_MAINTENANCE_INTERVAL=86400
|
|||
_APP_MAINTENANCE_RETENTION_EXECUTION=1209600
|
||||
_APP_MAINTENANCE_RETENTION_ABUSE=86400
|
||||
_APP_MAINTENANCE_RETENTION_AUDIT=1209600
|
||||
_APP_USAGE_AGGREGATION_INTERVAL=30
|
||||
_APP_USAGE_AGGREGATION_INTERVAL=2
|
||||
_APP_USAGE_STATS=enabled
|
||||
_APP_LOGGING_PROVIDER=
|
||||
_APP_LOGGING_CONFIG=
|
||||
|
|
|
@ -11,17 +11,18 @@ class UsageTest extends Scope {
|
|||
use SideServer;
|
||||
|
||||
protected array $headers = [];
|
||||
protected array $project;
|
||||
protected string $projectId;
|
||||
|
||||
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'];
|
||||
parent::setUp();
|
||||
$project = $this->getProject(true);
|
||||
$this->projectId = $project['$id'];
|
||||
$this->headers['x-appwrite-project'] = $project['$id'];
|
||||
$this->headers['x-appwrite-key'] = $project['apiKey'];
|
||||
$this->headers['content-type'] = 'application/json';
|
||||
|
||||
}
|
||||
|
||||
public function testUsersStats(): void
|
||||
|
@ -31,15 +32,34 @@ class UsageTest extends Scope {
|
|||
$email = uniqid() . 'user@usage.test';
|
||||
$password = 'password';
|
||||
$name = uniqid() . 'User';
|
||||
$user = $this->client->call(Client::METHOD_POST, '/users', $this->headers, [
|
||||
$res = $this->client->call(Client::METHOD_POST, '/users', $this->headers, [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
]);
|
||||
$this->assertEquals($email, $res['body']['email']);
|
||||
$this->assertNotEmpty($res['body']['$id']);
|
||||
$this->usersCount++;
|
||||
$this->requestsCount++;
|
||||
$this->requestsCount += 2;
|
||||
}
|
||||
sleep(65);
|
||||
|
||||
// console request
|
||||
$headers = [
|
||||
'origin' => 'http://localhost',
|
||||
'x-appwrite-project' => 'console',
|
||||
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
||||
];
|
||||
|
||||
$res = $this->client->call(Client::METHOD_GET, '/projects/' . $this->projectId . '/usage?range=30d', $headers);
|
||||
$res = $res['body'];
|
||||
|
||||
$this->assertEquals(8, count($res));
|
||||
$this->assertEquals(30, count($res['requests']));
|
||||
$this->assertEquals(30, count($res['users']));
|
||||
$this->assertEquals($this->requestsCount, $res['users'][array_key_last($res['users'])]['value']);
|
||||
$this->assertEquals($this->usersCount, $res['requests'][array_key_last($res['requests'])]['value']);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue