diff --git a/app/Jobs/SendDeploymentNotificationJob.php b/app/Jobs/SendDeploymentNotificationJob.php index 80d5fb4..29c11d2 100644 --- a/app/Jobs/SendDeploymentNotificationJob.php +++ b/app/Jobs/SendDeploymentNotificationJob.php @@ -19,12 +19,12 @@ class SendDeploymentNotificationJob implements ShouldQueue /** * @var User */ - private User $user; + public User $user; /** * @var array */ - private array $deploymentInfo; + public array $deploymentInfo; /** * Create a new job instance. diff --git a/tests/Feature/SendDeploymentNotificationTest.php b/tests/Feature/SendDeploymentNotificationTest.php index 1c5d7eb..ea85bba 100644 --- a/tests/Feature/SendDeploymentNotificationTest.php +++ b/tests/Feature/SendDeploymentNotificationTest.php @@ -2,6 +2,9 @@ namespace Tests\Feature; +use App\Facades\Hashids; +use App\Jobs\SendDeploymentNotificationJob; +use App\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Queue; use Tests\TestCase; @@ -13,10 +16,37 @@ class SendDeploymentNotificationTest extends TestCase /** @test */ public function dispatch_job_when_hash_is_valid() { - Queue::partialMock(); + Queue::fake(); + $user = factory(User::class)->create([ + 'telegram_chat_id' => '12345', + ]); + $hash = Hashids::encode($user->id); + $requestParams = [ + 'test_param_A' => 'Value_A', + 'test_param_B' => 'Value_B', + ]; - $response = $this->post(route('integrations.forge.webhook', ['hash' => '111'])); + $response = $this->post(route('integrations.forge.webhook', ['hash' => $hash]), $requestParams); + + $response->assertStatus(200); + Queue::assertPushed(SendDeploymentNotificationJob::class, function ($job) use ($user, $requestParams) { + $this->assertEquals($requestParams, $job->deploymentInfo); + + return $job->user->id === $user->id; + }); + } + + /** @test */ + public function job_didnot_dispatch_when_hash_was_invalid() + { + Queue::fake(); + factory(User::class)->create([ + 'telegram_chat_id' => '12345', + ]); + + $response = $this->post(route('integrations.forge.webhook', ['hash' => 'invalid-hash'])); $response->assertStatus(404); + Queue::assertNothingPushed(); } }