@@ -48,6 +48,16 @@ class StructureTest extends TestCase
4848 'array ' => false ,
4949 'filters ' => [],
5050 ],
51+ [
52+ '$id ' => 'reviews ' ,
53+ 'type ' => Database::VAR_INTEGER ,
54+ 'format ' => '' ,
55+ 'size ' => 5 ,
56+ 'required ' => false ,
57+ 'signed ' => true ,
58+ 'array ' => true ,
59+ 'filters ' => [],
60+ ],
5161 [
5262 '$id ' => 'price ' ,
5363 'type ' => Database::VAR_FLOAT ,
@@ -316,6 +326,61 @@ public function testIntegerValidation()
316326 $ this ->assertEquals ('Invalid document structure: Attribute "rating" has invalid type. Value must be a valid integer ' , $ validator ->getDescription ());
317327 }
318328
329+ public function testArrayOfIntegersValidation ()
330+ {
331+ $ validator = new Structure (new Document ($ this ->collection ));
332+
333+ $ this ->assertEquals (true , $ validator ->isValid (new Document ([
334+ '$collection ' => 'posts ' ,
335+ 'title ' => 'string ' ,
336+ 'description ' => 'Demo description ' ,
337+ 'rating ' => 5 ,
338+ 'reviews ' => [3 , 4 , 4 , 5 ],
339+ 'price ' => 1.99 ,
340+ 'published ' => true ,
341+ 'tags ' => ['dog ' , 'cat ' , 'mouse ' ],
342+ 'feedback ' => 'team@appwrite.io ' ,
343+ ])));
344+
345+ $ this ->assertEquals (true , $ validator ->isValid (new Document ([
346+ '$collection ' => 'posts ' ,
347+ 'title ' => 'string ' ,
348+ 'description ' => 'Demo description ' ,
349+ 'rating ' => 5 ,
350+ 'reviews ' => [],
351+ 'price ' => 1.99 ,
352+ 'published ' => true ,
353+ 'tags ' => ['dog ' , 'cat ' , 'mouse ' ],
354+ 'feedback ' => 'team@appwrite.io ' ,
355+ ])));
356+
357+ $ this ->assertEquals (true , $ validator ->isValid (new Document ([
358+ '$collection ' => 'posts ' ,
359+ 'title ' => 'string ' ,
360+ 'description ' => 'Demo description ' ,
361+ 'rating ' => 5 ,
362+ 'reviews ' => null ,
363+ 'price ' => 1.99 ,
364+ 'published ' => true ,
365+ 'tags ' => ['dog ' , 'cat ' , 'mouse ' ],
366+ 'feedback ' => 'team@appwrite.io ' ,
367+ ])));
368+
369+ $ this ->assertEquals (false , $ validator ->isValid (new Document ([
370+ '$collection ' => 'posts ' ,
371+ 'title ' => 'string ' ,
372+ 'description ' => 'Demo description ' ,
373+ 'rating ' => 5 ,
374+ 'reviews ' => ['' , 4 , 4 , 5 ],
375+ 'price ' => 1.99 ,
376+ 'published ' => true ,
377+ 'tags ' => ['dog ' , 'cat ' , 'mouse ' ],
378+ 'feedback ' => 'team@appwrite.io ' ,
379+ ])));
380+
381+ $ this ->assertEquals ('Invalid document structure: Attribute "reviews[ \'0 \']" has invalid type. Value must be a valid integer ' , $ validator ->getDescription ());
382+ }
383+
319384 public function testFloatValidation ()
320385 {
321386 $ validator = new Structure (new Document ($ this ->collection ));
0 commit comments