|
3 | 3 | namespace Tests\Unit\Validator\Query; |
4 | 4 |
|
5 | 5 | use PHPUnit\Framework\TestCase; |
| 6 | +use Utopia\Database\Attribute; |
6 | 7 | use Utopia\Database\Document; |
7 | 8 | use Utopia\Database\Exception; |
8 | 9 | use Utopia\Database\Query; |
| 10 | +use Utopia\Database\Relationship; |
| 11 | +use Utopia\Database\RelationshipSide; |
9 | 12 | use Utopia\Database\Validator\Query\Filter; |
10 | 13 | use Utopia\Query\Method; |
11 | 14 | use Utopia\Query\Schema\ColumnType; |
@@ -217,6 +220,45 @@ public function test_not_between(): void |
217 | 220 | $this->assertEquals('NotBetween queries require exactly two values.', $this->validator->getDescription()); |
218 | 221 | } |
219 | 222 |
|
| 223 | + public function test_nested_path_on_a_plain_attribute_is_rejected(): void |
| 224 | + { |
| 225 | + $this->assertFalse($this->validator->isValid(Query::equal('string.x', ['a']))); |
| 226 | + $this->assertSame('Cannot query nested attribute on: string', $this->validator->getDescription()); |
| 227 | + |
| 228 | + $this->assertFalse($this->validator->isValid(Query::greaterThan('integer.x', 1))); |
| 229 | + $this->assertSame('Cannot query nested attribute on: integer', $this->validator->getDescription()); |
| 230 | + } |
| 231 | + |
| 232 | + public function test_nested_path_on_a_relationship_or_object_is_accepted(): void |
| 233 | + { |
| 234 | + $validator = new Filter( |
| 235 | + attributes: [ |
| 236 | + Attribute::relationship('artist', Relationship::manyToOne('artists'), RelationshipSide::Parent)->toDocument(), |
| 237 | + new Document([ |
| 238 | + '$id' => 'meta', |
| 239 | + 'key' => 'meta', |
| 240 | + 'type' => ColumnType::Object->value, |
| 241 | + 'array' => false, |
| 242 | + ]), |
| 243 | + ], |
| 244 | + idAttributeType: ColumnType::Integer->value, |
| 245 | + ); |
| 246 | + |
| 247 | + $this->assertTrue($validator->isValid(Query::equal('artist.name', ['a'])), $validator->getDescription()); |
| 248 | + $this->assertTrue($validator->isValid(Query::equal('meta.key', ['a'])), $validator->getDescription()); |
| 249 | + } |
| 250 | + |
| 251 | + public function test_nested_path_on_a_plain_attribute_is_left_to_a_schemaless_adapter(): void |
| 252 | + { |
| 253 | + $validator = new Filter( |
| 254 | + attributes: [new Document(['$id' => 'string', 'key' => 'string', 'type' => ColumnType::String->value, 'array' => false])], |
| 255 | + idAttributeType: ColumnType::Integer->value, |
| 256 | + supportForAttributes: false, |
| 257 | + ); |
| 258 | + |
| 259 | + $this->assertTrue($validator->isValid(Query::equal('string.x', ['a'])), $validator->getDescription()); |
| 260 | + } |
| 261 | + |
220 | 262 | public function test_dotted_join_alias_is_accepted_after_allow_join_aliases(): void |
221 | 263 | { |
222 | 264 | $this->validator->allowJoinAliases(['sec']); |
|
0 commit comments