2020-01-17 03:06:28 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\Teams;
|
|
|
|
|
|
|
|
use Tests\E2E\Client;
|
2023-03-02 01:00:36 +13:00
|
|
|
use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
Fixed an incorrect test for team deletion
This commit contains changes in 3 places.
- First I changed the placement of an informative comment in the DELETE TEAM controller, and moved it outside of the loop. I did this when Steven pointed out that the behaviour I describe in the comment is for the whole loop.
- The second change is the removal of my first test. I was facing quite a few issues with creating users in the test, and ended up using the CREATE TEAM MEMBERSHIP to perform 2 actions at once -> create a new user if one doesn't exist with the provided email, and create a membership for the user. Before this approach, I had quite a bit of code that didn't work, and it seems like I removed some things that weren't supposed to be removed, and didn't change variable names where necessary. Anyway, I figured that the problem has something to do with the user being created on the client side, so I moved the test to the server side.
- The new test I implemented does the same thing as my previous failed test, but in more detailed and distinct steps. The test first creates 5 new users inside of a loop, and pushes each new user's ID to an array called 'new_users' if the response is as expected. Then a new team is created. The next step is to create memberships for all 5 users. If all these steps pass, the new team that was just created, is deleted, and we check to make sure the new users have 0 team memberships each.
Formatter and linter showed no errors. Tests were successful on localhost.
2023-08-04 23:40:42 +12:00
|
|
|
use Utopia\Database\Helpers\ID;
|
2020-01-17 03:06:28 +13:00
|
|
|
|
|
|
|
trait TeamsBaseServer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @depends testCreateTeam
|
|
|
|
*/
|
2022-05-24 02:54:50 +12: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
|
|
|
|
*/
|
2022-05-24 02:54:50 +12: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()));
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2020-01-17 03:06:28 +13:00
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-02-27 22:57:09 +13:00
|
|
|
$this->assertEquals(0, $response['body']['total']);
|
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
|
|
|
|
2022-09-22 20:06:30 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateTeamMembership
|
|
|
|
*/
|
|
|
|
public function testGetTeamMembership($data): void
|
|
|
|
{
|
|
|
|
$teamUid = $data['teamUid'] ?? '';
|
|
|
|
$membershipUid = $data['membershipUid'] ?? '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships/' . $membershipUid, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertNotEmpty($response['body']['userId']);
|
|
|
|
$this->assertNotEmpty($response['body']['userName']);
|
|
|
|
$this->assertNotEmpty($response['body']['userEmail']);
|
|
|
|
$this->assertNotEmpty($response['body']['teamId']);
|
|
|
|
$this->assertNotEmpty($response['body']['teamName']);
|
|
|
|
$this->assertCount(2, $response['body']['roles']);
|
2022-12-20 00:21:09 +13:00
|
|
|
$dateValidator = new DatetimeValidator();
|
|
|
|
$this->assertEquals(true, $dateValidator->isValid($response['body']['joined'])); // is null in DB
|
2022-09-22 20:06:30 +12:00
|
|
|
$this->assertEquals(true, $response['body']['confirm']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships/' . $membershipUid . 'dasdasd', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships/' . $membershipUid, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
}
|
2020-07-11 00:57:30 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateTeam
|
|
|
|
*/
|
2022-05-24 02:54:50 +12:00
|
|
|
public function testCreateTeamMembership($data): array
|
2020-07-11 00:57:30 +12:00
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$teamUid = $data['teamUid'] ?? '';
|
|
|
|
$teamName = $data['teamName'] ?? '';
|
2022-05-24 02:54:50 +12:00
|
|
|
$email = uniqid() . 'friend@localhost.test';
|
2020-07-11 00:57:30 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
2020-07-11 00:57:30 +12:00
|
|
|
'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']);
|
2022-07-23 11:51:58 +12:00
|
|
|
$this->assertEquals('Friend User', $response['body']['userName']);
|
|
|
|
$this->assertEquals($email, $response['body']['userEmail']);
|
2020-07-11 00:57:30 +12:00
|
|
|
$this->assertNotEmpty($response['body']['teamId']);
|
|
|
|
$this->assertCount(2, $response['body']['roles']);
|
2022-12-20 00:21:09 +13:00
|
|
|
$dateValidator = new DatetimeValidator();
|
|
|
|
$this->assertEquals(true, $dateValidator->isValid($response['body']['joined']));
|
2020-07-11 00:57:30 +12:00
|
|
|
$this->assertEquals(true, $response['body']['confirm']);
|
|
|
|
|
|
|
|
$userUid = $response['body']['userId'];
|
2021-05-14 02:47:35 +12:00
|
|
|
$membershipUid = $response['body']['$id'];
|
2020-07-11 00:57:30 +12:00
|
|
|
|
|
|
|
// $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
|
|
|
|
*/
|
2021-05-10 06:37:47 +12:00
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
2021-05-10 06:37:47 +12:00
|
|
|
'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(409, $response['headers']['status-code']);
|
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
2020-07-11 00:57:30 +12:00
|
|
|
'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']);
|
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
2020-07-11 00:57:30 +12:00
|
|
|
'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']);
|
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
2020-07-11 00:57:30 +12:00
|
|
|
'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,
|
2021-05-14 02:47:35 +12:00
|
|
|
'membershipUid' => $membershipUid
|
2020-07-11 00:57:30 +12:00
|
|
|
];
|
|
|
|
}
|
2021-05-14 02:47:35 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateTeamMembership
|
|
|
|
*/
|
|
|
|
public function testUpdateMembershipRoles($data)
|
|
|
|
{
|
|
|
|
$teamUid = $data['teamUid'] ?? '';
|
|
|
|
$membershipUid = $data['membershipUid'] ?? '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$roles = ['admin', 'editor', 'uncle'];
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . $teamUid . '/memberships/' . $membershipUid, array_merge([
|
2021-05-14 02:47:35 +12:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'roles' => $roles
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertNotEmpty($response['body']['userId']);
|
|
|
|
$this->assertNotEmpty($response['body']['teamId']);
|
|
|
|
$this->assertCount(count($roles), $response['body']['roles']);
|
|
|
|
$this->assertEquals($roles[0], $response['body']['roles'][0]);
|
|
|
|
$this->assertEquals($roles[1], $response['body']['roles'][1]);
|
|
|
|
$this->assertEquals($roles[2], $response['body']['roles'][2]);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$apiKey = $this->getNewKey(['teams.read']);
|
|
|
|
$roles = ['admin', 'editor', 'uncle'];
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . $teamUid . '/memberships/' . $membershipUid, [
|
2021-05-14 02:47:35 +12:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $apiKey
|
|
|
|
], [
|
|
|
|
'roles' => $roles
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
|
2021-05-31 16:56:06 +12:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testUpdateMembershipRoles
|
|
|
|
*/
|
2022-05-24 02:54:50 +12:00
|
|
|
public function testDeleteUserUpdatesTeamMembershipCount($data)
|
|
|
|
{
|
2021-05-31 16:56:06 +12:00
|
|
|
$teamUid = $data['teamUid'] ?? '';
|
|
|
|
$userUid = $data['userUid'] ?? '';
|
|
|
|
|
|
|
|
/** Get Team Count */
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid, array_merge([
|
2021-05-31 16:56:06 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('Arsenal', $response['body']['name']);
|
2022-02-27 22:57:09 +13:00
|
|
|
$this->assertEquals(1, $response['body']['total']);
|
|
|
|
$this->assertIsInt($response['body']['total']);
|
2022-12-20 00:21:09 +13:00
|
|
|
$dateValidator = new DatetimeValidator();
|
|
|
|
$this->assertEquals(true, $dateValidator->isValid($response['body']['$createdAt']));
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2021-05-31 16:56:06 +12:00
|
|
|
/** Delete User */
|
|
|
|
$user = $this->client->call(Client::METHOD_DELETE, '/users/' . $userUid, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals($user['headers']['status-code'], 204);
|
|
|
|
|
|
|
|
/** Wait for deletes worker to delete membership and update team membership count */
|
|
|
|
sleep(5);
|
|
|
|
|
|
|
|
/** Get Team Count */
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid, array_merge([
|
2021-05-31 16:56:06 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('Arsenal', $response['body']['name']);
|
2022-02-27 22:57:09 +13:00
|
|
|
$this->assertEquals(0, $response['body']['total']);
|
|
|
|
$this->assertIsInt($response['body']['total']);
|
2022-12-20 00:21:09 +13:00
|
|
|
$this->assertEquals(true, $dateValidator->isValid($response['body']['$createdAt']));
|
2021-05-14 02:47:35 +12:00
|
|
|
}
|
Fixed an incorrect test for team deletion
This commit contains changes in 3 places.
- First I changed the placement of an informative comment in the DELETE TEAM controller, and moved it outside of the loop. I did this when Steven pointed out that the behaviour I describe in the comment is for the whole loop.
- The second change is the removal of my first test. I was facing quite a few issues with creating users in the test, and ended up using the CREATE TEAM MEMBERSHIP to perform 2 actions at once -> create a new user if one doesn't exist with the provided email, and create a membership for the user. Before this approach, I had quite a bit of code that didn't work, and it seems like I removed some things that weren't supposed to be removed, and didn't change variable names where necessary. Anyway, I figured that the problem has something to do with the user being created on the client side, so I moved the test to the server side.
- The new test I implemented does the same thing as my previous failed test, but in more detailed and distinct steps. The test first creates 5 new users inside of a loop, and pushes each new user's ID to an array called 'new_users' if the response is as expected. Then a new team is created. The next step is to create memberships for all 5 users. If all these steps pass, the new team that was just created, is deleted, and we check to make sure the new users have 0 team memberships each.
Formatter and linter showed no errors. Tests were successful on localhost.
2023-08-04 23:40:42 +12:00
|
|
|
|
|
|
|
public function testTeamDeleteUpdatesUserMembership()
|
|
|
|
{
|
2023-08-05 07:17:41 +12:00
|
|
|
// Array to store the IDs of newly created users
|
Fixed an incorrect test for team deletion
This commit contains changes in 3 places.
- First I changed the placement of an informative comment in the DELETE TEAM controller, and moved it outside of the loop. I did this when Steven pointed out that the behaviour I describe in the comment is for the whole loop.
- The second change is the removal of my first test. I was facing quite a few issues with creating users in the test, and ended up using the CREATE TEAM MEMBERSHIP to perform 2 actions at once -> create a new user if one doesn't exist with the provided email, and create a membership for the user. Before this approach, I had quite a bit of code that didn't work, and it seems like I removed some things that weren't supposed to be removed, and didn't change variable names where necessary. Anyway, I figured that the problem has something to do with the user being created on the client side, so I moved the test to the server side.
- The new test I implemented does the same thing as my previous failed test, but in more detailed and distinct steps. The test first creates 5 new users inside of a loop, and pushes each new user's ID to an array called 'new_users' if the response is as expected. Then a new team is created. The next step is to create memberships for all 5 users. If all these steps pass, the new team that was just created, is deleted, and we check to make sure the new users have 0 team memberships each.
Formatter and linter showed no errors. Tests were successful on localhost.
2023-08-04 23:40:42 +12:00
|
|
|
$new_users = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new team
|
|
|
|
*/
|
|
|
|
$new_team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'teamId' => ID::unique(),
|
|
|
|
'name' => 'New Team Test',
|
|
|
|
'roles' => ['admin', 'editor'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $new_team['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($new_team['body']['$id']);
|
|
|
|
$this->assertEquals('New Team Test', $new_team['body']['name']);
|
|
|
|
$this->assertGreaterThan(-1, $new_team['body']['total']);
|
|
|
|
$this->assertIsInt($new_team['body']['total']);
|
|
|
|
$this->assertArrayHasKey('prefs', $new_team['body']);
|
|
|
|
|
|
|
|
/**
|
2023-08-05 07:41:29 +12:00
|
|
|
* Use the Create Team Membership endpoint
|
2023-08-05 07:17:41 +12:00
|
|
|
* to create 5 new users and add them to the team immediately
|
Fixed an incorrect test for team deletion
This commit contains changes in 3 places.
- First I changed the placement of an informative comment in the DELETE TEAM controller, and moved it outside of the loop. I did this when Steven pointed out that the behaviour I describe in the comment is for the whole loop.
- The second change is the removal of my first test. I was facing quite a few issues with creating users in the test, and ended up using the CREATE TEAM MEMBERSHIP to perform 2 actions at once -> create a new user if one doesn't exist with the provided email, and create a membership for the user. Before this approach, I had quite a bit of code that didn't work, and it seems like I removed some things that weren't supposed to be removed, and didn't change variable names where necessary. Anyway, I figured that the problem has something to do with the user being created on the client side, so I moved the test to the server side.
- The new test I implemented does the same thing as my previous failed test, but in more detailed and distinct steps. The test first creates 5 new users inside of a loop, and pushes each new user's ID to an array called 'new_users' if the response is as expected. Then a new team is created. The next step is to create memberships for all 5 users. If all these steps pass, the new team that was just created, is deleted, and we check to make sure the new users have 0 team memberships each.
Formatter and linter showed no errors. Tests were successful on localhost.
2023-08-04 23:40:42 +12:00
|
|
|
*/
|
|
|
|
for ($i = 0; $i < 5; $i++) {
|
|
|
|
$new_membership = $this->client->call(Client::METHOD_POST, '/teams/' . $new_team['body']['$id'] . '/memberships', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'email' => 'newuser' . $i . '@localhost.test',
|
|
|
|
'name' => 'New User ' . $i,
|
|
|
|
'roles' => ['admin', 'editor'],
|
|
|
|
'url' => 'http://localhost:5000/join-us#title'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $new_membership['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($new_membership['body']['$id']);
|
|
|
|
$this->assertNotEmpty($new_membership['body']['userId']);
|
|
|
|
$this->assertEquals('New User ' . $i, $new_membership['body']['userName']);
|
|
|
|
$this->assertEquals('newuser' . $i . '@localhost.test', $new_membership['body']['userEmail']);
|
|
|
|
$this->assertNotEmpty($new_membership['body']['teamId']);
|
|
|
|
$this->assertCount(2, $new_membership['body']['roles']);
|
|
|
|
$dateValidator = new DatetimeValidator();
|
|
|
|
$this->assertEquals(true, $dateValidator->isValid($new_membership['body']['joined']));
|
|
|
|
$this->assertEquals(true, $new_membership['body']['confirm']);
|
2023-08-05 07:17:41 +12:00
|
|
|
|
|
|
|
$new_users[] = $new_membership['body']['userId'];
|
Fixed an incorrect test for team deletion
This commit contains changes in 3 places.
- First I changed the placement of an informative comment in the DELETE TEAM controller, and moved it outside of the loop. I did this when Steven pointed out that the behaviour I describe in the comment is for the whole loop.
- The second change is the removal of my first test. I was facing quite a few issues with creating users in the test, and ended up using the CREATE TEAM MEMBERSHIP to perform 2 actions at once -> create a new user if one doesn't exist with the provided email, and create a membership for the user. Before this approach, I had quite a bit of code that didn't work, and it seems like I removed some things that weren't supposed to be removed, and didn't change variable names where necessary. Anyway, I figured that the problem has something to do with the user being created on the client side, so I moved the test to the server side.
- The new test I implemented does the same thing as my previous failed test, but in more detailed and distinct steps. The test first creates 5 new users inside of a loop, and pushes each new user's ID to an array called 'new_users' if the response is as expected. Then a new team is created. The next step is to create memberships for all 5 users. If all these steps pass, the new team that was just created, is deleted, and we check to make sure the new users have 0 team memberships each.
Formatter and linter showed no errors. Tests were successful on localhost.
2023-08-04 23:40:42 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete the team
|
|
|
|
*/
|
|
|
|
$team_del_response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $new_team['body']['$id'], array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(204, $team_del_response['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that the team memberships for each of the new users has been deleted
|
|
|
|
*/
|
|
|
|
for ($i = 0; $i < 5; $i++) {
|
|
|
|
$membership = $this->client->call(Client::METHOD_GET, '/users/' . $new_users[$i] . '/memberships', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $membership['headers']['status-code']);
|
|
|
|
$this->assertEquals(0, $membership['body']['total']);
|
|
|
|
}
|
|
|
|
}
|
2022-05-24 02:54:50 +12:00
|
|
|
}
|