1
0
Fork 0
mirror of synced 2024-09-19 10:59:50 +12:00
appwrite/tests/e2e/Services/Account/AccountConsoleClientTest.php
2023-08-24 13:04:49 +02:00

100 lines
3.7 KiB
PHP

<?php
namespace Tests\E2E\Services\Account;
use Appwrite\Extend\Exception;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\ProjectConsole;
use Tests\E2E\Scopes\SideClient;
use Utopia\Database\Helpers\ID;
use Tests\E2E\Client;
use Utopia\Database\Validator\Datetime as DatetimeValidator;
class AccountConsoleClientTest extends Scope
{
use AccountBase;
use ProjectConsole;
use SideClient;
public function testCreateAccountWithInvite(): void
{
$email = uniqid() . 'user@localhost.test';
$password = 'password';
$name = 'User Name';
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_POST, '/account/invite', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
]), [
'userId' => ID::unique(),
'email' => $email,
'password' => $password,
'name' => $name,
'code' => 'Invalid Code'
]);
$this->assertEquals($response['headers']['status-code'], 401);
$this->assertEquals($response['body']['type'], Exception::USER_INVALID_CODE);
$response = $this->client->call(Client::METHOD_POST, '/account/invite', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
]), [
'userId' => ID::unique(),
'email' => $email,
'password' => $password,
'name' => $name,
]);
$this->assertEquals($response['headers']['status-code'], 401);
$this->assertEquals($response['body']['type'], Exception::USER_INVALID_CODE);
// Temporary disabled tests
// /**
// * Test for SUCCESS
// */
// $response = $this->client->call(Client::METHOD_POST, '/account/invite', array_merge([
// 'origin' => 'http://localhost',
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $this->getProject()['$id'],
// ]), [
// 'userId' => ID::unique(),
// 'email' => $email,
// 'password' => $password,
// 'name' => $name,
// 'code' => 'code-zero'
// ]);
// $this->assertEquals(201, $response['headers']['status-code']);
// $this->assertNotEmpty($response['body']);
// $this->assertNotEmpty($response['body']['$id']);
// $this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['registration']));
// $this->assertEquals($response['body']['email'], $email);
// $this->assertEquals($response['body']['name'], $name);
// $email = uniqid() . 'user@localhost.test';
// $response = $this->client->call(Client::METHOD_POST, '/account/invite', array_merge([
// 'origin' => 'http://localhost',
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $this->getProject()['$id'],
// ]), [
// 'userId' => ID::unique(),
// 'email' => $email,
// 'password' => $password,
// 'name' => $name,
// 'code' => 'code-one'
// ]);
// $this->assertEquals(201, $response['headers']['status-code']);
// $this->assertNotEmpty($response['body']);
// $this->assertNotEmpty($response['body']['$id']);
// $this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['registration']));
// $this->assertEquals($response['body']['email'], $email);
// $this->assertEquals($response['body']['name'], $name);
}
}