-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathNotificationsTest.php
More file actions
167 lines (137 loc) · 4.24 KB
/
Copy pathNotificationsTest.php
File metadata and controls
167 lines (137 loc) · 4.24 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
namespace Tests\Feature\Api;
use Carbon\Carbon;
use Faker\Factory as Faker;
use Illuminate\Support\Facades\DB;
use ProcessMaker\Models\Notification;
use ProcessMaker\Models\User;
use Ramsey\Uuid\Uuid;
use Tests\Feature\Shared\RequestHelper;
use Tests\TestCase;
class NotificationsTest extends TestCase
{
use RequestHelper;
const API_TEST_URL = '/notifications';
const STRUCTURE = [
'id',
'type',
'notifiable_type',
'notifiable_id',
'data',
'read_at',
'updated_at',
'created_at',
];
/**
* Create new notification successfully
*/
public function testCreateNotification()
{
//Post title duplicated
$url = self::API_TEST_URL;
$response = $this->apiCall('POST', $url, [
'type' => 'TEST',
'notifiable_type' => 'NOTIFIABLE/TEST',
'data' => '[]',
'notifiable_id' => 1,
]);
//Validate the header status code
$response->assertStatus(201);
}
/**
* Get a list of Notifications without query parameters.
*/
public function testListNotification()
{
$existing = Notification::count();
Notification::factory()->count(10)->create([
'notifiable_type' => User::class,
'notifiable_id' => $this->user->id,
]);
$response = $this->apiCall('GET', self::API_TEST_URL);
//Validate the header status code
$response->assertStatus(200);
// Verify structure
$response->assertJsonStructure([
'data',
'meta',
]);
// Verify count
$this->assertEquals(10 + $existing, $response->json()['meta']['total']);
}
/**
* Test to verify that the list dates are in the correct format (yyyy-mm-dd H:i+GMT)
*/
public function testNotificationListDates()
{
$newEntity = Notification::factory()->create([
'notifiable_type' => User::class,
'notifiable_id' => $this->user->id,
]);
$route = self::API_TEST_URL;
$response = $this->apiCall('GET', $route);
$this->assertEquals(
$newEntity->created_at->format('c'),
$response->getData()->data[0]->created_at
);
$this->assertEquals(
$newEntity->updated_at->format('c'),
$response->getData()->data[0]->updated_at
);
}
/**
* Get a notification
*/
public function testGetNotification()
{
//get the id from the factory
$notification = Notification::factory()->create()->id;
//load api
$response = $this->apiCall('GET', self::API_TEST_URL . '/' . $notification);
//Validate the status is correct
$response->assertStatus(200);
//verify structure
$response->assertJsonStructure(self::STRUCTURE);
}
/**
* Update notification in process
*/
public function testUpdateNotification()
{
$url = self::API_TEST_URL . '/' . Notification::factory()->create()->id;
//Load the starting notification data
$verify = $this->apiCall('GET', $url);
//Post saved success
$response = $this->apiCall('PUT', $url, [
'data' => '["test":1]',
]);
//Validate the header status code
$response->assertStatus(204);
//Load the updated notification data
$verify_new = $this->apiCall('GET', $url);
//Check that it has changed
$this->assertNotEquals($verify, $verify_new);
}
/**
* Delete notification in process
*/
public function testDeleteNotification()
{
//Remove notification
$url = self::API_TEST_URL . '/' . Notification::factory()->create()->id;
$response = $this->apiCall('DELETE', $url);
//Validate the header status code
$response->assertStatus(204);
}
/**
* The notification does not exist in process
*/
public function testDeleteNotificationNotExist()
{
//Notification not exist
$url = self::API_TEST_URL . '/' . Notification::factory()->make()->id;
$response = $this->apiCall('DELETE', $url);
//Validate the header status code
$response->assertStatus(405);
}
}