-
Notifications
You must be signed in to change notification settings - Fork 246
Expand file tree
/
Copy pathUserResourceViewTest.php
More file actions
56 lines (45 loc) · 1.81 KB
/
UserResourceViewTest.php
File metadata and controls
56 lines (45 loc) · 1.81 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
<?php
namespace Tests\Model;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\ProcessRequestToken;
use ProcessMaker\Models\UserResourceView;
use Tests\Feature\Shared\RequestHelper;
use Tests\TestCase;
class UserResourceViewTest extends TestCase
{
use RequestHelper;
private function createUserResourceView($resource)
{
$now = now();
UserResourceView::factory()->create([
'user_id' => $this->user->id,
'viewable_id' => $resource->id,
'viewable_type' => get_class($resource),
'created_at' => $now,
]);
return $now;
}
public function testAddsUserViewedAtToRequests()
{
$processRequest = ProcessRequest::factory()->create();
$processRequestNotViewed = ProcessRequest::factory()->create();
$now = $this->createUserResourceView($processRequest);
$response = $this->apiCall('GET', '/requests');
$results = collect($response->json()['data']);
$this->assertEquals(
(string) $now,
$results->first(fn ($i) => $i['id'] === $processRequest->id)['user_viewed_at']
);
$this->assertNull($results->first(fn ($i) => $i['id'] === $processRequestNotViewed->id)['user_viewed_at']);
}
public function testAddsUserViewedAtToTasks()
{
$task = ProcessRequestToken::factory()->create();
$taskNotViewed = ProcessRequestToken::factory()->create();
$now = $this->createUserResourceView($task);
$response = $this->apiCall('GET', '/tasks');
$results = collect($response->json()['data']);
$this->assertEquals((string) $now, $results->first(fn ($i) => $i['id'] === $task->id)['user_viewed_at']);
$this->assertNull($results->first(fn ($i) => $i['id'] === $taskNotViewed->id)['user_viewed_at']);
}
}