From 84ed87d7c304e9610aec06df6729ea0508a671b1 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 21 Jun 2022 20:21:36 +0200 Subject: [PATCH] tests: add test for migration --- tests/unit/Migration/MigrationTest.php | 1 - tests/unit/Migration/MigrationV13Test.php | 10 -- tests/unit/Migration/MigrationV14Test.php | 130 ++++++++++++++++++++++ 3 files changed, 130 insertions(+), 11 deletions(-) create mode 100644 tests/unit/Migration/MigrationV14Test.php diff --git a/tests/unit/Migration/MigrationTest.php b/tests/unit/Migration/MigrationTest.php index 0c8c34cbc8..24aab8d1e3 100644 --- a/tests/unit/Migration/MigrationTest.php +++ b/tests/unit/Migration/MigrationTest.php @@ -4,7 +4,6 @@ namespace Appwrite\Tests; use Appwrite\Migration\Migration; use PHPUnit\Framework\TestCase; -use ReflectionClass; use ReflectionMethod; use Utopia\Database\Document; diff --git a/tests/unit/Migration/MigrationV13Test.php b/tests/unit/Migration/MigrationV13Test.php index 3d0b0e2971..ff04403536 100644 --- a/tests/unit/Migration/MigrationV13Test.php +++ b/tests/unit/Migration/MigrationV13Test.php @@ -38,14 +38,4 @@ class MigrationV13Test extends MigrationTest $this->assertEquals($document->getAttribute('events'), ['users.*.create']); } - - public function testEventsConversion() - { - $migration = new V13(); - $events = $migration->migrateEvents($migration->events); - foreach ($events as $event) { - $this->assertTrue((new Event())->isValid($event), $event); - } - $this->assertCount(44, $events); - } } diff --git a/tests/unit/Migration/MigrationV14Test.php b/tests/unit/Migration/MigrationV14Test.php new file mode 100644 index 0000000000..43b93b1539 --- /dev/null +++ b/tests/unit/Migration/MigrationV14Test.php @@ -0,0 +1,130 @@ +migration = new V14(); + $reflector = new ReflectionClass('Appwrite\Migration\Version\V14'); + $this->method = $reflector->getMethod('fixDocument'); + $this->method->setAccessible(true); + } + + public function testMigrateProject() + { + $document = $this->fixDocument(new Document([ + '$id' => 'appwrite', + '$collection' => 'projects', + 'version' => '0.14.0' + ])); + + $this->assertEquals($document->getAttribute('version'), '0.15.0'); + $this->assertEquals($document->getAttribute('version'), '0.15.0'); + } + + public function testMigrateKey() + { + $document = $this->fixDocument(new Document([ + '$id' => 'appwrite', + '$collection' => 'keys' + ])); + + $this->assertArrayHasKey('expire', $document->getArrayCopy()); + $this->assertEquals($document->getAttribute('expire'), 0); + } + + public function testMigrateWebhooks() + { + $document = $this->fixDocument(new Document([ + '$id' => 'appwrite', + '$collection' => 'webhooks' + ])); + + $this->assertArrayHasKey('signatureKey', $document->getArrayCopy()); + $this->assertEquals(strlen($document->getAttribute('signatureKey')), 128); + } + + public function testMigrateUsers() + { + $document = $this->fixDocument(new Document([ + '$id' => 'appwrite', + '$collection' => 'users', + 'phoneVerification' => null + ])); + + $this->assertArrayHasKey('phoneVerification', $document->getArrayCopy()); + $this->assertFalse($document->getAttribute('phoneVerification')); + } + + public function testMigratePlatforms() + { + $document = $this->fixDocument(new Document([ + '$id' => 'appwrite', + '$collection' => 'platforms', + '$createdAt' => null, + '$updatedAt' => null, + 'dateCreated' => 123456789, + 'dateUpdated' => 987654321 + ])); + + $this->assertEquals($document->getCreatedAt(), 123456789); + $this->assertEquals($document->getUpdateAt(), 987654321); + } + + public function testMigrateFunctions() + { + $document = $this->fixDocument(new Document([ + '$id' => 'appwrite', + '$collection' => 'functions', + '$createdAt' => null, + '$updatedAt' => null, + 'dateCreated' => 123456789, + 'dateUpdated' => 987654321 + ])); + + $this->assertEquals($document->getCreatedAt(), 123456789); + $this->assertEquals($document->getUpdateAt(), 987654321); + } + + public function testMigrateDeployments() + { + $document = $this->fixDocument(new Document([ + '$id' => 'appwrite', + '$collection' => 'deployments', + '$createdAt' => null, + 'dateCreated' => 123456789, + ])); + + $this->assertEquals($document->getCreatedAt(), 123456789); + } + + public function testMigrateExecutions() + { + $document = $this->fixDocument(new Document([ + '$id' => 'appwrite', + '$collection' => 'executions', + '$createdAt' => null, + 'dateCreated' => 123456789, + ])); + + $this->assertEquals($document->getCreatedAt(), 123456789); + } + + public function testMigrateTeams() + { + $document = $this->fixDocument(new Document([ + '$id' => 'appwrite', + '$collection' => 'teams', + '$createdAt' => null, + 'dateCreated' => 123456789, + ])); + + $this->assertEquals($document->getCreatedAt(), 123456789); + } +}