diff --git a/tests/Feature/Joined/CreateTest.php b/tests/Feature/Joined/CreateTest.php index d459d0c..744dba7 100644 --- a/tests/Feature/Joined/CreateTest.php +++ b/tests/Feature/Joined/CreateTest.php @@ -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(); -}); \ No newline at end of file +}); diff --git a/tests/Feature/Joined/DestroyTest.php b/tests/Feature/Joined/DestroyTest.php new file mode 100644 index 0000000..7064e97 --- /dev/null +++ b/tests/Feature/Joined/DestroyTest.php @@ -0,0 +1,14 @@ +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]); +}); diff --git a/tests/Feature/Joined/EditTest.php b/tests/Feature/Joined/EditTest.php new file mode 100644 index 0000000..c5b248f --- /dev/null +++ b/tests/Feature/Joined/EditTest.php @@ -0,0 +1,123 @@ +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']); +}); diff --git a/tests/Feature/Joined/IndexTest.php b/tests/Feature/Joined/IndexTest.php index 767f681..d61707a 100644 --- a/tests/Feature/Joined/IndexTest.php +++ b/tests/Feature/Joined/IndexTest.php @@ -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'); -}); \ No newline at end of file +}); diff --git a/tests/Feature/Models/OwnedTest.php b/tests/Feature/Models/OwnedTest.php deleted file mode 100644 index b46239f..0000000 --- a/tests/Feature/Models/OwnedTest.php +++ /dev/null @@ -1,7 +0,0 @@ -get('/'); - - $response->assertStatus(200); -}); diff --git a/tests/Feature/Owned/CreateTest.php b/tests/Feature/Owned/CreateTest.php new file mode 100644 index 0000000..d9e97ed --- /dev/null +++ b/tests/Feature/Owned/CreateTest.php @@ -0,0 +1,7 @@ +get('/owned/create'); + + $response->assertStatus(200); +}); diff --git a/tests/Feature/Owned/IndexTest.php b/tests/Feature/Owned/IndexTest.php new file mode 100644 index 0000000..ee16ba7 --- /dev/null +++ b/tests/Feature/Owned/IndexTest.php @@ -0,0 +1,17 @@ +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'); +}); diff --git a/tests/Feature/SessionsTest.php b/tests/Feature/SessionsTest.php index 88a410e..7dd461a 100644 --- a/tests/Feature/SessionsTest.php +++ b/tests/Feature/SessionsTest.php @@ -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'); });