Skip to content

Commit 484c434

Browse files
updated structure unit test
1 parent 5b5e2c5 commit 484c434

1 file changed

Lines changed: 58 additions & 2 deletions

File tree

tests/unit/Validator/StructureTest.php

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ public function testCollection(): void
153153
'published' => true,
154154
'tags' => ['dog', 'cat', 'mouse'],
155155
'feedback' => 'team@appwrite.io',
156+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
157+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
156158
])));
157159

158160
$this->assertEquals('Invalid document structure: Collection not found', $validator->getDescription());
@@ -170,6 +172,8 @@ public function testRequiredKeys(): void
170172
'published' => true,
171173
'tags' => ['dog', 'cat', 'mouse'],
172174
'feedback' => 'team@appwrite.io',
175+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
176+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
173177
])));
174178

175179
$this->assertEquals('Invalid document structure: Missing required attribute "title"', $validator->getDescription());
@@ -188,6 +192,8 @@ public function testNullValues(): void
188192
'published' => true,
189193
'tags' => ['dog', 'cat', 'mouse'],
190194
'feedback' => 'team@appwrite.io',
195+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
196+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
191197
])));
192198

193199
$this->assertEquals(true, $validator->isValid(new Document([
@@ -199,6 +205,8 @@ public function testNullValues(): void
199205
'published' => true,
200206
'tags' => ['dog', null, 'mouse'],
201207
'feedback' => 'team@appwrite.io',
208+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
209+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
202210
])));
203211
}
204212

@@ -216,6 +224,8 @@ public function testUnknownKeys(): void
216224
'published' => true,
217225
'tags' => ['dog', 'cat', 'mouse'],
218226
'feedback' => 'team@appwrite.io',
227+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
228+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
219229
])));
220230

221231
$this->assertEquals('Invalid document structure: Unknown attribute: "titlex"', $validator->getDescription());
@@ -234,6 +244,8 @@ public function testIntegerAsString(): void
234244
'published' => true,
235245
'tags' => ['dog', 'cat', 'mouse'],
236246
'feedback' => 'team@appwrite.io',
247+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
248+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
237249
])));
238250

239251
$this->assertEquals('Invalid document structure: Attribute "rating" has invalid type. Value must be a valid integer', $validator->getDescription());
@@ -252,6 +264,8 @@ public function testValidDocument(): void
252264
'published' => true,
253265
'tags' => ['dog', 'cat', 'mouse'],
254266
'feedback' => 'team@appwrite.io',
267+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
268+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
255269
])));
256270
}
257271

@@ -268,6 +282,8 @@ public function testStringValidation(): void
268282
'published' => true,
269283
'tags' => ['dog', 'cat', 'mouse'],
270284
'feedback' => 'team@appwrite.io',
285+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
286+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
271287
])));
272288

273289
$this->assertEquals('Invalid document structure: Attribute "title" has invalid type. Value must be a valid string and no longer than 256 chars', $validator->getDescription());
@@ -286,6 +302,8 @@ public function testArrayOfStringsValidation(): void
286302
'published' => true,
287303
'tags' => [1, 'cat', 'mouse'],
288304
'feedback' => 'team@appwrite.io',
305+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
306+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
289307
])));
290308

291309
$this->assertEquals('Invalid document structure: Attribute "tags[\'0\']" has invalid type. Value must be a valid string and no longer than 55 chars', $validator->getDescription());
@@ -299,6 +317,8 @@ public function testArrayOfStringsValidation(): void
299317
'published' => true,
300318
'tags' => [true],
301319
'feedback' => 'team@appwrite.io',
320+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
321+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
302322
])));
303323

304324
$this->assertEquals('Invalid document structure: Attribute "tags[\'0\']" has invalid type. Value must be a valid string and no longer than 55 chars', $validator->getDescription());
@@ -312,6 +332,8 @@ public function testArrayOfStringsValidation(): void
312332
'published' => true,
313333
'tags' => [],
314334
'feedback' => 'team@appwrite.io',
335+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
336+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
315337
])));
316338

317339
$this->assertEquals(false, $validator->isValid(new Document([
@@ -323,6 +345,8 @@ public function testArrayOfStringsValidation(): void
323345
'published' => true,
324346
'tags' => ['too-long-tag-name-to-make-sure-the-length-validator-inside-string-attribute-type-fails-properly'],
325347
'feedback' => 'team@appwrite.io',
348+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
349+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
326350
])));
327351

328352
$this->assertEquals('Invalid document structure: Attribute "tags[\'0\']" has invalid type. Value must be a valid string and no longer than 55 chars', $validator->getDescription());
@@ -343,7 +367,9 @@ public function testArrayAsObjectValidation(): void
343367
'price' => 1.99,
344368
'published' => true,
345369
'tags' => ['name' => 'dog'],
346-
'feedback' => 'team@appwrite.io'
370+
'feedback' => 'team@appwrite.io',
371+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
372+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
347373
])));
348374
}
349375

@@ -359,7 +385,9 @@ public function testArrayOfObjectsValidation(): void
359385
'price' => 1.99,
360386
'published' => true,
361387
'tags' => [['name' => 'dog']],
362-
'feedback' => 'team@appwrite.io'
388+
'feedback' => 'team@appwrite.io',
389+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
390+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
363391
])));
364392
}
365393

