|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Feature; |
| 4 | + |
| 5 | +use Tests\TestCase; |
| 6 | +use Typesense\Exceptions\ObjectNotFound; |
| 7 | + |
| 8 | +class AnalyticsRuleTest extends TestCase |
| 9 | +{ |
| 10 | + private $ruleName = 'product_queries_aggregation'; |
| 11 | + private $ruleConfiguration = [ |
| 12 | + "type" => "popular_queries", |
| 13 | + "params" => [ |
| 14 | + "source" => [ |
| 15 | + "collections" => ["products"] |
| 16 | + ], |
| 17 | + "destination" => [ |
| 18 | + "collection" => "product_queries" |
| 19 | + ], |
| 20 | + "expand_query" => false, |
| 21 | + "limit" => 1000 |
| 22 | + ] |
| 23 | + ]; |
| 24 | + private $ruleUpsertResponse = null; |
| 25 | + |
| 26 | + protected function setUp(): void |
| 27 | + { |
| 28 | + parent::setUp(); |
| 29 | + $this->ruleUpsertResponse = $this->client()->analytics->rules()->upsert($this->ruleName, $this->ruleConfiguration); |
| 30 | + } |
| 31 | + |
| 32 | + public function testCanUpsertARule(): void |
| 33 | + { |
| 34 | + $this->assertEquals($this->ruleName, $this->ruleUpsertResponse['name']); |
| 35 | + } |
| 36 | + |
| 37 | + public function testCanRetrieveARule(): void |
| 38 | + { |
| 39 | + $returnData = $this->client()->analytics->rules()->{$this->ruleName}->retrieve(); |
| 40 | + $this->assertEquals($returnData['name'], $this->ruleName); |
| 41 | + } |
| 42 | + |
| 43 | + public function testCanDeleteARule(): void |
| 44 | + { |
| 45 | + $returnData = $this->client()->analytics->rules()->{$this->ruleName}->delete(); |
| 46 | + $this->assertEquals($returnData['name'], $this->ruleName); |
| 47 | + |
| 48 | + $this->expectException(ObjectNotFound::class); |
| 49 | + $this->client()->analytics->rules()->{$this->ruleName}->retrieve(); |
| 50 | + } |
| 51 | + |
| 52 | + public function testCanRetrieveAllRules(): void |
| 53 | + { |
| 54 | + $returnData = $this->client()->analytics->rules()->retrieve(); |
| 55 | + $this->assertEquals(count($returnData['rules']), 1); |
| 56 | + } |
| 57 | +} |
0 commit comments