22
33namespace Tests ;
44
5- use Factories \StackkitCloudTaskFactory ;
65use Google \Cloud \Tasks \V2 \RetryConfig ;
76use Illuminate \Support \Carbon ;
87use Stackkit \LaravelGoogleCloudTasksQueue \CloudTasksApi ;
@@ -19,7 +18,7 @@ class CloudTasksMonitoringTest extends TestCase
1918 public function test_loading_dashboard_works ()
2019 {
2120 // Arrange
22- StackkitCloudTaskFactory:: new ( )->create ();
21+ factory (StackkitCloudTask::class )->create ();
2322
2423 // Act
2524 $ response = $ this ->getJson ('/cloud-tasks-api/dashboard ' );
@@ -40,13 +39,15 @@ public function it_counts_the_number_of_tasks()
4039 $ thisHour = now ()->startOfHour ();
4140 $ thisDay = now ()->startOfDay ();
4241
43- StackkitCloudTaskFactory::new ()
44- ->crossJoinSequence (
45- [['status ' => 'failed ' ], ['status ' => 'queued ' ]],
46- [['created_at ' => $ thisMinute ], ['created_at ' => $ thisHour ], ['created_at ' => $ thisDay ], ['created_at ' => $ lastMinute ]]
47- )
48- ->count (8 )
49- ->create ();
42+ factory (StackkitCloudTask::class)->create (['status ' => 'queued ' , 'created_at ' => $ thisMinute ]);
43+ factory (StackkitCloudTask::class)->create (['status ' => 'queued ' , 'created_at ' => $ thisHour ]);
44+ factory (StackkitCloudTask::class)->create (['status ' => 'queued ' , 'created_at ' => $ thisDay ]);
45+ factory (StackkitCloudTask::class)->create (['status ' => 'queued ' , 'created_at ' => $ lastMinute ]);
46+
47+ factory (StackkitCloudTask::class)->create (['status ' => 'failed ' , 'created_at ' => $ thisMinute ]);
48+ factory (StackkitCloudTask::class)->create (['status ' => 'failed ' , 'created_at ' => $ thisHour ]);
49+ factory (StackkitCloudTask::class)->create (['status ' => 'failed ' , 'created_at ' => $ thisDay ]);
50+ factory (StackkitCloudTask::class)->create (['status ' => 'failed ' , 'created_at ' => $ lastMinute ]);
5051
5152 // Act
5253 $ response = $ this ->getJson ('/cloud-tasks-api/dashboard ' );
@@ -67,19 +68,14 @@ public function it_counts_the_number_of_tasks()
6768 public function tasks_shows_newest_first ()
6869 {
6970 // Arrange
70- $ tasks = StackkitCloudTaskFactory::new ()
71- ->count (2 )
72- ->sequence (
73- ['created_at ' => now ()->subMinute ()],
74- ['created_at ' => now ()],
75- )
76- ->create ();
71+ factory (StackkitCloudTask::class)->create (['created_at ' => now ()->subMinute ()]);
72+ $ task = factory (StackkitCloudTask::class)->create (['created_at ' => now ()]);
7773
7874 // Act
7975 $ response = $ this ->getJson ('/cloud-tasks-api/tasks ' );
8076
8177 // Assert
82- $ this ->assertEquals ($ tasks [ 1 ] ->task_uuid , $ response ->json ('0.uuid ' ));
78+ $ this ->assertEquals ($ task ->task_uuid , $ response ->json ('0.uuid ' ));
8379 }
8480
8581 /**
@@ -88,13 +84,8 @@ public function tasks_shows_newest_first()
8884 public function it_shows_tasks_only_from_today ()
8985 {
9086 // Arrange
91- $ tasks = StackkitCloudTaskFactory::new ()
92- ->count (2 )
93- ->sequence (
94- ['created_at ' => today ()],
95- ['created_at ' => today ()->subDay ()],
96- )
97- ->create ();
87+ factory (StackkitCloudTask::class)->create (['created_at ' => today ()]);
88+ factory (StackkitCloudTask::class)->create (['created_at ' => today ()->subDay ()]);
9889
9990 // Act
10091 $ response = $ this ->getJson ('/cloud-tasks-api/tasks ' );
@@ -109,13 +100,8 @@ public function it_shows_tasks_only_from_today()
109100 public function it_can_filter_only_failed_tasks ()
110101 {
111102 // Arrange
112- StackkitCloudTaskFactory::new ()
113- ->count (2 )
114- ->sequence (
115- ['status ' => 'pending ' ],
116- ['status ' => 'failed ' ],
117- )
118- ->create ();
103+ factory (StackkitCloudTask::class)->create (['status ' => 'pending ' ]);
104+ factory (StackkitCloudTask::class)->create (['status ' => 'failed ' ]);
119105
120106 // Act
121107 $ response = $ this ->getJson ('/cloud-tasks-api/tasks?filter=failed ' );
@@ -130,15 +116,10 @@ public function it_can_filter_only_failed_tasks()
130116 public function it_can_filter_tasks_created_at_exact_time ()
131117 {
132118 // Arrange
133- StackkitCloudTaskFactory::new ()
134- ->count (4 )
135- ->sequence (
136- ['created_at ' => now ()->setTime (15 ,4 , 59 )],
137- ['created_at ' => now ()->setTime (16 , 5 , 0 )],
138- ['created_at ' => now ()->setTime (16 , 5 , 59 )],
139- ['created_at ' => now ()->setTime (16 , 6 , 0 )],
140- )
141- ->create ();
119+ factory (StackkitCloudTask::class)->create (['created_at ' => now ()->setTime (15 ,4 , 59 )]);
120+ factory (StackkitCloudTask::class)->create (['created_at ' => now ()->setTime (16 ,5 , 0 )]);
121+ factory (StackkitCloudTask::class)->create (['created_at ' => now ()->setTime (16 ,5 , 59 )]);
122+ factory (StackkitCloudTask::class)->create (['created_at ' => now ()->setTime (16 ,6 , 0 )]);
142123
143124 // Act
144125 $ response = $ this ->getJson ('/cloud-tasks-api/tasks?time=16:05 ' );
@@ -153,14 +134,9 @@ public function it_can_filter_tasks_created_at_exact_time()
153134 public function it_can_filter_tasks_created_at_exact_hour ()
154135 {
155136 // Arrange
156- StackkitCloudTaskFactory::new ()
157- ->count (4 )
158- ->sequence (
159- ['created_at ' => now ()->setTime (15 ,59 , 59 )],
160- ['created_at ' => now ()->setTime (16 , 5 , 59 )],
161- ['created_at ' => now ()->setTime (16 , 32 , 32 )],
162- )
163- ->create ();
137+ factory (StackkitCloudTask::class)->create (['created_at ' => now ()->setTime (15 ,59 , 59 )]);
138+ factory (StackkitCloudTask::class)->create (['created_at ' => now ()->setTime (16 ,5 , 59 )]);
139+ factory (StackkitCloudTask::class)->create (['created_at ' => now ()->setTime (16 ,32 , 32 )]);
164140
165141 // Act
166142 $ response = $ this ->getJson ('/cloud-tasks-api/tasks?hour=16 ' );
@@ -175,14 +151,9 @@ public function it_can_filter_tasks_created_at_exact_hour()
175151 public function it_can_filter_tasks_by_queue ()
176152 {
177153 // Arrange
178- StackkitCloudTaskFactory::new ()
179- ->count (3 )
180- ->sequence (
181- ['queue ' => 'barbequeue ' ],
182- ['queue ' => 'barbequeue-priority ' ],
183- ['queue ' => 'barbequeue-priority ' ],
184- )
185- ->create ();
154+ factory (StackkitCloudTask::class)->create (['queue ' => 'barbequeue ' ]);
155+ factory (StackkitCloudTask::class)->create (['queue ' => 'barbequeue-priority ' ]);
156+ factory (StackkitCloudTask::class)->create (['queue ' => 'barbequeue-priority ' ]);
186157
187158 // Act
188159 $ response = $ this ->getJson ('/cloud-tasks-api/tasks?queue=barbequeue-priority ' );
@@ -197,15 +168,10 @@ public function it_can_filter_tasks_by_queue()
197168 public function it_can_filter_tasks_by_status ()
198169 {
199170 // Arrange
200- StackkitCloudTaskFactory::new ()
201- ->count (4 )
202- ->sequence (
203- ['status ' => 'queued ' ],
204- ['status ' => 'pending ' ],
205- ['status ' => 'failed ' ],
206- ['status ' => 'failed ' ],
207- )
208- ->create ();
171+ factory (StackkitCloudTask::class)->create (['status ' => 'queued ' ]);
172+ factory (StackkitCloudTask::class)->create (['status ' => 'pending ' ]);
173+ factory (StackkitCloudTask::class)->create (['status ' => 'failed ' ]);
174+ factory (StackkitCloudTask::class)->create (['status ' => 'failed ' ]);
209175
210176 // Act
211177 $ response = $ this ->getJson ('/cloud-tasks-api/tasks?status=failed ' );
@@ -220,9 +186,7 @@ public function it_can_filter_tasks_by_status()
220186 public function it_shows_max_100_tasks ()
221187 {
222188 // Arrange
223- StackkitCloudTaskFactory::new ()
224- ->count (101 )
225- ->create ();
189+ factory (StackkitCloudTask::class)->times (101 )->create ();
226190
227191 // Act
228192 $ response = $ this ->getJson ('/cloud-tasks-api/tasks ' );
@@ -237,7 +201,7 @@ public function it_shows_max_100_tasks()
237201 public function it_returns_the_correct_task_fields ()
238202 {
239203 // Arrange
240- $ task = StackkitCloudTaskFactory:: new ( )->create ();
204+ $ task = factory (StackkitCloudTask::class )->create ();
241205
242206 // Act
243207 $ response = $ this ->getJson ('/cloud-tasks-api/tasks ' );
@@ -258,7 +222,7 @@ public function it_returns_the_correct_task_fields()
258222 public function it_returns_info_about_a_specific_task ()
259223 {
260224 // Arrange
261- $ task = StackkitCloudTaskFactory:: new ( )->create ();
225+ $ task = factory (StackkitCloudTask::class )->create ();
262226
263227 // Act
264228 $ response = $ this ->getJson ('/cloud-tasks-api/task/ ' . $ task ->task_uuid );
@@ -287,7 +251,7 @@ public function when_a_job_is_dispatched_it_will_be_added_to_the_monitor()
287251 $ task = StackkitCloudTask::first ();
288252 $ this ->assertSame (0 , $ tasksBefore );
289253 $ this ->assertSame (1 , $ tasksAfter );
290- $ this ->assertDatabaseHas (StackkitCloudTask::class , [
254+ $ this ->assertDatabaseHas (( new StackkitCloudTask ())-> getTable () , [
291255 'queue ' => 'barbequeue ' ,
292256 'status ' => 'queued ' ,
293257 'name ' => SimpleJob::class,
0 commit comments