This commit is contained in:
Marley Rae 2022-04-27 18:41:16 -07:00
parent 0c8389fa29
commit 259ebe827c
8 changed files with 174 additions and 12 deletions

View file

@ -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();
@ -99,4 +103,4 @@
$response = $this->actingAs($this->user)->post('/fanatic/joined', $this->request);
$response->assertInvalid();
});
});

View 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]);
});

View 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']);
});

View file

@ -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');
@ -10,4 +12,4 @@
it('does not show index to guests', function () {
$response = $this->get('/fanatic/joined');
$response->assertRedirect('/fanatic/login');
});
});

View file

@ -1,7 +0,0 @@
<?php
test('example', function () {
$response = $this->get('/');
$response->assertStatus(200);
});

View file

@ -0,0 +1,7 @@
<?php
it('has owned/create page', function () {
$response = $this->get('/owned/create');
$response->assertStatus(200);
});

View 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');
});

View file

@ -2,13 +2,15 @@
use App\Models\Collective;
uses()->group('sessions', 'admin');
test('dashboard hidden for guests', function () {
$response = $this->get('/fanatic');
$response->assertRedirect('/fanatic/login');
});
test('logs in', function () {
$user = Collective::first();
$user = Collective::first();
$response = $this->actingAs($user)->get('/fanatic');
$response->assertViewIs('admin.dashboard');
});