1
0
Fork 0
mirror of synced 2024-06-02 19:04:49 +12:00
appwrite/tests/e2e/Services/Teams/TeamsBaseClient.php

204 lines
7.7 KiB
PHP
Raw Normal View History

2020-01-17 03:06:28 +13:00
<?php
namespace Tests\E2E\Services\Teams;
use Tests\E2E\Client;
trait TeamsBaseClient
{
/**
* @depends testCreateTeam
*/
public function testGetTeamMembers($data):array
{
2020-01-20 01:22:54 +13:00
$teamUid = (isset($data['teamUid'])) ? $data['teamUid'] : '';
2020-01-17 03:06:28 +13:00
/**
* Test for SUCCESS
*/
2020-01-20 01:22:54 +13:00
$response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/members', array_merge([
2020-01-17 03:06:28 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()));
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body'][0]['$uid']);
$this->assertEquals($this->getUser()['$uid'], $response['body'][0]['$uid']);
$this->assertEquals($this->getUser()['name'], $response['body'][0]['name']);
$this->assertEquals($this->getUser()['email'], $response['body'][0]['email']);
$this->assertEquals('owner', $response['body'][0]['roles'][0]);
/**
* Test for FAILURE
*/
2020-01-20 01:22:54 +13:00
return $data;
2020-01-17 03:06:28 +13:00
}
2020-01-19 09:02:47 +13:00
/**
* @depends testCreateTeam
*/
public function testCreateTeamMembership($data):array
{
2020-01-20 01:22:54 +13:00
$teamUid = (isset($data['teamUid'])) ? $data['teamUid'] : '';
$teamName = (isset($data['teamName'])) ? $data['teamName'] : '';
2020-01-19 09:02:47 +13:00
$email = uniqid().'friend@localhost.test';
/**
* Test for SUCCESS
*/
2020-01-20 01:22:54 +13:00
$response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([
2020-01-19 09:02:47 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), [
'email' => $email,
'name' => 'Friend User',
'roles' => ['admin', 'editor'],
'url' => 'http://localhost:5000/join-us#title'
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$uid']);
$this->assertNotEmpty($response['body']['userId']);
$this->assertNotEmpty($response['body']['teamId']);
$this->assertCount(2, $response['body']['roles']);
$this->assertIsInt($response['body']['joined']);
$this->assertEquals(false, $response['body']['confirm']);
2020-01-20 01:22:54 +13:00
$lastEmail = $this->getLastEmail();
$this->assertEquals($email, $lastEmail['to'][0]['address']);
$this->assertEquals('Friend User', $lastEmail['to'][0]['name']);
$this->assertEquals('Invitation to '.$teamName.' Team at '.$this->getProject()['name'], $lastEmail['subject']);
$secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
$inviteUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?inviteId=', 0) + 10, 13);
$userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13);
2020-01-19 09:02:47 +13:00
/**
* Test for FAILURE
*/
2020-01-20 01:22:54 +13:00
$response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([
2020-01-19 23:43:06 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), [
'email' => 'dasdkaskdjaskdjasjkd',
'name' => 'Friend User',
'roles' => ['admin', 'editor'],
'url' => 'http://localhost:5000/join-us#title'
]);
$this->assertEquals(400, $response['headers']['status-code']);
2020-01-19 09:02:47 +13:00
2020-01-20 01:22:54 +13:00
$response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), [
'email' => $email,
'name' => 'Friend User',
'roles' => 'bad string',
'url' => 'http://localhost:5000/join-us#title'
]);
$this->assertEquals(400, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), [
'email' => $email,
'name' => 'Friend User',
'roles' => ['admin', 'editor'],
'url' => 'http://example.com/join-us#title' // bad url
]);
$this->assertEquals(400, $response['headers']['status-code']);
return [
'teamUid' => $teamUid,
'secret' => $secret,
'inviteUid' => $inviteUid,
'userUid' => $userUid,
];
}
/**
* @depends testCreateTeamMembership
*/
public function testUpdateTeamMembership($data):array
{
$teamUid = (isset($data['teamUid'])) ? $data['teamUid'] : '';
$secret = (isset($data['secret'])) ? $data['secret'] : '';
$inviteUid = (isset($data['inviteUid'])) ? $data['inviteUid'] : '';
$userUid = (isset($data['userUid'])) ? $data['userUid'] : '';
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$inviteUid.'/status', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
]), [
'secret' => $secret,
'userId' => $userUid,
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$uid']);
$this->assertNotEmpty($response['body']['userId']);
$this->assertNotEmpty($response['body']['teamId']);
$this->assertCount(2, $response['body']['roles']);
$this->assertIsInt($response['body']['joined']);
$this->assertEquals(true, $response['body']['confirm']);
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$inviteUid.'/status', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
]), [
'secret' => 'sdasdasd',
'userId' => $userUid,
]);
$this->assertEquals(401, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$inviteUid.'/status', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
]), [
'secret' => '',
'userId' => $userUid,
]);
$this->assertEquals(400, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$inviteUid.'/status', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
]), [
'secret' => $secret,
'userId' => 'sdasd',
]);
$this->assertEquals(401, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$inviteUid.'/status', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
]), [
'secret' => $secret,
'userId' => '',
]);
$this->assertEquals(400, $response['headers']['status-code']);
2020-01-19 09:02:47 +13:00
return [];
}
2020-01-17 03:06:28 +13:00
}