@@ -206,19 +206,21 @@ public function test_update_env_file(): void
206206 SSH ::assertExecutedContains ('APP_ENV="production" ' );
207207 }
208208
209- public function test_git_hook_deployment (): void
209+ /**
210+ * @dataProvider hookData
211+ */
212+ public function test_git_hook_deployment (string $ provider , array $ webhook , string $ url , array $ payload , bool $ skip ): void
210213 {
211214 SSH ::fake ();
212215 Http::fake ([
213- 'github.com/* ' => Http::response ([
214- 'sha ' => '123 ' ,
215- 'commit ' => [
216- 'message ' => 'test commit message ' ,
217- 'name ' => 'test commit name ' ,
218- 'email ' => 'user@example.com ' ,
219- 'url ' => 'https://github.com ' ,
220- ],
221- ], 200 ),
216+ $ url => Http::response ($ payload ),
217+ ]);
218+
219+ $ this ->site ->update ([
220+ 'branch ' => 'main ' ,
221+ ]);
222+ $ this ->site ->sourceControl ->update ([
223+ 'provider ' => $ provider ,
222224 ]);
223225
224226 GitHook::factory ()->create ([
@@ -233,15 +235,29 @@ public function test_git_hook_deployment(): void
233235 'content ' => 'git pull ' ,
234236 ]);
235237
236- $ this ->post (route ('api.git-hooks ' ) , [
238+ $ this ->post (route ('api.git-hooks ' , [
237239 'secret ' => 'secret ' ,
238- ])->assertSessionDoesntHaveErrors ();
240+ ]), $ webhook )->assertSessionDoesntHaveErrors ();
241+
242+ if ($ skip ) {
243+ $ this ->assertDatabaseMissing ('deployments ' , [
244+ 'site_id ' => $ this ->site ->id ,
245+ 'deployment_script_id ' => $ this ->site ->deploymentScript ->id ,
246+ 'status ' => DeploymentStatus::FINISHED ,
247+ ]);
248+
249+ return ;
250+ }
239251
240252 $ this ->assertDatabaseHas ('deployments ' , [
241253 'site_id ' => $ this ->site ->id ,
242254 'deployment_script_id ' => $ this ->site ->deploymentScript ->id ,
243255 'status ' => DeploymentStatus::FINISHED ,
244256 ]);
257+
258+ $ deployment = $ this ->site ->deployments ()->first ();
259+ $ this ->assertEquals ('saeed ' , $ deployment ->commit_data ['name ' ]);
260+ $ this ->assertEquals ('saeed@vitodeploy.com ' , $ deployment ->commit_data ['email ' ]);
245261 }
246262
247263 public function test_git_hook_deployment_invalid_secret (): void
@@ -271,4 +287,146 @@ public function test_git_hook_deployment_invalid_secret(): void
271287 'status ' => DeploymentStatus::FINISHED ,
272288 ]);
273289 }
290+
291+ public static function hookData (): array
292+ {
293+ return [
294+ [
295+ 'github ' ,
296+ [
297+ 'ref ' => 'refs/heads/main ' ,
298+ ],
299+ 'github.com/* ' ,
300+ [
301+ 'sha ' => '123 ' ,
302+ 'commit ' => [
303+ 'committer ' => [
304+ 'name ' => 'saeed ' ,
305+ 'email ' => 'saeed@vitodeploy.com ' ,
306+ ],
307+ 'message ' => 'test commit message ' ,
308+ 'url ' => 'https://github.com ' ,
309+ ],
310+ ],
311+ false ,
312+ ],
313+ [
314+ 'github ' ,
315+ [
316+ 'ref ' => 'refs/heads/other-branch ' ,
317+ ],
318+ 'github.com/* ' ,
319+ [
320+ 'sha ' => '123 ' ,
321+ 'commit ' => [
322+ 'committer ' => [
323+ 'name ' => 'saeed ' ,
324+ 'email ' => 'saeed@vitodeploy.com ' ,
325+ ],
326+ 'message ' => 'test commit message ' ,
327+ 'url ' => 'https://github.com ' ,
328+ ],
329+ ],
330+ true ,
331+ ],
332+ [
333+ 'gitlab ' ,
334+ [
335+ 'ref ' => 'main ' ,
336+ ],
337+ 'gitlab.com/* ' ,
338+ [
339+ [
340+ 'id ' => '123 ' ,
341+ 'committer_name ' => 'saeed ' ,
342+ 'committer_email ' => 'saeed@vitodeploy.com ' ,
343+ 'title ' => 'test ' ,
344+ 'web_url ' => 'https://gitlab.com ' ,
345+ ],
346+ ],
347+ false ,
348+ ],
349+ [
350+ 'gitlab ' ,
351+ [
352+ 'ref ' => 'other-branch ' ,
353+ ],
354+ 'gitlab.com/* ' ,
355+ [
356+ [
357+ 'id ' => '123 ' ,
358+ 'committer_name ' => 'saeed ' ,
359+ 'committer_email ' => 'saeed@vitodeploy.com ' ,
360+ 'title ' => 'test ' ,
361+ 'web_url ' => 'https://gitlab.com ' ,
362+ ],
363+ ],
364+ true ,
365+ ],
366+ [
367+ 'bitbucket ' ,
368+ [
369+ 'push ' => [
370+ 'changes ' => [
371+ [
372+ 'new ' => [
373+ 'name ' => 'main ' ,
374+ ],
375+ ],
376+ ],
377+ ],
378+ ],
379+ 'bitbucket.org/* ' ,
380+ [
381+ 'values ' => [
382+ [
383+ 'hash ' => '123 ' ,
384+ 'author ' => [
385+ 'raw ' => 'saeed <saeed@vitodeploy.com> ' ,
386+ ],
387+ 'message ' => 'test ' ,
388+ 'links ' => [
389+ 'html ' => [
390+ 'href ' => 'https://bitbucket.org ' ,
391+ ],
392+ ],
393+ ],
394+ ],
395+ ],
396+ false ,
397+ ],
398+ [
399+ 'bitbucket ' ,
400+ [
401+ 'push ' => [
402+ 'changes ' => [
403+ [
404+ 'new ' => [
405+ 'name ' => 'other-branch ' ,
406+ ],
407+ ],
408+ ],
409+ ],
410+ ],
411+ 'bitbucket.org/* ' ,
412+ [
413+ 'values ' => [
414+ [
415+ 'hash ' => '123 ' ,
416+ 'author ' => [
417+ 'raw ' => 'saeed <saeed@vitodeploy.com> ' ,
418+ ],
419+ 'message ' => 'test ' ,
420+ 'links ' => [
421+ 'html ' => [
422+ 'href ' => 'https://bitbucket.org ' ,
423+ ],
424+ ],
425+ ],
426+ ],
427+ ],
428+ true ,
429+ ],
430+ ];
431+ }
274432}
0 commit comments