fix(teams): added unit test
This commit is contained in:
parent
b7efefa40f
commit
404e1ace91
|
@ -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
|
||||
]));
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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']);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue