Skip to content

Commit a4a2412

Browse files
committed
test: document
1 parent ac03da0 commit a4a2412

2 files changed

Lines changed: 65 additions & 11 deletions

File tree

tests/Feature/DocumentTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Feature;
4+
5+
use Tests\TestCase;
6+
use Typesense\Exceptions\ObjectNotFound;
7+
8+
class DocumentTest extends TestCase
9+
{
10+
private $documentId = '1';
11+
private $testDocument = null;
12+
13+
protected function setUp(): void
14+
{
15+
parent::setUp();
16+
$this->setUpCollection('books');
17+
$this->setUpDocuments('books');
18+
19+
$this->testDocument = $this->client()->collections['books']->documents[$this->documentId];
20+
}
21+
22+
public function testCanRetrieveADocumentById(): void
23+
{
24+
$response = $this->testDocument->retrieve();
25+
$this->assertEquals($this->documentId, $response['id']);
26+
}
27+
28+
public function testCanUpdateADocumentById(): void
29+
{
30+
$partialDocument = [
31+
"title" => "hello there :D",
32+
];
33+
$response = $this->testDocument->update($partialDocument);
34+
$this->assertEquals("hello there :D", $response['title']);
35+
}
36+
37+
public function testCanUpdateADocumentWithDirtyValuesById(): void
38+
{
39+
$partialDocument = [
40+
"title" => 1,
41+
];
42+
$response = $this->testDocument->update(
43+
$partialDocument,
44+
[
45+
"dirty_values" => "coerce_or_reject",
46+
]
47+
);
48+
$this->assertIsString($response['title']);
49+
}
50+
51+
public function testCanDeleteADocumentById(): void
52+
{
53+
$response = $this->testDocument->delete();
54+
$this->assertEquals($this->documentId, $response['id']);
55+
56+
$this->expectException(ObjectNotFound::class);
57+
$this->testDocument->retrieve();
58+
}
59+
}

tests/data/books.data.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
[
22
{
3+
"id": "1",
34
"title": "Book 1",
45
"description": "Wonderful Description",
5-
"authors": [
6-
"Jane",
7-
"John"
8-
],
6+
"authors": ["Jane", "John"],
97
"isbn": "1234567890",
108
"publisher": "AwesomeBooks",
119
"pages": 123
1210
},
1311
{
12+
"id": "2",
1413
"title": "Book 2",
1514
"description": "Another helpful description",
16-
"authors": [
17-
"Jeff",
18-
"Mia"
19-
],
15+
"authors": ["Jeff", "Mia"],
2016
"isbn": "1234567891",
2117
"publisher": "AwesomeBooks",
2218
"pages": 150
2319
},
2420
{
21+
"id": "3",
2522
"title": "Book 3",
2623
"description": "Another useless description",
27-
"authors": [
28-
"Martin"
29-
],
24+
"authors": ["Martin"],
3025
"isbn": "1234567892",
3126
"publisher": "PubLishEr",
3227
"pages": 268

0 commit comments

Comments
 (0)