Skip to content

Commit

Permalink
Fixed test.
Browse files Browse the repository at this point in the history
  • Loading branch information
itorgov committed Mar 28, 2020
1 parent f664c17 commit 5042457
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/Jobs/SendDeploymentNotificationJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 32 additions & 2 deletions tests/Feature/SendDeploymentNotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}

0 comments on commit 5042457

Please sign in to comment.