mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
feat: some test code
This commit is contained in:
+11
-1
@@ -101,6 +101,8 @@ class DeletesV1
|
||||
}
|
||||
|
||||
protected function deleteMemberships(Document $document, $projectId) {
|
||||
var_dump("In deleteMembership");
|
||||
var_dump($document);
|
||||
// Delete Memberships
|
||||
$this->deleteByGroup([
|
||||
'$collection='.Database::SYSTEM_COLLECTION_MEMBERSHIPS,
|
||||
@@ -214,7 +216,7 @@ class DeletesV1
|
||||
Console::success('Delete code tag: '.$document->getAttribute('path', ''));
|
||||
}
|
||||
else {
|
||||
Console::error('Dailed to delete code tag: '.$document->getAttribute('path', ''));
|
||||
Console::error('Failed to delete code tag: '.$document->getAttribute('path', ''));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -229,6 +231,8 @@ class DeletesV1
|
||||
{
|
||||
Authorization::disable();
|
||||
|
||||
Console::success($document->getAttribute('name', 'noname'));
|
||||
var_dump($document);
|
||||
if($database->deleteDocument($document->getId())) {
|
||||
Console::success('Deleted document "'.$document->getId().'" successfully');
|
||||
|
||||
@@ -314,6 +318,12 @@ class DeletesV1
|
||||
|
||||
Authorization::reset();
|
||||
|
||||
var_dump("chunk=".$chunk);
|
||||
var_dump("sum=".$sum);
|
||||
var_dump("limit=".$limit);
|
||||
var_dump("offset=".$count);
|
||||
var_dump("count(results)=".count($results));
|
||||
|
||||
$sum = count($results);
|
||||
|
||||
Console::info('Deleting chunk #'.$chunk.'. Found '.$sum.' documents');
|
||||
|
||||
@@ -6,236 +6,236 @@ use Tests\E2E\Client;
|
||||
|
||||
trait TeamsBaseClient
|
||||
{
|
||||
/**
|
||||
* @depends testCreateTeam
|
||||
*/
|
||||
public function testGetTeamMemberships($data):array
|
||||
{
|
||||
$teamUid = $data['teamUid'] ?? '';
|
||||
// /**
|
||||
// * @depends testCreateTeam
|
||||
// */
|
||||
// public function testGetTeamMemberships($data):array
|
||||
// {
|
||||
// $teamUid = $data['teamUid'] ?? '';
|
||||
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
// /**
|
||||
// * Test for SUCCESS
|
||||
// */
|
||||
// $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships', array_merge([
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['sum']);
|
||||
$this->assertNotEmpty($response['body']['memberships'][0]['$id']);
|
||||
$this->assertEquals($this->getUser()['name'], $response['body']['memberships'][0]['name']);
|
||||
$this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['email']);
|
||||
$this->assertEquals('owner', $response['body']['memberships'][0]['roles'][0]);
|
||||
// $this->assertEquals(200, $response['headers']['status-code']);
|
||||
// $this->assertIsInt($response['body']['sum']);
|
||||
// $this->assertNotEmpty($response['body']['memberships'][0]['$id']);
|
||||
// $this->assertEquals($this->getUser()['name'], $response['body']['memberships'][0]['name']);
|
||||
// $this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['email']);
|
||||
// $this->assertEquals('owner', $response['body']['memberships'][0]['roles'][0]);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
// /**
|
||||
// * Test for FAILURE
|
||||
// */
|
||||
|
||||
return $data;
|
||||
}
|
||||
// return $data;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @depends testCreateTeam
|
||||
*/
|
||||
public function testCreateTeamMembership($data):array
|
||||
{
|
||||
$teamUid = $data['teamUid'] ?? '';
|
||||
$teamName = $data['teamName'] ?? '';
|
||||
$email = uniqid().'friend@localhost.test';
|
||||
// /**
|
||||
// * @depends testCreateTeam
|
||||
// */
|
||||
// public function testCreateTeamMembership($data):array
|
||||
// {
|
||||
// $teamUid = $data['teamUid'] ?? '';
|
||||
// $teamName = $data['teamName'] ?? '';
|
||||
// $email = uniqid().'friend@localhost.test';
|
||||
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'email' => $email,
|
||||
'name' => 'Friend User',
|
||||
'roles' => ['admin', 'editor'],
|
||||
'url' => 'http://localhost:5000/join-us#title'
|
||||
]);
|
||||
// /**
|
||||
// * Test for SUCCESS
|
||||
// */
|
||||
// $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ], $this->getHeaders()), [
|
||||
// 'email' => $email,
|
||||
// 'name' => 'Friend User',
|
||||
// 'roles' => ['admin', 'editor'],
|
||||
// 'url' => 'http://localhost:5000/join-us#title'
|
||||
// ]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$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']);
|
||||
// $this->assertEquals(201, $response['headers']['status-code']);
|
||||
// $this->assertNotEmpty($response['body']['$id']);
|
||||
// $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']);
|
||||
|
||||
$lastEmail = $this->getLastEmail();
|
||||
// $lastEmail = $this->getLastEmail();
|
||||
|
||||
$this->assertEquals($email, $lastEmail['to'][0]['address']);
|
||||
$this->assertEquals('Friend User', $lastEmail['to'][0]['name']);
|
||||
$this->assertEquals('Invitation to '.$teamName.' Team at '.$this->getProject()['name'], $lastEmail['subject']);
|
||||
// $this->assertEquals($email, $lastEmail['to'][0]['address']);
|
||||
// $this->assertEquals('Friend User', $lastEmail['to'][0]['name']);
|
||||
// $this->assertEquals('Invitation to '.$teamName.' Team at '.$this->getProject()['name'], $lastEmail['subject']);
|
||||
|
||||
$secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
|
||||
$membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 14, 13);
|
||||
$userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13);
|
||||
// $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
|
||||
// $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 14, 13);
|
||||
// $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'email' => 'dasdkaskdjaskdjasjkd',
|
||||
'name' => 'Friend User',
|
||||
'roles' => ['admin', 'editor'],
|
||||
'url' => 'http://localhost:5000/join-us#title'
|
||||
]);
|
||||
// /**
|
||||
// * Test for FAILURE
|
||||
// */
|
||||
// $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ], $this->getHeaders()), [
|
||||
// 'email' => 'dasdkaskdjaskdjasjkd',
|
||||
// 'name' => 'Friend User',
|
||||
// 'roles' => ['admin', 'editor'],
|
||||
// 'url' => 'http://localhost:5000/join-us#title'
|
||||
// ]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
// $this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'email' => $email,
|
||||
'name' => 'Friend User',
|
||||
'roles' => 'bad string',
|
||||
'url' => 'http://localhost:5000/join-us#title'
|
||||
]);
|
||||
// $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ], $this->getHeaders()), [
|
||||
// 'email' => $email,
|
||||
// 'name' => 'Friend User',
|
||||
// 'roles' => 'bad string',
|
||||
// 'url' => 'http://localhost:5000/join-us#title'
|
||||
// ]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
// $this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'email' => $email,
|
||||
'name' => 'Friend User',
|
||||
'roles' => ['admin', 'editor'],
|
||||
'url' => 'http://example.com/join-us#title' // bad url
|
||||
]);
|
||||
// $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ], $this->getHeaders()), [
|
||||
// 'email' => $email,
|
||||
// 'name' => 'Friend User',
|
||||
// 'roles' => ['admin', 'editor'],
|
||||
// 'url' => 'http://example.com/join-us#title' // bad url
|
||||
// ]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
// $this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
return [
|
||||
'teamUid' => $teamUid,
|
||||
'secret' => $secret,
|
||||
'membershipUid' => $membershipUid,
|
||||
'userUid' => $userUid,
|
||||
];
|
||||
}
|
||||
// return [
|
||||
// 'teamUid' => $teamUid,
|
||||
// 'secret' => $secret,
|
||||
// 'membershipUid' => $membershipUid,
|
||||
// 'userUid' => $userUid,
|
||||
// ];
|
||||
// }
|
||||
|
||||
/**
|
||||
* @depends testCreateTeamMembership
|
||||
*/
|
||||
public function testUpdateTeamMembership($data):array
|
||||
{
|
||||
$teamUid = $data['teamUid'] ?? '';
|
||||
$secret = $data['secret'] ?? '';
|
||||
$membershipUid = $data['membershipUid'] ?? '';
|
||||
$userUid = $data['userUid'] ?? '';
|
||||
// /**
|
||||
// * @depends testCreateTeamMembership
|
||||
// */
|
||||
// public function testUpdateTeamMembership($data):array
|
||||
// {
|
||||
// $teamUid = $data['teamUid'] ?? '';
|
||||
// $secret = $data['secret'] ?? '';
|
||||
// $membershipUid = $data['membershipUid'] ?? '';
|
||||
// $userUid = $data['userUid'] ?? '';
|
||||
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'secret' => $secret,
|
||||
'userId' => $userUid,
|
||||
]);
|
||||
// /**
|
||||
// * Test for SUCCESS
|
||||
// */
|
||||
// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([
|
||||
// 'origin' => 'http://localhost',
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ]), [
|
||||
// 'secret' => $secret,
|
||||
// 'userId' => $userUid,
|
||||
// ]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertNotEmpty($response['body']['userId']);
|
||||
$this->assertNotEmpty($response['body']['teamId']);
|
||||
$this->assertCount(2, $response['body']['roles']);
|
||||
$this->assertIsInt($response['body']['joined']);
|
||||
$this->assertEquals(true, $response['body']['confirm']);
|
||||
// $this->assertEquals(200, $response['headers']['status-code']);
|
||||
// $this->assertNotEmpty($response['body']['$id']);
|
||||
// $this->assertNotEmpty($response['body']['userId']);
|
||||
// $this->assertNotEmpty($response['body']['teamId']);
|
||||
// $this->assertCount(2, $response['body']['roles']);
|
||||
// $this->assertIsInt($response['body']['joined']);
|
||||
// $this->assertEquals(true, $response['body']['confirm']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'secret' => 'sdasdasd',
|
||||
'userId' => $userUid,
|
||||
]);
|
||||
// /**
|
||||
// * Test for FAILURE
|
||||
// */
|
||||
// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([
|
||||
// 'origin' => 'http://localhost',
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ]), [
|
||||
// 'secret' => 'sdasdasd',
|
||||
// 'userId' => $userUid,
|
||||
// ]);
|
||||
|
||||
$this->assertEquals(401, $response['headers']['status-code']);
|
||||
// $this->assertEquals(401, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'secret' => '',
|
||||
'userId' => $userUid,
|
||||
]);
|
||||
// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([
|
||||
// 'origin' => 'http://localhost',
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ]), [
|
||||
// 'secret' => '',
|
||||
// 'userId' => $userUid,
|
||||
// ]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
// $this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'secret' => $secret,
|
||||
'userId' => 'sdasd',
|
||||
]);
|
||||
// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([
|
||||
// 'origin' => 'http://localhost',
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ]), [
|
||||
// 'secret' => $secret,
|
||||
// 'userId' => 'sdasd',
|
||||
// ]);
|
||||
|
||||
$this->assertEquals(401, $response['headers']['status-code']);
|
||||
// $this->assertEquals(401, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'secret' => $secret,
|
||||
'userId' => '',
|
||||
]);
|
||||
// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([
|
||||
// 'origin' => 'http://localhost',
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ]), [
|
||||
// 'secret' => $secret,
|
||||
// 'userId' => '',
|
||||
// ]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
// $this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
// return $data;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @depends testUpdateTeamMembership
|
||||
*/
|
||||
public function testDeleteTeamMembership($data):array
|
||||
{
|
||||
$teamUid = $data['teamUid'] ?? '';
|
||||
$membershipUid = $data['membershipUid'] ?? '';
|
||||
// /**
|
||||
// * @depends testUpdateTeamMembership
|
||||
// */
|
||||
// public function testDeleteTeamMembership($data):array
|
||||
// {
|
||||
// $teamUid = $data['teamUid'] ?? '';
|
||||
// $membershipUid = $data['membershipUid'] ?? '';
|
||||
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
// /**
|
||||
// * Test for SUCCESS
|
||||
// */
|
||||
// $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([
|
||||
// 'origin' => 'http://localhost',
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(204, $response['headers']['status-code']);
|
||||
$this->assertEmpty($response['body']);
|
||||
// $this->assertEquals(204, $response['headers']['status-code']);
|
||||
// $this->assertEmpty($response['body']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
// /**
|
||||
// * Test for FAILURE
|
||||
// */
|
||||
// $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([
|
||||
// 'origin' => 'http://localhost',
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertCount(1, $response['body']['memberships']);
|
||||
// $this->assertEquals(200, $response['headers']['status-code']);
|
||||
// $this->assertCount(1, $response['body']['memberships']);
|
||||
|
||||
return [];
|
||||
}
|
||||
// return [];
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
@@ -244,7 +244,7 @@ trait TeamsBaseClient
|
||||
public function testDeleteTeamMembershipsWorker($data):array
|
||||
{
|
||||
$teamUid = $data['teamUid'] ?? '';
|
||||
$count = 50;
|
||||
$count = 3;
|
||||
|
||||
/*
|
||||
* Create $count Team Memberships
|
||||
|
||||
Reference in New Issue
Block a user