1
0
Fork 0
mirror of synced 2024-10-02 10:16:27 +13:00

added test

This commit is contained in:
Safwan Parkar 2023-08-04 00:34:01 +04:00
parent d142620c5e
commit 06e1191063

View file

@ -428,4 +428,67 @@ trait TeamsBase
$this->assertEquals($user['headers']['status-code'], 400);
}
public function testTeamDeleteUpdatesUserMembership()
{
$users = [];
$team = null;
$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' => 'Demo'
]);
$this->assertEquals(201, $team['headers']['status-code']);
$this->assertNotEmpty($team['body']['$id']);
$this->assertEquals('Demo', $team['body']['name']);
$this->assertGreaterThan(-1, $team['body']['total']);
$this->assertIsInt($team['body']['total']);
for ($i = 0; $i < 5; $i++) {
$mem = $this->client->call(Client::METHOD_POST, '/teams/' . $team['body']['$id'] . '/memberships', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'email' => 'email' . $i . '@example.com',
'roles' => ['admin', 'editor'],
'name' => 'User ' . $i,
'url' => 'http://localhost:5000/join-us#title'
]);
$this->assertEquals(201, $mem['headers']['status-code']);
$this->assertNotEmpty($mem['body']['$id']);
$this->assertNotEmpty($mem['body']['userId']);
$this->assertEquals('User ' . $i, $mem['body']['userName']);
$this->assertEquals('email' . $i . '@example.com', $mem['body']['userEmail']);
$this->assertNotEmpty($mem['body']['teamId']);
$this->assertCount(2, $mem['body']['roles']);
}
$this->client->call(Client::METHOD_DELETE, '/teams/' . $team['body']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
foreach ($users as $user) {
$user = $this->client->call(Client::METHOD_GET, '/users/' . $user['body']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(200, $user['headers']['status-code']);
$this->assertEquals(0, $user['body']['total']);
$this->assertEquals([], $user['body']['memberships']);
}
$team = $this->client->call(Client::METHOD_GET, '/teams/' . $team['body']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(404, $team['headers']['status-code']);
}
}