|
6 | 6 |
|
7 | 7 | class AnalyticsEventsTest extends TestCase |
8 | 8 | { |
9 | | - //* there is no method for sending events |
10 | | - // public function testCanCreateAnEvent(): void |
11 | | - // { |
12 | | - // $returnData = $this->client()->analytics->rules()->even |
13 | | - // $this->assertEquals($returnData['name'], $this->ruleName); |
14 | | - // } |
| 9 | + private $ruleName = 'product_queries_aggregation'; |
15 | 10 |
|
16 | | - public function testNeedImplementationForAnalyticsEvents(): void |
| 11 | + protected function setUp(): void |
17 | 12 | { |
18 | | - $this->markTestIncomplete( |
19 | | - 'This test has not been implemented yet.', |
20 | | - ); |
| 13 | + parent::setUp(); |
| 14 | + $this->client()->collections->create([ |
| 15 | + "name" => "products", |
| 16 | + "fields" => [ |
| 17 | + [ |
| 18 | + "name" => "title", |
| 19 | + "type" => "string" |
| 20 | + ], |
| 21 | + [ |
| 22 | + "name" => "popularity", |
| 23 | + "type" => "int32", |
| 24 | + "optional" => true |
| 25 | + ] |
| 26 | + ] |
| 27 | + ]); |
| 28 | + $this->client()->analytics->rules()->upsert($this->ruleName, [ |
| 29 | + "name" => "products_popularity", |
| 30 | + "type" => "counter", |
| 31 | + "params" => [ |
| 32 | + "source" => [ |
| 33 | + "collections" => [ |
| 34 | + "products" |
| 35 | + ], |
| 36 | + "events" => [ |
| 37 | + [ |
| 38 | + "type" => "click", |
| 39 | + "weight" => 1, |
| 40 | + "name" => "products_click_event" |
| 41 | + ] |
| 42 | + ] |
| 43 | + ], |
| 44 | + "destination" => [ |
| 45 | + "collection" => "products", |
| 46 | + "counter_field" => "popularity" |
| 47 | + ] |
| 48 | + ] |
| 49 | + ]); |
| 50 | + } |
| 51 | + |
| 52 | + protected function tearDown(): void |
| 53 | + { |
| 54 | + parent::tearDown(); |
| 55 | + $this->client()->analytics->rules()->{'product_queries_aggregation'}->delete(); |
| 56 | + } |
| 57 | + |
| 58 | + public function testCanCreateAnEvent(): void |
| 59 | + { |
| 60 | + $response = $this->client()->analytics->events()->create([ |
| 61 | + "type" => "click", |
| 62 | + "name" => "products_click_event", |
| 63 | + "data" => [ |
| 64 | + "q" => "nike shoes", |
| 65 | + "doc_id" => "1024", |
| 66 | + "user_id" => "111112" |
| 67 | + ] |
| 68 | + ]); |
| 69 | + $this->assertTrue($response['ok']); |
21 | 70 | } |
22 | 71 | } |
0 commit comments