forked from typesense/typesense-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalyticsEventsTest.php
More file actions
83 lines (74 loc) · 2.21 KB
/
AnalyticsEventsTest.php
File metadata and controls
83 lines (74 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace Feature;
use Tests\TestCase;
use Exception;
class AnalyticsEventsTest extends TestCase
{
private $ruleName = 'product_queries_aggregation';
protected function setUp(): void
{
parent::setUp();
if ($this->isV30OrAbove()) {
$this->markTestSkipped('Analytics is deprecated in Typesense v30+');
}
$this->client()->collections->create([
"name" => "products",
"fields" => [
[
"name" => "title",
"type" => "string"
],
[
"name" => "popularity",
"type" => "int32",
"optional" => true
]
]
]);
$this->client()->analytics->rules()->upsert($this->ruleName, [
"name" => "products_popularity",
"type" => "counter",
"params" => [
"source" => [
"collections" => [
"products"
],
"events" => [
[
"type" => "click",
"weight" => 1,
"name" => "products_click_event"
]
]
],
"destination" => [
"collection" => "products",
"counter_field" => "popularity"
]
]
]);
}
protected function tearDown(): void
{
parent::tearDown();
if (!$this->isV30OrAbove()) {
try {
$this->client()->analytics->rules()->{'product_queries_aggregation'}->delete();
} catch (Exception $e) {
}
}
}
public function testCanCreateAnEvent(): void
{
$response = $this->client()->analytics->events()->create([
"type" => "click",
"name" => "products_click_event",
"data" => [
"q" => "nike shoes",
"doc_id" => "1024",
"user_id" => "111112"
]
]);
$this->assertTrue($response['ok']);
}
}