@@ -376,6 +404,8 @@ public function testIntegerValidation(): void
376404
'published' => false,
377405
'tags' => ['dog', 'cat', 'mouse'],
378406
'feedback' => 'team@appwrite.io',
407+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
408+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
379409
])));
380410

381411
$this->assertEquals('Invalid document structure: Attribute "rating" has invalid type. Value must be a valid integer', $validator->getDescription());
@@ -389,6 +419,8 @@ public function testIntegerValidation(): void
389419
'published' => false,
390420
'tags' => ['dog', 'cat', 'mouse'],
391421
'feedback' => 'team@appwrite.io',
422+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
423+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
392424
])));
393425

394426
$this->assertEquals('Invalid document structure: Attribute "rating" has invalid type. Value must be a valid integer', $validator->getDescription());
@@ -408,6 +440,8 @@ public function testArrayOfIntegersValidation(): void
408440
'published' => true,
409441
'tags' => ['dog', 'cat', 'mouse'],
410442
'feedback' => 'team@appwrite.io',
443+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
444+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
411445
])));
412446

413447
$this->assertEquals(true, $validator->isValid(new Document([
@@ -420,6 +454,8 @@ public function testArrayOfIntegersValidation(): void
420454
'published' => true,
421455
'tags' => ['dog', 'cat', 'mouse'],
422456
'feedback' => 'team@appwrite.io',
457+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
458+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
423459
])));
424460

425461
$this->assertEquals(true, $validator->isValid(new Document([
@@ -432,6 +468,8 @@ public function testArrayOfIntegersValidation(): void
432468
'published' => true,
433469
'tags' => ['dog', 'cat', 'mouse'],
434470
'feedback' => 'team@appwrite.io',
471+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
472+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
435473
])));
436474

437475
$this->assertEquals(false, $validator->isValid(new Document([
@@ -444,6 +482,8 @@ public function testArrayOfIntegersValidation(): void
444482
'published' => true,
445483
'tags' => ['dog', 'cat', 'mouse'],
446484
'feedback' => 'team@appwrite.io',
485+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
486+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
447487
])));
448488

449489
$this->assertEquals('Invalid document structure: Attribute "reviews[\'0\']" has invalid type. Value must be a valid integer', $validator->getDescription());
@@ -462,6 +502,8 @@ public function testFloatValidation(): void
462502
'published' => false,
463503
'tags' => ['dog', 'cat', 'mouse'],
464504
'feedback' => 'team@appwrite.io',
505+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
506+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
465507
])));
466508

467509
$this->assertEquals('Invalid document structure: Attribute "price" has invalid type. Value must be a valid float', $validator->getDescription());
@@ -475,6 +517,8 @@ public function testFloatValidation(): void
475517
'published' => false,
476518
'tags' => ['dog', 'cat', 'mouse'],
477519
'feedback' => 'team@appwrite.io',
520+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
521+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
478522
])));
479523

480524
$this->assertEquals('Invalid document structure: Attribute "price" has invalid type. Value must be a valid float', $validator->getDescription());
@@ -493,6 +537,8 @@ public function testBooleanValidation(): void
493537
'published' => 1,
494538
'tags' => ['dog', 'cat', 'mouse'],
495539
'feedback' => 'team@appwrite.io',
540+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
541+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
496542
])));
497543

498544
$this->assertEquals('Invalid document structure: Attribute "published" has invalid type. Value must be a valid boolean', $validator->getDescription());
@@ -506,6 +552,8 @@ public function testBooleanValidation(): void
506552
'published' => '',
507553
'tags' => ['dog', 'cat', 'mouse'],
508554
'feedback' => 'team@appwrite.io',
555+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
556+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
509557
])));
510558

511559
$this->assertEquals('Invalid document structure: Attribute "published" has invalid type. Value must be a valid boolean', $validator->getDescription());
@@ -524,6 +572,8 @@ public function testFormatValidation(): void
524572
'published' => true,
525573
'tags' => ['dog', 'cat', 'mouse'],
526574
'feedback' => 'team_appwrite.io',
575+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
576+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
527577
])));
528578

529579
$this->assertEquals('Invalid document structure: Attribute "feedback" has invalid format. Value must be a valid email address', $validator->getDescription());
@@ -542,6 +592,8 @@ public function testIntegerMaxRange(): void
542592
'published' => true,
543593
'tags' => ['dog', 'cat', 'mouse'],
544594
'feedback' => 'team@appwrite.io',
595+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
596+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
545597
])));
546598

547599
$this->assertEquals('Invalid document structure: Attribute "rating" has invalid type. Value must be a valid range between -2,147,483,647 and 2,147,483,647', $validator->getDescription());
@@ -560,6 +612,8 @@ public function testDoubleUnsigned(): void
560612
'published' => true,
561613
'tags' => ['dog', 'cat', 'mouse'],
562614
'feedback' => 'team@appwrite.io',
615+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
616+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
563617
])));
564618

565619
$this->assertStringContainsString('Invalid document structure: Attribute "price" has invalid type. Value must be a valid range between 0 and ', $validator->getDescription());
@@ -578,6 +632,8 @@ public function testDoubleMaxRange(): void
578632
'published' => true,
579633
'tags' => ['dog', 'cat', 'mouse'],
580634
'feedback' => 'team@appwrite.io',
635+
'$createdAt' => '2000-04-01T12:00:00.000+00:00',
636+
'$updatedAt' => '2000-04-01T12:00:00.000+00:00'
581637
])));
582638
}
583639

0 commit comments

Comments
 (0)