1
0
Fork 0
mirror of synced 2024-06-10 14:54:43 +12:00

fix(teams): added unit test

This commit is contained in:
Christy Jacob 2021-05-31 10:26:06 +05:30
parent b7efefa40f
commit 404e1ace91
3 changed files with 52 additions and 2 deletions

View file

@ -784,7 +784,7 @@ App::delete('/v1/teams/:teamId/memberships/:membershipId')
if ($membership->getAttribute('confirm')) { // Count only confirmed members
$team = $projectDB->updateDocument(\array_merge($team->getArrayCopy(), [
'sum' => \max($team->getAttribute('sum', 0) - 1, 0), // Ensure that sum is always >= 0
'sum' => \max($team->getAttribute('sum', 0) - 1, 0), // Ensure that sum >= 0
]));
}

View file

@ -138,7 +138,7 @@ class DeletesV1
$team = $this->getProjectDB($projectId)->getDocument($teamId);
if(!$team->isEmpty()) {
$team = $this->getProjectDB($projectId)->updateDocument(\array_merge($team->getArrayCopy(), [
'sum' => \max($team->getAttribute('sum', 0) - 1, 0), // Ensure that sum is always >= 0
'sum' => \max($team->getAttribute('sum', 0) - 1, 0), // Ensure that sum >= 0
]));
}
}

View file

@ -168,5 +168,55 @@ trait TeamsBaseServer
$this->assertEquals(401, $response['headers']['status-code']);
return $data;
}
/**
* @depends testUpdateMembershipRoles
*/
public function testDeleteUserUpdatesTeamMembershipCount($data) {
$teamUid = $data['teamUid'] ?? '';
$userUid = $data['userUid'] ?? '';
/** Get Team Count */
$response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid, 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->assertEquals('Arsenal', $response['body']['name']);
$this->assertEquals(1, $response['body']['sum']);
$this->assertIsInt($response['body']['sum']);
$this->assertIsInt($response['body']['dateCreated']);
/** 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 */
$response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid, 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->assertEquals('Arsenal', $response['body']['name']);
$this->assertEquals(0, $response['body']['sum']);
$this->assertIsInt($response['body']['sum']);
$this->assertIsInt($response['body']['dateCreated']);
}
}