1
0
Fork 0
mirror of synced 2024-07-06 07:00:56 +12:00
appwrite/tests/unit/Migration/MigrationV14Test.php

174 lines
5.8 KiB
PHP
Raw Normal View History

2022-06-22 06:21:36 +12:00
<?php
2022-08-01 22:22:04 +12:00
namespace Tests\Unit\Migration;
2022-06-22 06:21:36 +12:00
use ReflectionClass;
use Appwrite\Migration\Version\V14;
use Utopia\Database\Document;
2022-08-14 22:33:36 +12:00
use Utopia\Database\ID;
2022-06-22 06:21:36 +12:00
class MigrationV14Test extends MigrationTest
{
public function setUp(): void
{
$this->migration = new V14();
$reflector = new ReflectionClass('Appwrite\Migration\Version\V14');
$this->method = $reflector->getMethod('fixDocument');
$this->method->setAccessible(true);
}
2022-08-01 22:22:04 +12:00
public function testMigrateProjects(): void
2022-06-22 06:21:36 +12:00
{
$document = $this->fixDocument(new Document([
2022-08-14 22:33:36 +12:00
'$id' => ID::custom('appwrite'),
'$collection' => ID::custom('projects'),
2022-06-22 06:21:36 +12:00
'version' => '0.14.0'
]));
$this->assertEquals($document->getAttribute('version'), '0.15.0');
$this->assertEquals($document->getAttribute('version'), '0.15.0');
}
2022-08-01 22:22:04 +12:00
public function testMigrateKeys(): void
2022-06-22 06:21:36 +12:00
{
$document = $this->fixDocument(new Document([
2022-08-14 22:33:36 +12:00
'$id' => ID::custom('appwrite'),
2022-06-22 06:21:36 +12:00
'$collection' => 'keys'
]));
$this->assertArrayHasKey('expire', $document->getArrayCopy());
$this->assertEquals($document->getAttribute('expire'), 0);
}
2022-08-01 22:22:04 +12:00
public function testMigrateWebhooks(): void
2022-06-22 06:21:36 +12:00
{
$document = $this->fixDocument(new Document([
2022-08-14 22:33:36 +12:00
'$id' => ID::custom('appwrite'),
2022-06-22 06:21:36 +12:00
'$collection' => 'webhooks'
]));
$this->assertArrayHasKey('signatureKey', $document->getArrayCopy());
$this->assertEquals(strlen($document->getAttribute('signatureKey')), 128);
}
2022-08-01 22:22:04 +12:00
public function testMigrateUsers(): void
2022-06-22 06:21:36 +12:00
{
$document = $this->fixDocument(new Document([
2022-08-14 22:33:36 +12:00
'$id' => ID::custom('appwrite'),
'$collection' => ID::custom('users'),
2022-06-22 06:21:36 +12:00
'phoneVerification' => null
]));
$this->assertArrayHasKey('phoneVerification', $document->getArrayCopy());
$this->assertFalse($document->getAttribute('phoneVerification'));
}
2022-08-01 22:22:04 +12:00
public function testMigratePlatforms(): void
2022-06-22 06:21:36 +12:00
{
$document = $this->fixDocument(new Document([
2022-08-14 22:33:36 +12:00
'$id' => ID::custom('appwrite'),
'$collection' => ID::custom('platforms'),
2022-06-22 06:21:36 +12:00
'$createdAt' => null,
'$updatedAt' => null,
'dateCreated' => 123456789,
'dateUpdated' => 987654321
]));
$this->assertEquals($document->getCreatedAt(), 123456789);
2022-06-23 01:52:21 +12:00
$this->assertEquals($document->getUpdatedAt(), 987654321);
2022-06-22 06:21:36 +12:00
}
2022-08-01 22:22:04 +12:00
public function testMigrateFunctions(): void
2022-06-22 06:21:36 +12:00
{
$document = $this->fixDocument(new Document([
2022-08-14 22:33:36 +12:00
'$id' => ID::custom('appwrite'),
'$collection' => ID::custom('functions'),
2022-06-22 06:21:36 +12:00
'$createdAt' => null,
'$updatedAt' => null,
'dateCreated' => 123456789,
'dateUpdated' => 987654321
]));
$this->assertEquals($document->getCreatedAt(), 123456789);
2022-06-23 01:52:21 +12:00
$this->assertEquals($document->getUpdatedAt(), 987654321);
2022-06-22 06:21:36 +12:00
}
2022-08-01 22:22:04 +12:00
public function testMigrateDeployments(): void
2022-06-22 06:21:36 +12:00
{
$document = $this->fixDocument(new Document([
2022-08-14 22:33:36 +12:00
'$id' => ID::custom('appwrite'),
'$collection' => ID::custom('deployments'),
2022-06-22 06:21:36 +12:00
'$createdAt' => null,
'dateCreated' => 123456789,
]));
$this->assertEquals($document->getCreatedAt(), 123456789);
}
2022-08-01 22:22:04 +12:00
public function testMigrateExecutions(): void
2022-06-22 06:21:36 +12:00
{
$document = $this->fixDocument(new Document([
2022-08-14 22:33:36 +12:00
'$id' => ID::custom('appwrite'),
'$collection' => ID::custom('executions'),
2022-06-22 06:21:36 +12:00
'$createdAt' => null,
'dateCreated' => 123456789,
]));
$this->assertEquals($document->getCreatedAt(), 123456789);
}
2022-08-01 22:22:04 +12:00
public function testMigrateTeams(): void
2022-06-22 06:21:36 +12:00
{
$document = $this->fixDocument(new Document([
2022-08-14 22:33:36 +12:00
'$id' => ID::custom('appwrite'),
'$collection' => ID::custom('teams'),
2022-06-22 06:21:36 +12:00
'$createdAt' => null,
'dateCreated' => 123456789,
]));
$this->assertEquals($document->getCreatedAt(), 123456789);
}
2022-06-23 20:18:23 +12:00
2022-08-01 22:22:04 +12:00
public function testMigrateAudits(): void
2022-06-23 20:18:23 +12:00
{
$document = $this->fixDocument(new Document([
2022-08-14 22:33:36 +12:00
'$id' => ID::custom('appwrite'),
'$collection' => ID::custom('audit'),
2022-06-23 20:18:23 +12:00
'resource' => 'collection/movies',
'event' => 'collections.movies.create'
]));
$this->assertEquals($document->getAttribute('resource'), 'database/default/collection/movies');
$this->assertEquals($document->getAttribute('event'), 'databases.default.collections.movies.create');
$document = $this->fixDocument(new Document([
2022-08-14 22:33:36 +12:00
'$id' => ID::custom('appwrite'),
'$collection' => ID::custom('audit'),
2022-06-23 20:18:23 +12:00
'resource' => 'document/avatar',
'event' => 'collections.movies.documents.avatar.create'
]));
$this->assertEquals($document->getAttribute('resource'), 'database/default/collection/movies/document/avatar');
$this->assertEquals($document->getAttribute('event'), 'databases.default.collections.movies.documents.avatar.create');
}
2022-08-01 22:22:04 +12:00
public function testMigrateStats(): void
2022-06-23 20:18:23 +12:00
{
$document = $this->fixDocument(new Document([
2022-08-14 22:33:36 +12:00
'$id' => ID::custom('appwrite'),
'$collection' => ID::custom('stats'),
2022-06-23 20:18:23 +12:00
'metric' => 'database.collections.62b2039844d4277495d0.documents.create'
]));
$this->assertEquals($document->getAttribute('metric'), 'databases.default.collections.62b2039844d4277495d0.documents.create');
$document = $this->fixDocument(new Document([
2022-08-14 22:33:36 +12:00
'$id' => ID::custom('appwrite'),
'$collection' => ID::custom('stats'),
2022-06-23 20:18:23 +12:00
'metric' => 'users.create'
]));
$this->assertEquals($document->getAttribute('metric'), 'users.create');
}
2022-06-22 06:21:36 +12:00
}