Added tests
This commit is contained in:
parent
f034d1024d
commit
81805d0c62
2 changed files with 25 additions and 24 deletions
|
@ -388,7 +388,15 @@ $utopia->post('/v1/teams/:teamId/memberships')
|
||||||
|
|
||||||
$response
|
$response
|
||||||
->setStatusCode(Response::STATUS_CODE_CREATED) // TODO change response of this endpoint
|
->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')
|
->param('inviteId', '', function () { return new UID(); }, 'Invite unique ID')
|
||||||
->action(
|
->action(
|
||||||
function ($teamId, $inviteId) use ($response, $projectDB, $audit) {
|
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);
|
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);
|
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);
|
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);
|
throw new Exception('Failed to remove membership from DB', 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -567,7 +575,7 @@ $utopia->delete('/v1/teams/:teamId/memberships/:inviteId')
|
||||||
}
|
}
|
||||||
|
|
||||||
$audit
|
$audit
|
||||||
->setParam('userId', $invite->getAttribute('userId'))
|
->setParam('userId', $membership->getAttribute('userId'))
|
||||||
->setParam('event', 'auth.leave')
|
->setParam('event', 'auth.leave')
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
@ -283,32 +283,25 @@ trait TeamsBase
|
||||||
'url' => 'http://localhost:5000/join-us#title'
|
'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->assertEquals(201, $response['headers']['status-code']);
|
||||||
$this->assertNotEmpty($response['body']['$uid']);
|
$this->assertNotEmpty($response['body']['$uid']);
|
||||||
$this->assertEquals('Demo', $response['body']['name']);
|
$this->assertNotEmpty($response['body']['userId']);
|
||||||
$this->assertGreaterThan(-1, $response['body']['sum']);
|
$this->assertNotEmpty($response['body']['teamId']);
|
||||||
$this->assertIsInt($response['body']['sum']);
|
$this->assertCount(2, $response['body']['roles']);
|
||||||
$this->assertIsInt($response['body']['dateCreated']);
|
$this->assertIsInt($response['body']['joined']);
|
||||||
|
$this->assertEquals(false, $response['body']['confirm']);
|
||||||
$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']);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for FAILURE
|
* Test for FAILURE
|
||||||
*/
|
*/
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid, array_merge([
|
// $response = $this->client->call(Client::METHOD_POST, '/teams/'.$uid.'/memberships', array_merge([
|
||||||
'content-type' => 'application/json',
|
// 'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
// 'x-appwrite-project' => $this->getProject()['$uid'],
|
||||||
], $this->getHeaders()));
|
// ], $this->getHeaders()));
|
||||||
|
|
||||||
$this->assertEquals(404, $response['headers']['status-code']);
|
// $this->assertEquals(404, $response['headers']['status-code']);
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue