Skip to content

Commit

Permalink
Update AppwriteTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
PineappleIOnic committed Jun 3, 2024
1 parent 0a598ae commit 8d00c87
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions tests/Migration/Unit/Sources/AppwriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Appwrite\Client;
use Appwrite\Query;
use Appwrite\Services\Teams;
use Appwrite\Services\Users;
use Utopia\CLI\Console;
use Utopia\Migration\Resource;
Expand All @@ -17,7 +18,6 @@ class AppwriteTest extends Base

public static function setUpBeforeClass(): void
{
// If we've already bootstrapped Appwrite, skip
if (file_exists('projects.json')) {
Console::info('Appwrite already bootstrapped, skipping');

Expand Down Expand Up @@ -50,7 +50,6 @@ public static function setUpBeforeClass(): void

Console::info('Bootstrapping Appwrite...');

// Bootstrap Appwrite
$stdout = '';
Console::execute(
'appwrite-toolkit --endpoint http://appwrite/v1 --auto bootstrap --amount 1',
Expand All @@ -61,7 +60,6 @@ public static function setUpBeforeClass(): void

Console::info('Running Faker...');

// Run Faker
$stdout = '';
Console::execute(
'appwrite-toolkit --endpoint http://appwrite/v1 --auto faker',
Expand Down Expand Up @@ -139,7 +137,7 @@ public function testValidateTransfer($state)
$this->assertNotEmpty($counters);

if ($counters[Resource::STATUS_ERROR] > 0) {
$this->fail('Resource '.$resource.' has '.$counters[Resource::STATUS_ERROR].' errors');
$this->fail('Resource ' . $resource . ' has ' . $counters[Resource::STATUS_ERROR] . ' errors');

return;
}
Expand All @@ -153,15 +151,16 @@ public function testValidateTransfer($state)
*/
public function testValidateAuthTransfer($state): void
{
// Process all users from Appwrite source and check if our copy is 1:1
$userClient = new Users($this->client);
$teamClient = new Teams($this->client);

/** @var Transfer $transfer */
$transfer = $state['transfer'];

/** @var MockDestination $destination */
$destination = $transfer->getDestination();

// Check Users
$last = '';
while (true) {
$response = $userClient->list(
Expand All @@ -173,7 +172,7 @@ public function testValidateAuthTransfer($state): void
$destinationUser = $destination->get('user', $user['$id']);

if (empty($destinationUser)) {
$this->fail('User '.$user['$id'].' not found in destination');
$this->fail('User ' . $user['$id'] . ' not found in destination');
}

// Compare data
Expand All @@ -183,6 +182,7 @@ public function testValidateAuthTransfer($state): void
$this->assertEquals($user['password'], $destinationUser['passwordHash']);
$this->assertEquals($user['phone'], $destinationUser['phone']);
$this->assertEquals($user['emailVerification'], $destinationUser['emailVerified']);
$this->assertEquals($user['phoneVerification'], $destinationUser['phoneVerified']);

$last = $user['$id'];
}
Expand All @@ -191,6 +191,34 @@ public function testValidateAuthTransfer($state): void
break;
}
}

// Check Teams
$last = '';
while (true) {
$response = $teamClient->list(
empty($last) ? [] : [Query::cursorAfter($last)]
);

foreach ($response['teams'] as $team) {
// Check if exists
$destinationTeam = $destination->get('team', $team['$id']);

if (empty($destinationTeam)) {
$this->fail('Team ' . $team['$id'] . ' not found in destination');
}

// Compare data
$this->assertEquals($team['$id'], $destinationTeam['id']);
$this->assertEquals($team['name'], $destinationTeam['name']);
$this->assertEquals($team['prefs'], $destinationTeam['preferences']);

$last = $team['$id'];
}

if (empty($response['sum'])) {
break;
}
}
}

/**
Expand Down

0 comments on commit 8d00c87

Please sign in to comment.