1
0
Fork 0
mirror of synced 2024-07-03 21:50:34 +12:00
appwrite/tests/e2e/Services/Users/UsersBase.php

210 lines
7.5 KiB
PHP
Raw Normal View History

2020-01-14 07:30:13 +13:00
<?php
namespace Tests\E2E\Services\Users;
use Tests\E2E\Client;
trait UsersBase
{
2020-01-14 07:55:57 +13:00
public function testCreateUser():array
2020-01-14 07:30:13 +13:00
{
/**
* Test for SUCCESS
*/
2020-01-14 07:55:57 +13:00
$user = $this->client->call(Client::METHOD_POST, '/users', array_merge([
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-14 07:55:57 +13:00
], $this->getHeaders()), [
'email' => 'users.service@example.com',
'password' => 'password',
'name' => 'Project User',
]);
$this->assertEquals($user['headers']['status-code'], 201);
$this->assertEquals($user['body']['name'], 'Project User');
$this->assertEquals($user['body']['email'], 'users.service@example.com');
$this->assertEquals($user['body']['status'], 0);
$this->assertGreaterThan(0, $user['body']['registration']);
2020-02-17 20:16:11 +13:00
return ['userId' => $user['body']['$id']];
2020-01-14 07:55:57 +13:00
}
/**
* @depends testCreateUser
*/
public function testGetUser(array $data):array
{
/**
* Test for SUCCESS
*/
$user = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'], array_merge([
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-14 07:55:57 +13:00
], $this->getHeaders()));
$this->assertEquals($user['headers']['status-code'], 200);
$this->assertEquals($user['body']['name'], 'Project User');
$this->assertEquals($user['body']['email'], 'users.service@example.com');
$this->assertEquals($user['body']['status'], 0);
$this->assertGreaterThan(0, $user['body']['registration']);
$sessions = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/sessions', array_merge([
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-14 07:55:57 +13:00
], $this->getHeaders()));
$this->assertEquals($sessions['headers']['status-code'], 200);
$this->assertIsArray($sessions['body']);
$logs = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/logs', array_merge([
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-14 07:55:57 +13:00
], $this->getHeaders()));
$this->assertEquals($logs['headers']['status-code'], 200);
$this->assertIsArray($logs['body']);
$users = $this->client->call(Client::METHOD_GET, '/users', array_merge([
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-14 07:55:57 +13:00
], $this->getHeaders()));
$this->assertEquals($users['headers']['status-code'], 200);
$this->assertIsArray($users['body']);
$this->assertIsArray($users['body']['users']);
$this->assertIsInt($users['body']['sum']);
$this->assertGreaterThan(0, $users['body']['sum']);
$users = $this->client->call(Client::METHOD_GET, '/users', array_merge([
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-14 07:55:57 +13:00
], $this->getHeaders()), [
'search' => 'example.com'
]);
$this->assertEquals($users['headers']['status-code'], 200);
$this->assertIsArray($users['body']);
$this->assertIsArray($users['body']['users']);
$this->assertIsInt($users['body']['sum']);
$this->assertEquals(1, $users['body']['sum']);
$this->assertGreaterThan(0, $users['body']['sum']);
$this->assertCount(1, $users['body']['users']);
return $data;
}
/**
* @depends testGetUser
*/
public function testUpdateUserStatus(array $data):array
{
/**
* Test for SUCCESS
*/
$user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/status', array_merge([
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-14 07:55:57 +13:00
], $this->getHeaders()), [
'status' => 2,
]);
$this->assertEquals($user['headers']['status-code'], 200);
$this->assertEquals($user['body']['status'], 2);
$user = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'], array_merge([
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-14 07:55:57 +13:00
], $this->getHeaders()));
$this->assertEquals($user['headers']['status-code'], 200);
$this->assertEquals($user['body']['status'], 2);
return $data;
}
/**
* @depends testGetUser
*/
2021-01-11 00:56:48 +13:00
public function testUpdateAndGetUserPrefs(array $data):array
2020-01-14 07:55:57 +13:00
{
/**
* Test for SUCCESS
*/
2021-01-11 00:56:48 +13:00
$user = $this->client->call(Client::METHOD_PATCH, '/users/'.$data['userId'].'/prefs', array_merge([
2020-01-14 07:55:57 +13:00
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-14 07:55:57 +13:00
], $this->getHeaders()), [
'prefs' => [
2020-10-31 08:53:27 +13:00
'funcKey1' => 'funcValue1',
'funcKey2' => 'funcValue2',
2020-01-14 07:55:57 +13:00
],
]);
$this->assertEquals($user['headers']['status-code'], 200);
2020-10-31 08:53:27 +13:00
$this->assertEquals($user['body']['funcKey1'], 'funcValue1');
$this->assertEquals($user['body']['funcKey2'], 'funcValue2');
2020-01-14 07:55:57 +13:00
2021-01-11 00:56:48 +13:00
$user = $this->client->call(Client::METHOD_GET, '/users/'.$data['userId'].'/prefs', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals($user['headers']['status-code'], 200);
$this->assertEquals($user['body'], [
'funcKey1' => 'funcValue1',
'funcKey2' => 'funcValue2',
]);
2020-01-20 09:38:00 +13:00
/**
* Test for FAILURE
*/
$user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/prefs', array_merge([
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-20 09:38:00 +13:00
], $this->getHeaders()), [
'prefs' => 'bad-string',
]);
$this->assertEquals($user['headers']['status-code'], 400);
$user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/prefs', array_merge([
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-20 09:38:00 +13:00
], $this->getHeaders()));
$this->assertEquals($user['headers']['status-code'], 400);
2020-01-14 07:55:57 +13:00
return $data;
2020-01-14 07:30:13 +13:00
}
2020-08-29 09:56:22 +12:00
/**
* @depends testGetUser
*/
public function testDeleteUser(array $data):array
{
/**
* Test for SUCCESS
*/
$user = $this->client->call(Client::METHOD_DELETE, '/users/' . $data['userId'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals($user['headers']['status-code'], 204);
/**
* Test for FAILURE
*/
$user = $this->client->call(Client::METHOD_DELETE, '/users/' . $data['userId'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals($user['headers']['status-code'], 404);
return $data;
}
2020-01-14 07:55:57 +13:00
// TODO add test for session delete
// TODO add test for all sessions delete
2020-01-14 07:30:13 +13:00
}