Skip to content

Commit 4f7bae7

Browse files
updated spatial type tests with spatial index and non spatial combiation
1 parent 7ed30f4 commit 4f7bae7

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

tests/e2e/Adapter/Scopes/SpatialTests.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Utopia\Database\Helpers\Permission;
1313
use Utopia\Database\Helpers\Role;
1414
use Utopia\Database\Query;
15+
use Utopia\Database\Validator\Index;
1516

1617
trait SpatialTests
1718
{
@@ -2546,4 +2547,65 @@ public function testSpatialIndexRequiredToggling(): void
25462547
}
25472548
}
25482549

2550+
public function testSpatialIndexOnNonSpatial(): void
2551+
{
2552+
/** @var Database $database */
2553+
$database = static::getDatabase();
2554+
if (!$database->getAdapter()->getSupportForSpatialAttributes()) {
2555+
$this->expectNotToPerformAssertions();
2556+
return;
2557+
}
2558+
2559+
try {
2560+
$collUpdateNull = 'spatial_idx_toggle';
2561+
$database->createCollection($collUpdateNull);
2562+
2563+
$database->createAttribute($collUpdateNull, 'loc', Database::VAR_POINT, 0, true);
2564+
$database->createAttribute($collUpdateNull, 'name', Database::VAR_STRING, 0, true);
2565+
try {
2566+
$database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_SPATIAL, ['name']);
2567+
$this->fail('Expected exception when creating spatial index on NULL-able attribute');
2568+
} catch (\Throwable $e) {
2569+
$this->assertInstanceOf(IndexException::class, $e);
2570+
}
2571+
2572+
try {
2573+
$database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_KEY, ['loc']);
2574+
$this->fail('Expected exception when creating non spatial index on spatial attribute');
2575+
} catch (\Throwable $e) {
2576+
$this->assertInstanceOf(IndexException::class, $e);
2577+
}
2578+
2579+
try {
2580+
$database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_KEY, ['loc,name']);
2581+
$this->fail('Expected exception when creating index');
2582+
} catch (\Throwable $e) {
2583+
$this->assertInstanceOf(IndexException::class, $e);
2584+
}
2585+
2586+
try {
2587+
$database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_KEY, ['name,loc']);
2588+
$this->fail('Expected exception when creating index');
2589+
} catch (\Throwable $e) {
2590+
$this->assertInstanceOf(IndexException::class, $e);
2591+
}
2592+
2593+
try {
2594+
$database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_SPATIAL, ['name,loc']);
2595+
$this->fail('Expected exception when creating index');
2596+
} catch (\Throwable $e) {
2597+
$this->assertInstanceOf(IndexException::class, $e);
2598+
}
2599+
2600+
try {
2601+
$database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_SPATIAL, ['loc,name']);
2602+
$this->fail('Expected exception when creating index');
2603+
} catch (\Throwable $e) {
2604+
$this->assertInstanceOf(IndexException::class, $e);
2605+
}
2606+
2607+
} finally {
2608+
$database->deleteCollection($collUpdateNull);
2609+
}
2610+
}
25492611
}

0 commit comments

Comments
 (0)