fanatic/tests/Feature/Joined/CreateTest.php

107 lines
3 KiB
PHP
Raw Permalink Normal View History

2022-04-25 19:50:01 -07:00
<?php
use App\Models\Category;
use App\Models\Collective;
use function Pest\Faker\faker;
2022-04-27 18:41:16 -07:00
uses()->group('joined', 'admin');
2022-04-25 19:50:01 -07:00
beforeEach(function () {
$this->user = Collective::first();
$this->request = [
2022-04-27 18:41:16 -07:00
'categories' => [rand(1, 57), rand(1, 57), rand(1, 57)],
2022-04-25 19:50:01 -07:00
'url' => faker()->url,
'subject' => faker()->word,
'approved' => faker()->boolean,
];
});
it('gets joined create', function () {
$response = $this->actingAs($this->user)->get('fanatic/joined/create');
2022-04-27 18:41:16 -07:00
2022-04-25 19:50:01 -07:00
$response->assertViewIs('admin.joined.create');
});
it('does not show create to guests', function () {
$response = $this->get('/fanatic/joined/create');
2022-04-27 18:41:16 -07:00
2022-04-25 19:50:01 -07:00
$response->assertRedirect('/fanatic/login');
});
it('validates correct joined create form', function () {
$response = $this->actingAs($this->user)->post('/fanatic/joined', $this->request);
$response->assertValid();
});
it('fails missing categories', function () {
unset($this->request['categories']);
$response = $this->actingAs($this->user)->post('/fanatic/joined', $this->request);
$response->assertInvalid();
});
it('fails incorrect category format', function () {
2022-04-27 18:41:16 -07:00
$this->request['categories'] = rand(1, 57);
2022-04-25 19:50:01 -07:00
$response = $this->actingAs($this->user)->post('/fanatic/joined', $this->request);
$response->assertInvalid();
});
it('fails incorrect category item format', function () {
$this->request['categories'][] = 'a';
$response = $this->actingAs($this->user)->post('/fanatic/joined', $this->request);
$response->assertInvalid();
});
it('fails non-existant category', function () {
$invalidCat = (Category::all()->count()) + 10;
$this->request['categories'][] = $invalidCat;
$response = $this->actingAs($this->user)->post('/fanatic/joined', $this->request);
$response->assertInvalid();
});
it('fails missing url', function () {
unset($this->request['url']);
$response = $this->actingAs($this->user)->post('/fanatic/joined', $this->request);
$response->assertInvalid();
});
it('fails incorrect url format', function () {
$this->request['url'] = faker()->word;
$response = $this->actingAs($this->user)->post('/fanatic/joined', $this->request);
$response->assertInvalid();
});
it('fails missing subject', function () {
unset($this->request['subject']);
$response = $this->actingAs($this->user)->post('/fanatic/joined', $this->request);
$response->assertInvalid();
});
it('fails non-string subject', function () {
$this->request['subject'] = 34950;
$response = $this->actingAs($this->user)->post('/fanatic/joined', $this->request);
$response->assertInvalid();
});
it('validates empty approved', function () {
unset($this->request['approved']);
$response = $this->actingAs($this->user)->post('/fanatic/joined', $this->request);
$response->assertValid();
});
it('fails non-bool approved', function () {
$this->request['approved'] = 'text';
$response = $this->actingAs($this->user)->post('/fanatic/joined', $this->request);
$response->assertInvalid();
2022-04-27 18:41:16 -07:00
});