2020-01-17 03:06:28 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\Teams;
|
|
|
|
|
|
|
|
use Tests\E2E\Client;
|
|
|
|
|
|
|
|
trait TeamsBaseServer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @depends testCreateTeam
|
|
|
|
*/
|
2020-01-20 09:02:50 +13:00
|
|
|
public function testGetTeamMemberships($data):array
|
2020-01-17 03:06:28 +13:00
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['teamUid'] ?? '';
|
2020-01-17 03:06:28 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-02-17 20:16:11 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/'.$id.'/memberships', array_merge([
|
2020-01-17 03:06:28 +13:00
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-17 03:06:28 +13:00
|
|
|
], $this->getHeaders()));
|
2020-01-20 09:02:50 +13:00
|
|
|
|
2020-01-17 03:06:28 +13:00
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-06-08 20:01:11 +12:00
|
|
|
$this->assertEquals(0, $response['body']['sum']);
|
2020-01-17 03:06:28 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
|
2020-10-28 08:48:38 +13:00
|
|
|
return [];
|
2020-01-17 03:06:28 +13:00
|
|
|
}
|
2020-07-11 00:57:30 +12:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateTeam
|
|
|
|
*/
|
|
|
|
public function testCreateTeamMembership($data):array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$teamUid = $data['teamUid'] ?? '';
|
|
|
|
$teamName = $data['teamName'] ?? '';
|
2020-07-11 00:57:30 +12:00
|
|
|
$email = uniqid().'friend@localhost.test';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $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']['$id']);
|
|
|
|
$this->assertNotEmpty($response['body']['userId']);
|
|
|
|
$this->assertNotEmpty($response['body']['teamId']);
|
|
|
|
$this->assertCount(2, $response['body']['roles']);
|
|
|
|
$this->assertIsInt($response['body']['joined']);
|
|
|
|
$this->assertGreaterThan(0, $response['body']['joined']);
|
|
|
|
$this->assertEquals(true, $response['body']['confirm']);
|
|
|
|
|
|
|
|
$userUid = $response['body']['userId'];
|
|
|
|
|
|
|
|
// $response = $this->client->call(Client::METHOD_GET, '/users/'.$userUid, array_merge([
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
// 'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
// ], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
// $this->assertEquals($userUid, $response['body']['$id']);
|
|
|
|
// $this->assertContains('team:'.$teamUid, $response['body']['roles']);
|
|
|
|
// $this->assertContains('team:'.$teamUid.'/admin', $response['body']['roles']);
|
|
|
|
// $this->assertContains('team:'.$teamUid.'/editor', $response['body']['roles']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'email' => 'dasdkaskdjaskdjasjkd',
|
|
|
|
'name' => 'Friend User',
|
|
|
|
'roles' => ['admin', 'editor'],
|
|
|
|
'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()['$id'],
|
|
|
|
], $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()['$id'],
|
|
|
|
], $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,
|
|
|
|
'userUid' => $userUid,
|
|
|
|
];
|
|
|
|
}
|
2020-01-17 03:06:28 +13:00
|
|
|
}
|