2020-01-12 02:58:02 +13:00
|
|
|
<?php
|
|
|
|
|
2020-01-12 19:35:37 +13:00
|
|
|
namespace Tests\E2E\Services\Account;
|
2020-01-12 02:58:02 +13:00
|
|
|
|
2023-01-12 01:24:37 +13:00
|
|
|
use Appwrite\Extend\Exception;
|
2023-08-24 05:12:43 +12:00
|
|
|
use Tests\E2E\Client;
|
2020-01-12 02:58:02 +13:00
|
|
|
use Tests\E2E\Scopes\ProjectConsole;
|
2023-08-24 05:12:43 +12:00
|
|
|
use Tests\E2E\Scopes\Scope;
|
2020-01-12 02:58:02 +13:00
|
|
|
use Tests\E2E\Scopes\SideClient;
|
2023-02-06 09:07:46 +13:00
|
|
|
use Utopia\Database\Helpers\ID;
|
2023-08-05 07:15:32 +12:00
|
|
|
use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
class AccountConsoleClientTest extends Scope
|
|
|
|
{
|
2023-01-12 01:39:56 +13:00
|
|
|
use AccountBase;
|
2020-01-12 02:58:02 +13:00
|
|
|
use ProjectConsole;
|
|
|
|
use SideClient;
|
2023-01-12 01:24:37 +13:00
|
|
|
|
|
|
|
public function testCreateAccountWithInvite(): void
|
|
|
|
{
|
2023-08-24 05:12:43 +12:00
|
|
|
$email = uniqid().'user@localhost.test';
|
2023-01-12 01:24:37 +13:00
|
|
|
$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,
|
2023-08-24 05:12:43 +12:00
|
|
|
'code' => 'Invalid Code',
|
2023-01-12 01:24:37 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
2023-01-20 00:56:41 +13:00
|
|
|
$this->assertEquals($response['body']['type'], Exception::USER_INVALID_CODE);
|
2023-01-12 01:24:37 +13:00
|
|
|
|
|
|
|
$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);
|
2023-01-20 01:11:15 +13:00
|
|
|
$this->assertEquals($response['body']['type'], Exception::USER_INVALID_CODE);
|
2023-01-12 01:24:37 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
2023-08-24 05:12:43 +12:00
|
|
|
'code' => 'code-zero',
|
2023-01-12 01:24:37 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['registration']));
|
2023-01-12 01:24:37 +13:00
|
|
|
$this->assertEquals($response['body']['email'], $email);
|
|
|
|
$this->assertEquals($response['body']['name'], $name);
|
|
|
|
|
2023-08-24 05:12:43 +12:00
|
|
|
$email = uniqid().'user@localhost.test';
|
2023-01-12 01:24:37 +13:00
|
|
|
$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,
|
2023-08-24 05:12:43 +12:00
|
|
|
'code' => 'code-one',
|
2023-01-12 01:24:37 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['registration']));
|
2023-01-12 01:24:37 +13:00
|
|
|
$this->assertEquals($response['body']['email'], $email);
|
|
|
|
$this->assertEquals($response['body']['name'], $name);
|
|
|
|
}
|
2022-05-24 02:54:50 +12:00
|
|
|
}
|