Added tests
This commit is contained in:
parent
f034d1024d
commit
81805d0c62
|
@ -388,7 +388,15 @@ $utopia->post('/v1/teams/:teamId/memberships')
|
|||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED) // TODO change response of this endpoint
|
||||
->json($membership->getArrayCopy())
|
||||
->json($membership->getArrayCopy([
|
||||
'$uid',
|
||||
'userId',
|
||||
'teamId',
|
||||
'roles',
|
||||
'invited',
|
||||
'joined',
|
||||
'confirm',
|
||||
]))
|
||||
;
|
||||
}
|
||||
);
|
||||
|
@ -538,13 +546,13 @@ $utopia->delete('/v1/teams/:teamId/memberships/:inviteId')
|
|||
->param('inviteId', '', function () { return new UID(); }, 'Invite unique ID')
|
||||
->action(
|
||||
function ($teamId, $inviteId) use ($response, $projectDB, $audit) {
|
||||
$invite = $projectDB->getDocument($inviteId);
|
||||
$membership = $projectDB->getDocument($inviteId);
|
||||
|
||||
if (empty($invite->getUid()) || Database::SYSTEM_COLLECTION_MEMBERSHIPS != $invite->getCollection()) {
|
||||
if (empty($membership->getUid()) || Database::SYSTEM_COLLECTION_MEMBERSHIPS != $membership->getCollection()) {
|
||||
throw new Exception('Invite not found', 404);
|
||||
}
|
||||
|
||||
if ($invite->getAttribute('teamId') !== $teamId) {
|
||||
if ($membership->getAttribute('teamId') !== $teamId) {
|
||||
throw new Exception('Team IDs don\'t match', 404);
|
||||
}
|
||||
|
||||
|
@ -554,7 +562,7 @@ $utopia->delete('/v1/teams/:teamId/memberships/:inviteId')
|
|||
throw new Exception('Team not found', 404);
|
||||
}
|
||||
|
||||
if (!$projectDB->deleteDocument($invite->getUid())) {
|
||||
if (!$projectDB->deleteDocument($membership->getUid())) {
|
||||
throw new Exception('Failed to remove membership from DB', 500);
|
||||
}
|
||||
|
||||
|
@ -567,7 +575,7 @@ $utopia->delete('/v1/teams/:teamId/memberships/:inviteId')
|
|||
}
|
||||
|
||||
$audit
|
||||
->setParam('userId', $invite->getAttribute('userId'))
|
||||
->setParam('userId', $membership->getAttribute('userId'))
|
||||
->setParam('event', 'auth.leave')
|
||||
;
|
||||
|
||||
|
|
|
@ -283,32 +283,25 @@ trait TeamsBase
|
|||
'url' => 'http://localhost:5000/join-us#title'
|
||||
]);
|
||||
|
||||
$teamUid = $response['body']['$uid'];
|
||||
if ($response['headers']['status-code'] !== 201) {var_dump($response);}
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$uid']);
|
||||
$this->assertEquals('Demo', $response['body']['name']);
|
||||
$this->assertGreaterThan(-1, $response['body']['sum']);
|
||||
$this->assertIsInt($response['body']['sum']);
|
||||
$this->assertIsInt($response['body']['dateCreated']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(204, $response['headers']['status-code']);
|
||||
$this->assertEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['userId']);
|
||||
$this->assertNotEmpty($response['body']['teamId']);
|
||||
$this->assertCount(2, $response['body']['roles']);
|
||||
$this->assertIsInt($response['body']['joined']);
|
||||
$this->assertEquals(false, $response['body']['confirm']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()));
|
||||
// $response = $this->client->call(Client::METHOD_POST, '/teams/'.$uid.'/memberships', array_merge([
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
// ], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(404, $response['headers']['status-code']);
|
||||
// $this->assertEquals(404, $response['headers']['status-code']);
|
||||
|
||||
return [];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue