1
0
Fork 0
mirror of synced 2024-09-17 01:47:57 +12:00
appwrite/tests/e2e/Services/Account/AccountConsoleClientTest.php

100 lines
3.5 KiB
PHP
Raw Normal View History

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;
2020-01-12 02:58:02 +13:00
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\ProjectConsole;
use Tests\E2E\Scopes\SideClient;
2023-01-12 01:24:37 +13:00
use Utopia\Database\ID;
use Utopia\Database\DateTime;
use Tests\E2E\Client;
2020-01-12 02:58:02 +13:00
class AccountConsoleClientTest extends Scope
{
2023-01-12 01:24:37 +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
{
$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_CODE_INVALID);
$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_CODE_INVALID);
/**
* 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, DateTime::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, DateTime::isValid($response['body']['registration']));
$this->assertEquals($response['body']['email'], $email);
$this->assertEquals($response['body']['name'], $name);
}
2022-05-24 02:54:50 +12:00
}