|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Feature; |
| 4 | + |
| 5 | +use Tests\TestCase; |
| 6 | +use Typesense\Exceptions\ObjectNotFound; |
| 7 | +use Exception; |
| 8 | + |
| 9 | +class CurationSetsTest extends TestCase |
| 10 | +{ |
| 11 | + private $upsertResponse = null; |
| 12 | + private $curationSets = null; |
| 13 | + private $curationSetData = [ |
| 14 | + 'items' => [ |
| 15 | + [ |
| 16 | + 'id' => 'rule-1', |
| 17 | + 'rule' => [ |
| 18 | + 'query' => 'test', |
| 19 | + 'match' => 'exact', |
| 20 | + ], |
| 21 | + 'includes' => [ |
| 22 | + [ |
| 23 | + 'id' => '123', |
| 24 | + 'position' => 1, |
| 25 | + ], |
| 26 | + ], |
| 27 | + ], |
| 28 | + ], |
| 29 | + ]; |
| 30 | + |
| 31 | + protected function setUp(): void |
| 32 | + { |
| 33 | + parent::setUp(); |
| 34 | + |
| 35 | + if (!$this->isV30OrAbove()) { |
| 36 | + $this->markTestSkipped('CurationSets is only supported in Typesense v30+'); |
| 37 | + } |
| 38 | + |
| 39 | + $this->curationSets = $this->client()->curationSets; |
| 40 | + $this->upsertResponse = $this->curationSets->upsert('test-curation-set', $this->curationSetData); |
| 41 | + } |
| 42 | + |
| 43 | + protected function tearDown(): void |
| 44 | + { |
| 45 | + try { |
| 46 | + $this->curationSets['test-curation-set']->delete(); |
| 47 | + } catch (Exception $e) { |
| 48 | + // Ignore cleanup errors |
| 49 | + } |
| 50 | + parent::tearDown(); |
| 51 | + } |
| 52 | + |
| 53 | + public function testCanUpsertACurationSet(): void |
| 54 | + { |
| 55 | + $this->assertEquals($this->curationSetData['items'][0]['id'], $this->upsertResponse['items'][0]['id']); |
| 56 | + $this->assertEquals($this->curationSetData['items'][0]['rule'], $this->upsertResponse['items'][0]['rule']); |
| 57 | + $this->assertEquals($this->curationSetData['items'][0]['includes'], $this->upsertResponse['items'][0]['includes']); |
| 58 | + } |
| 59 | + |
| 60 | + public function testCanRetrieveAllCurationSets(): void |
| 61 | + { |
| 62 | + $returnData = $this->curationSets->retrieve(); |
| 63 | + $this->assertIsArray($returnData); |
| 64 | + $this->assertGreaterThan(0, count($returnData)); |
| 65 | + |
| 66 | + $created = null; |
| 67 | + foreach ($returnData as $curationSet) { |
| 68 | + if ($curationSet['name'] === 'test-curation-set') { |
| 69 | + $created = $curationSet; |
| 70 | + break; |
| 71 | + } |
| 72 | + } |
| 73 | + $this->assertNotNull($created); |
| 74 | + } |
| 75 | + |
| 76 | + public function testCanRetrieveASpecificCurationSet(): void |
| 77 | + { |
| 78 | + $returnData = $this->curationSets['test-curation-set']->retrieve(); |
| 79 | + $this->assertEquals($this->curationSetData['items'][0]['id'], $returnData['items'][0]['id']); |
| 80 | + $this->assertEquals($this->curationSetData['items'][0]['rule'], $returnData['items'][0]['rule']); |
| 81 | + $this->assertEquals($this->curationSetData['items'][0]['includes'], $returnData['items'][0]['includes']); |
| 82 | + } |
| 83 | + |
| 84 | + public function testCanDeleteACurationSet(): void |
| 85 | + { |
| 86 | + $returnData = $this->curationSets['test-curation-set']->delete(); |
| 87 | + $this->assertEquals('test-curation-set', $returnData['name']); |
| 88 | + |
| 89 | + $this->expectException(ObjectNotFound::class); |
| 90 | + $this->curationSets['test-curation-set']->retrieve(); |
| 91 | + } |
| 92 | +} |
0 commit comments