tests
This commit is contained in:
parent
0c8389fa29
commit
259ebe827c
8 changed files with 174 additions and 12 deletions
|
@ -4,10 +4,12 @@
|
|||
use App\Models\Collective;
|
||||
use function Pest\Faker\faker;
|
||||
|
||||
uses()->group('joined', 'admin');
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = Collective::first();
|
||||
$this->request = [
|
||||
'categories' => [rand(1,57), rand(1,57), rand(1,57)],
|
||||
'categories' => [rand(1, 57), rand(1, 57), rand(1, 57)],
|
||||
'url' => faker()->url,
|
||||
'subject' => faker()->word,
|
||||
'approved' => faker()->boolean,
|
||||
|
@ -16,11 +18,13 @@
|
|||
|
||||
it('gets joined create', function () {
|
||||
$response = $this->actingAs($this->user)->get('fanatic/joined/create');
|
||||
|
||||
$response->assertViewIs('admin.joined.create');
|
||||
});
|
||||
|
||||
it('does not show create to guests', function () {
|
||||
$response = $this->get('/fanatic/joined/create');
|
||||
|
||||
$response->assertRedirect('/fanatic/login');
|
||||
});
|
||||
|
||||
|
@ -38,7 +42,7 @@
|
|||
});
|
||||
|
||||
it('fails incorrect category format', function () {
|
||||
$this->request['categories'] = rand(1,57);
|
||||
$this->request['categories'] = rand(1, 57);
|
||||
$response = $this->actingAs($this->user)->post('/fanatic/joined', $this->request);
|
||||
|
||||
$response->assertInvalid();
|
||||
|
|
14
tests/Feature/Joined/DestroyTest.php
Normal file
14
tests/Feature/Joined/DestroyTest.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Joined;
|
||||
|
||||
uses()->group('joined', 'admin');
|
||||
|
||||
it('destroys item in database', function () {
|
||||
$joined = Joined::factory()->create();
|
||||
$id = $joined->id;
|
||||
$this->assertDatabaseHas('joined', ['id' => $id]);
|
||||
|
||||
$joined->remove();
|
||||
$this->assertDatabaseMissing('joined', ['id' => $id]);
|
||||
});
|
123
tests/Feature/Joined/EditTest.php
Normal file
123
tests/Feature/Joined/EditTest.php
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Collective;
|
||||
use App\Models\Joined;
|
||||
use function Pest\Faker\faker;
|
||||
|
||||
uses()->group('joined', 'admin');
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = Collective::first();
|
||||
$this->joined = (Joined::inRandomOrder()->limit(1)->get())->first();
|
||||
$this->request = [
|
||||
'categories' => [rand(1, 57), rand(1, 57), rand(1, 57)],
|
||||
'url' => faker()->url,
|
||||
'subject' => faker()->word,
|
||||
'approved' => faker()->boolean,
|
||||
];
|
||||
$this->url = "/fanatic/joined/{$this->joined->id}";
|
||||
});
|
||||
|
||||
it('has edit page', function () {
|
||||
$response = $this->actingAs($this->user)->get("{$this->url}/edit");
|
||||
|
||||
$response->assertViewIs('admin.joined.edit');
|
||||
});
|
||||
|
||||
it('hides edit page from guests', function () {
|
||||
$response = $this->get("{$this->url}/edit");
|
||||
|
||||
$response->assertRedirect('/fanatic/login');
|
||||
});
|
||||
|
||||
it('validates correct edit form', function () {
|
||||
$response = $this->actingAs($this->user)->patch($this->url, $this->request);
|
||||
|
||||
$response->assertValid();
|
||||
});
|
||||
|
||||
it('fails missing categories array', function () {
|
||||
unset($this->request['categories']);
|
||||
$response = $this->actingAs($this->user)->patch($this->url, $this->request);
|
||||
|
||||
$response->assertInvalid();
|
||||
});
|
||||
|
||||
it('fails non-array categories', function () {
|
||||
$this->request['categories'] = 4;
|
||||
$response = $this->actingAs($this->user)->patch($this->url, $this->request);
|
||||
|
||||
$response->assertInvalid();
|
||||
});
|
||||
|
||||
it('fails empty categories array', function () {
|
||||
$this->request['categories'] = [];
|
||||
$response = $this->actingAs($this->user)->patch($this->url, $this->request);
|
||||
|
||||
$response->assertInvalid();
|
||||
});
|
||||
|
||||
it('fails non-numeric categories item', function () {
|
||||
$this->request['categories'][] = 'a';
|
||||
$response = $this->actingAs($this->user)->patch($this->url, $this->request);
|
||||
|
||||
$response->assertInvalid();
|
||||
});
|
||||
|
||||
it('fails non-existant categories', function () {
|
||||
$invalidCat = (Category::all()->count()) + 10;
|
||||
$this->request['categories'][] = $invalidCat;
|
||||
$response = $this->actingAs($this->user)->patch($this->url, $this->request);
|
||||
|
||||
$response->assertInvalid();
|
||||
});
|
||||
|
||||
it('fails empty url', function () {
|
||||
unset($this->request['url']);
|
||||
$response = $this->actingAs($this->user)->patch($this->url, $this->request);
|
||||
|
||||
$response->assertInvalid();
|
||||
});
|
||||
|
||||
it('fails non-url url', function () {
|
||||
$this->request['url'] = 'this is not a url';
|
||||
$response = $this->actingAs($this->user)->patch($this->url, $this->request);
|
||||
|
||||
$response->assertInvalid();
|
||||
});
|
||||
|
||||
it('fails empty subject', function () {
|
||||
unset($this->request['subject']);
|
||||
$response = $this->actingAs($this->user)->patch($this->url, $this->request);
|
||||
|
||||
$response->assertInvalid();
|
||||
});
|
||||
|
||||
it('fails non-string subject', function () {
|
||||
$this->request['subject'] = 30582;
|
||||
$response = $this->actingAs($this->user)->patch($this->url, $this->request);
|
||||
|
||||
$response->assertInvalid();
|
||||
});
|
||||
|
||||
it('allows null approved', function () {
|
||||
unset($this->request['approved']);
|
||||
$response = $this->actingAs($this->user)->patch($this->url, $this->request);
|
||||
|
||||
$response->assertValid();
|
||||
});
|
||||
|
||||
it('fails non-bool approved', function () {
|
||||
$this->request['approved'] = 'this is not a truthy response';
|
||||
$response = $this->actingAs($this->user)->patch($this->url, $this->request);
|
||||
|
||||
$response->assertInvalid();
|
||||
});
|
||||
|
||||
it('updates item in database', function () {
|
||||
$joined = Joined::factory()->create();
|
||||
$joined->patch($this->request);
|
||||
|
||||
$this->assertEquals($joined->subject, $this->request['subject']);
|
||||
});
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
use App\Models\Collective;
|
||||
|
||||
uses()->group('joined', 'admin');
|
||||
|
||||
it('gets joined index', function () {
|
||||
$response = $this->actingAs(Collective::first())->get('/fanatic/joined');
|
||||
$response->assertViewIs('admin.joined.index');
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
|
||||
test('example', function () {
|
||||
$response = $this->get('/');
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
7
tests/Feature/Owned/CreateTest.php
Normal file
7
tests/Feature/Owned/CreateTest.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
it('has owned/create page', function () {
|
||||
$response = $this->get('/owned/create');
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
17
tests/Feature/Owned/IndexTest.php
Normal file
17
tests/Feature/Owned/IndexTest.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Collective;
|
||||
|
||||
uses()->group('owned', 'admin');
|
||||
|
||||
it('has index page', function () {
|
||||
$response = $this->actingAs(Collective::first())->get('/fanatic/owned');
|
||||
|
||||
$response->assertViewIs('admin.owned.index');
|
||||
});
|
||||
|
||||
it('hides index from guests', function () {
|
||||
$response = $this->get('/fanatic/owned');
|
||||
|
||||
$response->assertRedirect('/fanatic/login');
|
||||
});
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
use App\Models\Collective;
|
||||
|
||||
uses()->group('sessions', 'admin');
|
||||
|
||||
test('dashboard hidden for guests', function () {
|
||||
$response = $this->get('/fanatic');
|
||||
$response->assertRedirect('/fanatic/login');
|
||||
|
|
Loading…
Reference in a new issue