add test
This commit is contained in:
75
tests/Feature/Setting/WebhookTest.php
Normal file
75
tests/Feature/Setting/WebhookTest.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Setting;
|
||||
|
||||
use App\CheckinWebhook;
|
||||
use App\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class WebhookTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->seed();
|
||||
}
|
||||
|
||||
public function testStoreWebhooks()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->followingRedirects()
|
||||
->post('/setting/webhooks', ['name' => 'example']);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertViewIs('setting.webhooks');
|
||||
$this->assertDatabaseHas('checkin_webhooks', ['user_id' => $user->id, 'name' => 'example']);
|
||||
}
|
||||
|
||||
public function testStoreWebhooksHas9Hooks()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$webhooks = factory(CheckinWebhook::class, CheckinWebhook::PER_USER_LIMIT - 1)->create(['user_id' => $user->id]);
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->followingRedirects()
|
||||
->post('/setting/webhooks', ['name' => 'example9']);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertViewIs('setting.webhooks');
|
||||
$this->assertDatabaseHas('checkin_webhooks', ['user_id' => $user->id, 'name' => 'example9']);
|
||||
}
|
||||
|
||||
public function testStoreWebhooksHas10Hooks()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$webhooks = factory(CheckinWebhook::class, CheckinWebhook::PER_USER_LIMIT)->create(['user_id' => $user->id]);
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->followingRedirects()
|
||||
->post('/setting/webhooks', ['name' => 'example10']);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertViewIs('setting.webhooks');
|
||||
$this->assertDatabaseMissing('checkin_webhooks', ['user_id' => $user->id, 'name' => 'example10']);
|
||||
}
|
||||
|
||||
public function testDestroyWebhooks()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$webhook = factory(CheckinWebhook::class)->create(['user_id' => $user->id]);
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->followingRedirects()
|
||||
->delete('/setting/webhooks/' . $webhook->id);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertViewIs('setting.webhooks')
|
||||
->assertSee('削除しました');
|
||||
$this->assertTrue($webhook->refresh()->trashed());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user