diff --git a/tests/Feature/AuthenticationTest.php b/tests/Feature/AuthenticationTest.php deleted file mode 100644 index 68559726..00000000 --- a/tests/Feature/AuthenticationTest.php +++ /dev/null @@ -1,71 +0,0 @@ -get("/auth/register") - ->assertOk(); - - $this->post("/auth/register", [ - "name" => "User", - "email" => "user@example.com", - "password" => "password", - "password_confirmation" => "password", - ]) - ->assertSessionHasNoErrors(); - - $this->assertDatabaseHas("users", [ - "name" => "User", - "email" => "user@example.com", - ]); - } - - public function testRegisterDataIsRequired(): void - { - $this->post("/auth/register") - ->assertInvalid([ - "name", - "email", - "password", - "password_confirmation", - ]); - } - - public function testUserCanLogIn(): void - { - User::factory()->create([ - "email" => "user@example.com", - "password" => "password", - ]); - - $this->post("/auth/login", [ - "email" => "user@example.com", - "password" => "password", - ]) - ->assertSessionHasNoErrors(); - - $this->assertAuthenticated(); - } - - public function testUserCanLogOut(): void - { - $user = User::factory()->create(); - - $this->actingAs($user) - ->get("/auth/logout") - ->assertRedirect("/"); - - $this->assertGuest(); - } -} diff --git a/tests/Feature/ContactTest.php b/tests/Feature/ContactTest.php index 989ca696..d24e5e3f 100644 --- a/tests/Feature/ContactTest.php +++ b/tests/Feature/ContactTest.php @@ -6,13 +6,13 @@ use Blumilk\Meetup\Core\Models\Contact; use Blumilk\Meetup\Core\Notifications\ContactEmailNotification; -use Illuminate\Foundation\Testing\DatabaseMigrations; +use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Notification; use Tests\TestCase; class ContactTest extends TestCase { - use DatabaseMigrations; + use RefreshDatabase; public function testUserCanSeeContactPage(): void { diff --git a/tests/Feature/InviteAdminTest.php b/tests/Feature/InviteAdminTest.php index 90f4c5e1..0b7e3d77 100644 --- a/tests/Feature/InviteAdminTest.php +++ b/tests/Feature/InviteAdminTest.php @@ -6,19 +6,28 @@ use Blumilk\Meetup\Core\Models\User; use Blumilk\Meetup\Core\Notifications\InvitationEmailNotification; -use Illuminate\Foundation\Testing\DatabaseMigrations; +use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Notification; +use Spatie\Permission\Models\Role; use Tests\TestCase; class InviteAdminTest extends TestCase { - use DatabaseMigrations; + use RefreshDatabase; - public function testAdminCanSeeSendInvitationPage(): void + public User $admin; + + protected function setUp(): void { - $admin = User::factory()->admin()->create(); + parent::setUp(); + + Role::create(["name" => "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } - $this->actingAs($admin) + public function testAdminCanSeeSendInvitationPage(): void + { + $this->actingAs($this->admin) ->get("/invitation") ->assertOk(); } @@ -27,13 +36,11 @@ public function testAdminCanSendInvitation(): void { Notification::fake(); - $admin = User::factory()->admin()->create(); - $invitedUser = User::factory([ "email" => "invited@example.com", ])->make(); - $this->actingAs($admin) + $this->actingAs($this->admin) ->post("/invitation", [ "email" => $invitedUser->email, ]) @@ -48,6 +55,6 @@ public function testUserCannotSendInvitation(): void $this->actingAs($user) ->get("/invitation") - ->assertForbidden(); + ->assertLocation("/"); } } diff --git a/tests/Feature/MeetupTest.php b/tests/Feature/MeetupTest.php deleted file mode 100644 index 8ef44f49..00000000 --- a/tests/Feature/MeetupTest.php +++ /dev/null @@ -1,190 +0,0 @@ -admin()->create(); - $meetups = Meetup::factory() - ->count(15) - ->for($admin) - ->create(); - - $this->assertDatabaseCount("meetups", 15); - - $response = $this->get(route("meetups")) - ->assertOk(); - - foreach ($meetups as $meetup) { - $response->assertSee($meetup->logo_path) - ->assertSee($meetup->title) - ->assertSee($meetup->date->format("Y-m-d h:i")) - ->assertSee($meetup->place); - } - } - - public function testMeetupsListIsPaginated(): void - { - $admin = User::factory()->admin()->create(); - Meetup::factory() - ->count(30) - ->for($admin) - ->create(); - - $meetups = Meetup::query() - ->latest() - ->skip(20) - ->take(10); - - $this->assertDatabaseCount("meetups", 30); - - $response = $this->get(route("meetups") . "?page=2") - ->assertOk(); - - foreach ($meetups as $meetup) { - $response->assertSee($meetup->logo_path) - ->assertSee($meetup->title) - ->assertSee($meetup->date->format("Y-m-d h:i")) - ->assertSee($meetup->place); - } - } - - public function testUserCanSeeMeetup(): void - { - $admin = User::factory()->admin()->create(); - $meetup = Meetup::factory()->for($admin)->create(); - - $this->get(route("meetups.show", $meetup)) - ->assertOk() - ->assertSee($meetup->logo_path) - ->assertSee($meetup->title) - ->assertSee($meetup->date->format("Y-m-d h:i")) - ->assertSee($meetup->place) - ->assertSee($meetup->language); - } - - public function testAdminCanCreateMeetup(): void - { - $admin = User::factory()->admin()->create(); - - $this->actingAs($admin) - ->get(route("meetups.create")) - ->assertOk(); - - $this->actingAs($admin) - ->post(route("meetups.store"), [ - "title" => "Test Meetup", - "description" => "Description", - "date" => Carbon::parse("2022-12-12 12:00:00"), - "place" => "Place", - "language" => "en", - ]) - ->assertSessionHasNoErrors() - ->assertRedirect(route("meetups.create")); - - $this->assertDatabaseHas("meetups", [ - "user_id" => $admin->id, - "title" => "Test Meetup", - "description" => "Description", - "date" => Carbon::parse("2022-12-12 12:00:00"), - "place" => "Place", - "language" => "en", - ]); - } - - public function testUserCannotCreateMeetup(): void - { - $user = User::factory()->create(); - - $this->actingAs($user) - ->get(route("meetups.create")) - ->assertForbidden(); - - $this->actingAs($user) - ->post(route("meetups.store")) - ->assertForbidden(); - } - - public function testAdminCanEditMeetup(): void - { - $admin = User::factory()->admin()->create(); - $meetup = Meetup::factory()->for($admin)->create(); - - $this->actingAs($admin) - ->get(route("meetups.edit", $meetup)) - ->assertOk(); - - $this->actingAs($admin) - ->put(route("meetups.update", $meetup), [ - "title" => "Test Meetup", - "description" => "Description", - "date" => Carbon::parse("2022-12-12 12:00:00"), - "place" => "Place", - "language" => "en", - ]) - ->assertSessionHasNoErrors() - ->assertRedirect(route("meetups.edit")); - - $this->assertDatabaseHas("meetups", [ - "user_id" => $admin->id, - "title" => "Test Meetup", - "description" => "Description", - "date" => Carbon::parse("2022-12-12 12:00:00"), - "place" => "Place", - "language" => "en", - ]); - } - - public function testUserCannotEditMeetup(): void - { - $admin = User::factory()->create(); - $meetup = Meetup::factory()->for($admin)->create(); - - $user = User::factory()->create(); - - $this->actingAs($user) - ->get(route("meetups.edit", $meetup)) - ->assertForbidden(); - - $this->actingAs($admin) - ->put(route("meetups.update", $meetup)) - ->assertForbidden(); - } - - public function testAdminCanDeleteMeetup(): void - { - $admin = User::factory()->admin()->create(); - - $meetup = Meetup::factory()->for($admin)->create(); - - $this->actingAs($admin) - ->delete(route("meetups.destroy", $meetup)) - ->assertRedirect(); - - $this->assertModelMissing($meetup); - } - - public function testUserCannotDeleteMeetup(): void - { - $admin = User::factory()->admin()->create(); - $meetup = Meetup::factory()->for($admin)->create(); - - $user = User::factory()->create(); - - $this->actingAs($user) - ->delete(route("meetups.destroy", $meetup)) - ->assertForbidden(); - } -} diff --git a/tests/Feature/Meetups/BrowseMeetupsTest.php b/tests/Feature/Meetups/BrowseMeetupsTest.php new file mode 100644 index 00000000..7e355061 --- /dev/null +++ b/tests/Feature/Meetups/BrowseMeetupsTest.php @@ -0,0 +1,71 @@ + "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } + + public function testUserCanSeeMeetupsList(): void + { + $meetups = Meetup::factory() + ->count(15) + ->for($this->admin) + ->create(); + + $this->assertDatabaseCount("meetups", 15); + + $response = $this->get(route("meetups")) + ->assertOk(); + + foreach ($meetups as $meetup) { + $response->assertSee($meetup->logo_path) + ->assertSee($meetup->title) + ->assertSee($meetup->date->toDateString()) + ->assertSee($meetup->place); + } + } + + public function testMeetupsListIsPaginated(): void + { + Meetup::factory() + ->count(30) + ->for($this->admin) + ->create(); + + $meetups = Meetup::query() + ->latest() + ->skip(20) + ->take(10); + + $this->assertDatabaseCount("meetups", 30); + + $response = $this->get(route("meetups") . "?page=2") + ->assertOk(); + + foreach ($meetups as $meetup) { + $response->assertSee($meetup->logo_path) + ->assertSee($meetup->title) + ->assertSee($meetup->date->format("Y-m-d h:i")) + ->assertSee($meetup->place); + } + } +} diff --git a/tests/Feature/Meetups/CreateMeetupsTest.php b/tests/Feature/Meetups/CreateMeetupsTest.php new file mode 100644 index 00000000..73d55ef7 --- /dev/null +++ b/tests/Feature/Meetups/CreateMeetupsTest.php @@ -0,0 +1,68 @@ + "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } + + public function testAdminCanCreateMeetup(): void + { + $this->actingAs($this->admin) + ->get(route("meetups.create")) + ->assertOk(); + + $this->actingAs($this->admin) + ->post(route("meetups.store"), [ + "title" => "Test Meetup", + "description" => "Description", + "date" => Carbon::parse("2022-12-12 12:00:00"), + "place" => "Place", + "language" => "en", + "organizations" => "", + "speakers" => "", + ]) + ->assertSessionHasNoErrors() + ->assertRedirect(); + + $this->assertDatabaseHas("meetups", [ + "user_id" => $this->admin->id, + "title" => "Test Meetup", + "description" => "Description", + "date" => Carbon::parse("2022-12-12 12:00:00"), + "place" => "Place", + "language" => "en", + ]); + } + + public function testUserCannotCreateMeetup(): void + { + $user = User::factory()->create(); + + $this->actingAs($user) + ->get(route("meetups.create")) + ->assertForbidden(); + + $this->actingAs($user) + ->post(route("meetups.store")) + ->assertForbidden(); + } +} diff --git a/tests/Feature/Meetups/DeleteMeetupsTest.php b/tests/Feature/Meetups/DeleteMeetupsTest.php new file mode 100644 index 00000000..c9ba743f --- /dev/null +++ b/tests/Feature/Meetups/DeleteMeetupsTest.php @@ -0,0 +1,48 @@ + "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } + + public function testAdminCanDeleteMeetup(): void + { + $meetup = Meetup::factory()->for($this->admin)->create(); + + $this->actingAs($this->admin) + ->delete(route("meetups.destroy", $meetup)) + ->assertRedirect(); + + $this->assertModelMissing($meetup); + } + + public function testUserCannotDeleteMeetup(): void + { + $meetup = Meetup::factory()->for($this->admin)->create(); + + $user = User::factory()->create(); + + $this->actingAs($user) + ->delete(route("meetups.destroy", $meetup)) + ->assertForbidden(); + } +} diff --git a/tests/Feature/Meetups/EditMeetupsTest.php b/tests/Feature/Meetups/EditMeetupsTest.php new file mode 100644 index 00000000..ced2032a --- /dev/null +++ b/tests/Feature/Meetups/EditMeetupsTest.php @@ -0,0 +1,74 @@ + "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } + + public function testAdminCanEditMeetup(): void + { + $meetup = Meetup::factory()->for($this->admin)->create(); + + $this->actingAs($this->admin) + ->get(route("meetups.edit", $meetup)) + ->assertOk(); + + $this->actingAs($this->admin) + ->put(route("meetups.update", $meetup), [ + "title" => "Test Meetup", + "description" => "Description", + "date" => Carbon::parse("2022-12-12 12:00:00"), + "place" => "Place", + "language" => "en", + "organizations" => "", + "speakers" => "", + ]) + ->assertSessionHasNoErrors() + ->assertRedirect(); + + $this->assertDatabaseHas("meetups", [ + "user_id" => $this->admin->id, + "title" => "Test Meetup", + "description" => "Description", + "date" => Carbon::parse("2022-12-12 12:00:00"), + "place" => "Place", + "language" => "en", + ]); + } + + public function testUserCannotEditMeetup(): void + { + $user = User::factory()->create(); + $meetup = Meetup::factory()->for($user)->create(); + + $user = User::factory()->create(); + + $this->actingAs($user) + ->get(route("meetups.edit", $meetup)) + ->assertForbidden(); + + $this->actingAs($user) + ->put(route("meetups.update", $meetup)) + ->assertForbidden(); + } +} diff --git a/tests/Feature/NewsTest.php b/tests/Feature/NewsTest.php deleted file mode 100644 index 77516ef3..00000000 --- a/tests/Feature/NewsTest.php +++ /dev/null @@ -1,164 +0,0 @@ -admin()->create(); - - $news = News::factory() - ->count(15) - ->for($admin) - ->create(); - - $this->assertDatabaseCount("news", 15); - - $response = $this->get(route("news")) - ->assertOk(); - - foreach ($news as $singleNews) { - $response->assertSee($singleNews->title); - } - } - - public function testNewsListIsPaginated(): void - { - $admin = User::factory()->admin()->create(); - - News::factory() - ->count(30) - ->for($admin) - ->create(); - - $news = News::query() - ->latest() - ->skip(20) - ->take(10); - - $this->assertDatabaseCount("meetups", 30); - - $response = $this->get(route("news") . "?page=2") - ->assertOk(); - - foreach ($news as $singleNews) { - $response->assertSee($singleNews->title); - } - } - - public function testUserCanSeeNews(): void - { - $admin = User::factory()->admin()->create(); - $news = News::factory()->for($admin)->create(); - - $this->get(route("news.show", $news)) - ->assertOk() - ->assertSee($news->title) - ->assertSee($news->text); - } - - public function testAdminCanCreateNews(): void - { - $admin = User::factory()->admin()->create(); - - $this->actingAs($admin) - ->get(route("news.create")) - ->assertOk(); - - $this->actingAs($admin) - ->post(route("news.store"), [ - "title" => "Test news", - "text" => "Test news content", - ]) - ->assertSessionHasNoErrors() - ->assertRedirect(route("news.create")); - - $this->assertDatabaseHas("news", [ - "user_id" => $admin->id, - "title" => "Test news", - "text" => "Test news content", - ]); - } - - public function testUserCannotCreateNews(): void - { - $user = User::factory()->create(); - - $this->actingAs($user) - ->get(route("news.create")) - ->assertForbidden(); - - $this->actingAs($user) - ->post(route("news.store")) - ->assertForbidden(); - } - - public function testAdminCanEditNews(): void - { - $admin = User::factory()->admin()->create(); - - $news = News::factory()->for($admin)->create(); - - $this->actingAs($admin) - ->get(route("news.edit", $news)) - ->assertOk(); - - $this->actingAs($admin) - ->put(route("news.update", $news), [ - "title" => "Test News", - "text" => "Test News Content", - ]) - ->assertSessionHasNoErrors() - ->assertRedirect(route("news.edit", $news)); - } - - public function testUserCannotEditNews(): void - { - $admin = User::factory()->admin()->create(); - $news = News::factory()->for($admin)->create(); - - $user = User::factory()->create(); - - $this->actingAs($user) - ->get(route("news.edit", $news)) - ->assertForbidden(); - - $this->actingAs($user) - ->put(route("news.update", $news)) - ->assertForbidden(); - } - - public function testAdminCanDeleteNews(): void - { - $admin = User::factory()->admin()->create(); - - $news = News::factory()->for($admin)->create(); - - $this->actingAs($admin) - ->delete(route("news.destroy", $news)) - ->assertRedirect(); - - $this->assertModelMissing($news); - } - - public function testUserCannotDeleteNews(): void - { - $admin = User::factory()->admin()->create(); - $news = News::factory()->for($admin)->create(); - - $user = User::factory()->create(); - - $this->actingAs($user) - ->delete(route("news.destroy", $news)); - } -} diff --git a/tests/Feature/NewsletterTest.php b/tests/Feature/NewsletterTest.php index 6a12cb72..18e16541 100644 --- a/tests/Feature/NewsletterTest.php +++ b/tests/Feature/NewsletterTest.php @@ -6,13 +6,13 @@ use Blumilk\Meetup\Core\Models\NewsletterSubscriber; use Blumilk\Meetup\Core\Notifications\NewsletterNotification; -use Illuminate\Foundation\Testing\DatabaseMigrations; +use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Notification; use Tests\TestCase; class NewsletterTest extends TestCase { - use DatabaseMigrations; + use RefreshDatabase; public function testGuestCanSeeNewsletterPage(): void { diff --git a/tests/Feature/OrganizationProfileTest.php b/tests/Feature/OrganizationProfileTest.php deleted file mode 100644 index d3eb6c84..00000000 --- a/tests/Feature/OrganizationProfileTest.php +++ /dev/null @@ -1,162 +0,0 @@ -admin()->create(); - - $organization = Organization::factory()->create(); - - $this->actingAs($admin) - ->get(route("organizations.profiles.create", $organization)) - ->assertOk(); - - $this->actingAs($admin) - ->post(route("organizations.profiles.store", $organization), [ - "label" => "Facebook", - "link" => "https://facebook.com", - ]) - ->assertSessionHasNoErrors() - ->assertRedirect(); - - $this->assertDatabaseHas("organization_profiles", [ - "organization_id" => $organization->id, - "label" => "Facebook", - "link" => "https://facebook.com", - ]); - } - - public function testUserCannotCreateOrganizationProfile(): void - { - $user = User::factory()->create(); - - $organization = Organization::factory()->create(); - - $this->actingAs($user) - ->get(route("organizations.profiles.create", $organization)) - ->assertForbidden(); - - $this->actingAs($user) - ->post(route("organizations.profiles.store", $organization)) - ->assertForbidden(); - } - - public function testAdminCanEditOrganizationProfile(): void - { - $admin = User::factory()->admin()->create(); - - $organization = Organization::factory()->create(); - - $organizationProfile = OrganizationProfile::factory() - ->for($organization) - ->create(); - - $this->actingAs($admin) - ->get(route("organizations.profiles.edit", [$organization, $organizationProfile])) - ->assertOk(); - - $this->actingAs($admin) - ->put(route("organizations.profiles.update", [$organization, $organizationProfile]), [ - "label" => "Twitter", - "link" => "https://twitter.com", - ]) - ->assertSessionHasNoErrors() - ->assertRedirect(); - - $this->assertDatabaseHas("organization_profiles", [ - "organization_id" => $organization->id, - "label" => "Twitter", - "link" => "https://twitter.com", - ]); - } - - public function testUserCannotEditOrganizationProfile(): void - { - $user = User::factory()->create(); - - $organization = Organization::factory()->create(); - - $organizationProfile = OrganizationProfile::factory() - ->for($organization) - ->create(); - - $this->actingAs($user) - ->get(route("organizations.profiles.edit", [$organization, $organizationProfile])) - ->assertForbidden(); - - $this->actingAs($user) - ->put(route("organizations.profiles.update", [$organization, $organizationProfile])) - ->assertForbidden(); - } - - public function testAdminCanDeleteOrganizationProfile(): void - { - $admin = User::factory()->admin()->create(); - - $organization = Organization::factory()->create(); - - $organizationProfile = OrganizationProfile::factory() - ->for($organization) - ->create(); - - $this->assertDatabaseCount("organization_profiles", 1); - - $this->actingAs($admin) - ->delete(route("organizations.profiles.destroy", [$organization, $organizationProfile])) - ->assertRedirect(); - - $this->assertModelMissing($organizationProfile); - } - - public function testUserCannotDeleteOrganizationProfile(): void - { - $user = User::factory()->create(); - - $organization = Organization::factory()->create(); - - $organizationProfile = OrganizationProfile::factory() - ->for($organization) - ->create(); - - $this->actingAs($user) - ->delete(route("organizations.profiles.destroy", [$organization, $organizationProfile])) - ->assertForbidden(); - } - - public function testOrganizationProfileRequestHasRelatedOrganization(): void - { - $organization = Organization::factory()->create(); - $foreignOrganization = Organization::factory()->create(); - - $organizationProfile = OrganizationProfile::factory() - ->for($organization) - ->create(); - - $admin = User::factory()->admin()->create(); - - $this->actingAs($admin) - ->put(route("organizations.profiles.store", [$foreignOrganization, $organizationProfile])) - ->assertNotFound(); - - $this->actingAs($admin) - ->put(route("organizations.profiles.update", [$foreignOrganization, $organizationProfile])) - ->assertNotFound(); - - $this->actingAs($admin) - ->delete(route("organizations.profiles.destroy", [$foreignOrganization, $organizationProfile])) - ->assertNotFound(); - } -} diff --git a/tests/Feature/OrganizationTest.php b/tests/Feature/OrganizationTest.php deleted file mode 100644 index 66c4bf47..00000000 --- a/tests/Feature/OrganizationTest.php +++ /dev/null @@ -1,179 +0,0 @@ -count(10)->create(); - - $this->assertDatabaseCount("meetups", 10); - - $response = $this->get(route("organizations")) - ->assertOk(); - - foreach ($organizations as $organization) { - $response->assertSee($organization->name) - ->assertSee($organization->logo_path) - ->assertSee($organization->description); - } - } - - public function testOrganizationsListIsPaginated(): void - { - Organization::factory()->count(30)->create(); - - $this->assertDatabaseCount("meetups", 30); - - $organizations = Meetup::query() - ->latest() - ->skip(20) - ->take(10); - - $response = $this->get(route("organizations") . "?page=2") - ->assertOk(); - - foreach ($organizations as $organization) { - $response->assertSee($organization->name) - ->assertSee($organization->logo_path) - ->assertSee($organization->description); - } - } - - public function testUserCanSeeOrganization(): void - { - $organization = Organization::factory()->create(); - - $this->get(route("organizations.show", $organization)) - ->assertOk() - ->assertSee($organization->name) - ->assertSee($organization->logo_path) - ->assertSee($organization->description) - ->assertSee($organization->location) - ->assertSee($organization->foundation_date) - ->assertSee($organization->website_url) - ->assertSee($organization->number_of_employees); - } - - public function testAdminCanCreateOrganization(): void - { - $admin = User::factory()->admin()->create(); - - $this->actingAs($admin) - ->get(route("organizations.create")) - ->assertOk(); - - $this->actingAs($admin) - ->post(route("organizations.store"), [ - "name" => "Test organization", - "description" => "Test organization description", - "location" => "Panama", - "organization_type" => "test", - "foundation_date" => Carbon::parse("2022-01-01 10:00:00"), - "number_of_employees" => 1000, - "website_url" => "https://testorganization.info", - ]) - ->assertRedirect(route("organizations.create")); - - $this->assertDatabaseHas("organizations", [ - "name" => "Test organization", - "description" => "Test organization description", - "location" => "Panama", - "organization_type" => "test", - "foundation_date" => Carbon::parse("2022-01-01 10:00:00"), - "number_of_employees" => 1000, - "website_url" => "https://testorganization.info", - ]); - } - - public function testUserCannotCreateOrganization(): void - { - $user = User::factory()->create(); - - $this->actingAs($user) - ->get(route("organizations.create")) - ->assertForbidden(); - - $this->actingAs($user) - ->post(route("organizations.store")) - ->assertForbidden(); - } - - public function testAdminCanEditOrganization(): void - { - $admin = User::factory()->admin()->create(); - $organization = Organization::factory()->create(); - - $this->actingAs($admin) - ->get(route("organizations.edit", $organization)) - ->assertOk(); - - $this->actingAs($admin) - ->put(route("organizations.update", $organization), [ - "name" => "Test organization", - "description" => "Test description", - "location" => "Panama", - "organization_type" => "test", - "foundation_date" => Carbon::parse("2022-01-01 10:00:00"), - "number_of_employees" => 1000, - "website_url" => "https://testorganization.info", - ]) - ->assertSessionHasNoErrors() - ->assertRedirect(route("organizations.edit", $organization)); - - $this->assertDatabaseHas("organizations", [ - "name" => "Test organization", - "description" => "Test description", - "location" => "Panama", - "organization_type" => "test", - "foundation_date" => Carbon::parse("2022-01-01 10:00:00"), - "number_of_employees" => 1000, - "website_url" => "https://testorganization.info", - ]); - } - - public function testUserCannotEditOrganization(): void - { - $organization = Organization::factory()->create(); - $user = User::factory()->create(); - - $this->actingAs($user) - ->get(route("organizations.edit", $organization)) - ->assertForbidden(); - } - - public function testAdminCanDeleteOrganization(): void - { - $admin = User::factory()->admin()->create(); - - $organization = Organization::factory()->create(); - - $this->actingAs($admin) - ->delete(route("organizations.destroy", $organization)) - ->assertRedirect(); - - $this->assertModelMissing($organization); - } - - public function testUserCannotDeleteOrganization(): void - { - $admin = User::factory()->admin()->create(); - - $organization = Organization::factory()->create(); - - $this->actingAs($admin) - ->delete(route("organizations.destroy", $organization)); - } -} diff --git a/tests/Feature/Organizations/BrowseOrganizationsTest.php b/tests/Feature/Organizations/BrowseOrganizationsTest.php new file mode 100644 index 00000000..ad7d2051 --- /dev/null +++ b/tests/Feature/Organizations/BrowseOrganizationsTest.php @@ -0,0 +1,52 @@ +count(10)->create(); + + $this->assertDatabaseCount("organizations", 10); + + $response = $this->get(route("organizations")) + ->assertOk(); + + foreach ($organizations as $organization) { + $response->assertSee($organization->name) + ->assertSee($organization->logo_path) + ->assertSee($organization->description); + } + } + + public function testOrganizationsListIsPaginated(): void + { + Organization::factory()->count(30)->create(); + + $this->assertDatabaseCount("organizations", 30); + + $organizations = Meetup::query() + ->latest() + ->skip(20) + ->take(10); + + $response = $this->get(route("organizations") . "?page=2") + ->assertOk(); + + foreach ($organizations as $organization) { + $response->assertSee($organization->name) + ->assertSee($organization->logo_path) + ->assertSee($organization->description); + } + } +} diff --git a/tests/Feature/Organizations/CreateOrganizationsTest.php b/tests/Feature/Organizations/CreateOrganizationsTest.php new file mode 100644 index 00000000..3d860fe9 --- /dev/null +++ b/tests/Feature/Organizations/CreateOrganizationsTest.php @@ -0,0 +1,69 @@ + "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } + + public function testAdminCanCreateOrganization(): void + { + $this->actingAs($this->admin) + ->get(route("organizations.create")) + ->assertOk(); + + $this->actingAs($this->admin) + ->post(route("organizations.store"), [ + "name" => "Test organization", + "description" => "Test organization description", + "location" => "Panama", + "organization_type" => "test", + "foundation_date" => Carbon::parse("2022-01-01 10:00:00"), + "number_of_employees" => 1000, + "website_url" => "https://testorganization.info", + ]) + ->assertSessionHasNoErrors() + ->assertRedirect(); + + $this->assertDatabaseHas("organizations", [ + "name" => "Test organization", + "description" => "Test organization description", + "location" => "Panama", + "organization_type" => "test", + "foundation_date" => Carbon::parse("2022-01-01 10:00:00"), + "number_of_employees" => 1000, + "website_url" => "https://testorganization.info", + ]); + } + + public function testUserCannotCreateOrganization(): void + { + $user = User::factory()->create(); + + $this->actingAs($user) + ->get(route("organizations.create")) + ->assertForbidden(); + + $this->actingAs($user) + ->post(route("organizations.store")) + ->assertForbidden(); + } +} diff --git a/tests/Feature/Organizations/DeleteOrganizationsTest.php b/tests/Feature/Organizations/DeleteOrganizationsTest.php new file mode 100644 index 00000000..d318beda --- /dev/null +++ b/tests/Feature/Organizations/DeleteOrganizationsTest.php @@ -0,0 +1,48 @@ + "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } + + public function testAdminCanDeleteOrganization(): void + { + $organization = Organization::factory()->create(); + + $this->actingAs($this->admin) + ->delete(route("organizations.destroy", $organization)) + ->assertRedirect(); + + $this->assertModelMissing($organization); + } + + public function testUserCannotDeleteOrganization(): void + { + $user = User::factory()->create(); + + $organization = Organization::factory()->create(); + + $this->actingAs($user) + ->delete(route("organizations.destroy", $organization)) + ->assertForbidden(); + } +} diff --git a/tests/Feature/Organizations/EditOrganizationsTest.php b/tests/Feature/Organizations/EditOrganizationsTest.php new file mode 100644 index 00000000..2cdff16a --- /dev/null +++ b/tests/Feature/Organizations/EditOrganizationsTest.php @@ -0,0 +1,69 @@ + "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } + + public function testAdminCanEditOrganization(): void + { + $organization = Organization::factory()->create(); + + $this->actingAs($this->admin) + ->get(route("organizations.edit", $organization)) + ->assertOk(); + + $this->actingAs($this->admin) + ->put(route("organizations.update", $organization), [ + "name" => "Test organization", + "description" => "Test description", + "location" => "Panama", + "organization_type" => "test", + "foundation_date" => Carbon::parse("2022-01-01 10:00:00"), + "number_of_employees" => 1000, + "website_url" => "https://testorganization.info", + ]) + ->assertSessionHasNoErrors() + ->assertRedirect(); + + $this->assertDatabaseHas("organizations", [ + "name" => "Test organization", + "description" => "Test description", + "location" => "Panama", + "organization_type" => "test", + "foundation_date" => Carbon::parse("2022-01-01 10:00:00"), + "number_of_employees" => 1000, + "website_url" => "https://testorganization.info", + ]); + } + + public function testUserCannotEditOrganization(): void + { + $organization = Organization::factory()->create(); + $user = User::factory()->create(); + + $this->actingAs($user) + ->get(route("organizations.edit", $organization)) + ->assertForbidden(); + } +} diff --git a/tests/Feature/Organizations/Profiles/CreateOrganizationProfilesTest.php b/tests/Feature/Organizations/Profiles/CreateOrganizationProfilesTest.php new file mode 100644 index 00000000..6584057c --- /dev/null +++ b/tests/Feature/Organizations/Profiles/CreateOrganizationProfilesTest.php @@ -0,0 +1,64 @@ + "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } + + public function testAdminCanCreateOrganizationProfile(): void + { + $organization = Organization::factory()->create(); + + $this->actingAs($this->admin) + ->get(route("organizations.profiles.create", $organization)) + ->assertOk(); + + $this->actingAs($this->admin) + ->post(route("organizations.profiles.store", $organization), [ + "label" => "Facebook", + "link" => "https://facebook.com", + ]) + ->assertSessionHasNoErrors() + ->assertRedirect(); + + $this->assertDatabaseHas("organization_profiles", [ + "organization_id" => $organization->id, + "label" => "Facebook", + "link" => "https://facebook.com", + ]); + } + + public function testUserCannotCreateOrganizationProfile(): void + { + $user = User::factory()->create(); + + $organization = Organization::factory()->create(); + + $this->actingAs($user) + ->get(route("organizations.profiles.create", $organization)) + ->assertForbidden(); + + $this->actingAs($user) + ->post(route("organizations.profiles.store", $organization)) + ->assertForbidden(); + } +} diff --git a/tests/Feature/Organizations/Profiles/DeleteOrganizationProfilesTest.php b/tests/Feature/Organizations/Profiles/DeleteOrganizationProfilesTest.php new file mode 100644 index 00000000..37f96867 --- /dev/null +++ b/tests/Feature/Organizations/Profiles/DeleteOrganizationProfilesTest.php @@ -0,0 +1,63 @@ + "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } + + public function testAdminCanDeleteOrganizationProfile(): void + { + $organization = Organization::factory()->create(); + + OrganizationProfile::factory() + ->for($organization) + ->create(); + + $this->assertDatabaseCount("organization_profiles", 1); + $organizationProfile = OrganizationProfile::query()->first(); + + $this->actingAs($this->admin) + ->delete(route("organizations.profiles.destroy", [$organization, $organizationProfile])) + ->assertRedirect(); + + $this->assertModelMissing($organizationProfile); + } + + public function testUserCannotDeleteOrganizationProfile(): void + { + $user = User::factory()->create(); + + $organization = Organization::factory()->create(); + + OrganizationProfile::factory() + ->for($organization) + ->create(); + + $this->assertDatabaseCount("organization_profiles", 1); + $organizationProfile = OrganizationProfile::query()->first(); + + $this->actingAs($user) + ->delete(route("organizations.profiles.destroy", [$organization, $organizationProfile])) + ->assertForbidden(); + } +} diff --git a/tests/Feature/Organizations/Profiles/EditOrganizationProfilesTest.php b/tests/Feature/Organizations/Profiles/EditOrganizationProfilesTest.php new file mode 100644 index 00000000..a75006f8 --- /dev/null +++ b/tests/Feature/Organizations/Profiles/EditOrganizationProfilesTest.php @@ -0,0 +1,79 @@ + "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } + + public function testAdminCanEditOrganizationProfile(): void + { + $organization = Organization::factory()->create(); + + OrganizationProfile::factory() + ->for($organization) + ->create(); + + $this->assertDatabaseCount("organization_profiles", 1); + $organizationProfile = OrganizationProfile::query()->first(); + + $this->actingAs($this->admin) + ->get(route("organizations.profiles.edit", [$organization, $organizationProfile])) + ->assertOk(); + + $this->actingAs($this->admin) + ->put(route("organizations.profiles.update", [$organization, $organizationProfile]), [ + "label" => "Twitter", + "link" => "https://twitter.com", + ]) + ->assertSessionHasNoErrors() + ->assertRedirect(); + + $this->assertDatabaseHas("organization_profiles", [ + "organization_id" => $organization->id, + "label" => "Twitter", + "link" => "https://twitter.com", + ]); + } + + public function testUserCannotEditOrganizationProfile(): void + { + $user = User::factory()->create(); + + $organization = Organization::factory()->create(); + + OrganizationProfile::factory() + ->for($organization) + ->create(); + + $this->assertDatabaseCount("organization_profiles", 1); + $organizationProfile = OrganizationProfile::query()->first(); + + $this->actingAs($user) + ->get(route("organizations.profiles.edit", [$organization, $organizationProfile])) + ->assertForbidden(); + + $this->actingAs($user) + ->put(route("organizations.profiles.update", [$organization, $organizationProfile])) + ->assertForbidden(); + } +} diff --git a/tests/Feature/Organizations/Profiles/OrganizationProfilesRequestTest.php b/tests/Feature/Organizations/Profiles/OrganizationProfilesRequestTest.php new file mode 100644 index 00000000..3746906f --- /dev/null +++ b/tests/Feature/Organizations/Profiles/OrganizationProfilesRequestTest.php @@ -0,0 +1,57 @@ + "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } + + public function testOrganizationProfileRequestHasRelatedOrganization(): void + { + $organization = Organization::factory()->create(); + $foreignOrganization = Organization::factory()->create(); + + $organizationProfile = OrganizationProfile::factory() + ->for($organization) + ->create(); + + $this->actingAs($this->admin) + ->get(route("organizations.profiles.create", [$foreignOrganization, $organizationProfile])) + ->assertNotFound(); + + $this->actingAs($this->admin) + ->get(route("organizations.profiles.edit", [$foreignOrganization, $organizationProfile])) + ->assertNotFound(); + + $this->actingAs($this->admin) + ->post(route("organizations.profiles.store", [$foreignOrganization, $organizationProfile])) + ->assertNotFound(); + + $this->actingAs($this->admin) + ->put(route("organizations.profiles.update", [$foreignOrganization, $organizationProfile])) + ->assertNotFound(); + + $this->actingAs($this->admin) + ->delete(route("organizations.profiles.destroy", [$foreignOrganization, $organizationProfile])) + ->assertNotFound(); + } +} diff --git a/tests/Feature/SpeakerTest.php b/tests/Feature/SpeakerTest.php deleted file mode 100644 index 2aec4ae3..00000000 --- a/tests/Feature/SpeakerTest.php +++ /dev/null @@ -1,173 +0,0 @@ -create(); - $speakers = Speaker::factory()->count(10)->create(); - - $response = $this->actingAs($user) - ->get(route("speakers")) - ->assertOk(); - - foreach ($speakers as $speaker) { - $response->assertSee($speaker->name) - ->assertSee($speaker->avatar_path); - } - } - - public function testSpeakersListIsPaginated(): void - { - $user = User::factory()->create(); - - Speaker::factory()->count(30)->create(); - - $speakers = Speaker::query() - ->latest() - ->skip(20) - ->take(10); - - $response = $this->actingAs($user) - ->get(route("speakers") . "?page=2") - ->assertOk(); - - foreach ($speakers as $speaker) { - $response->assertSee($speaker->name) - ->assertSee($speaker->avatar_path); - } - } - - public function testUserCanSeeSpeaker(): void - { - $user = User::factory()->create(); - - $speaker = Speaker::factory()->create(); - - $this->actingAs($user) - ->get(route("speakers.show"), $speaker) - ->assertOk() - ->assertSee($speaker->name) - ->assertSee($speaker->avatar_path) - ->assertSee($speaker->description) - ->assertSee($speaker->linkedin_url) - ->assertSee($speaker->github_url); - } - - public function testAdminCanCreateSpeaker(): void - { - $admin = User::factory()->admin()->create(); - - $this->actingAs($admin) - ->get(route("speakers.create")) - ->assertOk(); - - $this->actingAs($admin) - ->post(route("speakers.store"), [ - "name" => "speaker", - "description" => "speaker description", - "linkedin_url" => "https://linkedin.com/example", - "github_url" => "https://github.com/example", - ]) - ->assertSessionHasNoErrors() - ->assertRedirect(); - - $this->assertDatabaseHas("speakers", [ - "name" => "speaker", - "description" => "speaker description", - "linkedin_url" => "https://linkedin.com/example", - "github_url" => "https://github.com/example", - ]); - } - - public function testUserCannotCreateSpeaker(): void - { - $user = User::factory()->create(); - - $this->actingAs($user) - ->get(route("speakers.create")) - ->assertForbidden(); - - $this->actingAs($user) - ->post(route("speakers.store")) - ->assertForbidden(); - } - - public function testAdminCanEditSpeaker(): void - { - $admin = User::factory()->admin()->create(); - - $speaker = Speaker::factory()->create(); - - $this->actingAs($admin) - ->get(route("speakers.edit", $speaker)) - ->assertOk(); - - $this->actingAs($admin) - ->put(route("speakers.update", $speaker), [ - "name" => "speaker", - "description" => "speaker description", - "linkedin_url" => "https://linkedin.com/", - "github_url" => "https://github.com/", - ]) - ->assertSessionHasNoErrors() - ->assertRedirect(); - - $this->assertDatabaseHas("speakers", [ - "name" => "speaker", - "description" => "speaker description", - "linkedin_url" => "https://linkedin.com/", - "github_url" => "https://github.com/", - ]); - } - - public function testUserCannotEditSpeaker(): void - { - $user = User::factory()->create(); - - $speaker = Speaker::factory()->create(); - - $this->actingAs($user) - ->get(route("speakers.edit", $speaker)) - ->assertForbidden(); - - $this->actingAs($user) - ->put(route("speakers.update", $speaker)) - ->assertForbidden(); - } - - public function testAdminCanDeleteSpeaker(): void - { - $admin = User::factory()->admin()->create(); - - $speaker = Speaker::factory()->create(); - - $this->actingAs($admin) - ->delete(route("speakers.destroy", $speaker)) - ->assertRedirect(); - - $this->assertModelMissing($speaker); - } - - public function testUserCannotDeleteSpeaker(): void - { - $user = User::factory()->admin()->create(); - - $speaker = Speaker::factory()->create(); - - $this->actingAs($user) - ->delete(route("speakers.destroy", $speaker)) - ->assertRedirect(); - } -} diff --git a/tests/Feature/Speakers/BrowseSpeakersTest.php b/tests/Feature/Speakers/BrowseSpeakersTest.php new file mode 100644 index 00000000..01f149e3 --- /dev/null +++ b/tests/Feature/Speakers/BrowseSpeakersTest.php @@ -0,0 +1,51 @@ +create(); + $speakers = Speaker::factory()->count(10)->create(); + + $response = $this->actingAs($user) + ->get(route("speakers")) + ->assertOk(); + + foreach ($speakers as $speaker) { + $response->assertSee($speaker->name) + ->assertSee($speaker->avatar_path); + } + } + + public function testSpeakersListIsPaginated(): void + { + $user = User::factory()->create(); + + Speaker::factory()->count(30)->create(); + + $speakers = Speaker::query() + ->latest() + ->skip(20) + ->take(10); + + $response = $this->actingAs($user) + ->get(route("speakers") . "?page=2") + ->assertOk(); + + foreach ($speakers as $speaker) { + $response->assertSee($speaker->name) + ->assertSee($speaker->avatar_path); + } + } +} diff --git a/tests/Feature/Speakers/CreateSpeakersTest.php b/tests/Feature/Speakers/CreateSpeakersTest.php new file mode 100644 index 00000000..aa29999d --- /dev/null +++ b/tests/Feature/Speakers/CreateSpeakersTest.php @@ -0,0 +1,62 @@ + "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } + + public function testAdminCanCreateSpeaker(): void + { + $this->actingAs($this->admin) + ->get(route("speakers.create")) + ->assertOk(); + + $this->actingAs($this->admin) + ->post(route("speakers.store"), [ + "name" => "speaker", + "description" => "speaker description", + "linkedin_url" => "https://linkedin.com/example", + "github_url" => "https://github.com/example", + ]) + ->assertSessionHasNoErrors() + ->assertRedirect(); + + $this->assertDatabaseHas("speakers", [ + "name" => "speaker", + "description" => "speaker description", + "linkedin_url" => "https://linkedin.com/example", + "github_url" => "https://github.com/example", + ]); + } + + public function testUserCannotCreateSpeaker(): void + { + $user = User::factory()->create(); + + $this->actingAs($user) + ->get(route("speakers.create")) + ->assertForbidden(); + + $this->actingAs($user) + ->post(route("speakers.store")) + ->assertForbidden(); + } +} diff --git a/tests/Feature/Speakers/DeleteSpeakersTest.php b/tests/Feature/Speakers/DeleteSpeakersTest.php new file mode 100644 index 00000000..6f44513a --- /dev/null +++ b/tests/Feature/Speakers/DeleteSpeakersTest.php @@ -0,0 +1,48 @@ + "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } + + public function testAdminCanDeleteSpeaker(): void + { + $speaker = Speaker::factory()->create(); + + $this->actingAs($this->admin) + ->delete(route("speakers.destroy", $speaker)) + ->assertRedirect(); + + $this->assertModelMissing($speaker); + } + + public function testUserCannotDeleteSpeaker(): void + { + $user = User::factory()->create(); + + $speaker = Speaker::factory()->create(); + + $this->actingAs($user) + ->delete(route("speakers.destroy", $speaker)) + ->assertForbidden(); + } +} diff --git a/tests/Feature/Speakers/EditSpeakersTest.php b/tests/Feature/Speakers/EditSpeakersTest.php new file mode 100644 index 00000000..6320e7e9 --- /dev/null +++ b/tests/Feature/Speakers/EditSpeakersTest.php @@ -0,0 +1,67 @@ + "admin"]); + $this->admin = User::factory()->create()->assignRole("admin"); + } + + public function testAdminCanEditSpeaker(): void + { + $speaker = Speaker::factory()->create(); + + $this->actingAs($this->admin) + ->get(route("speakers.edit", $speaker)) + ->assertOk(); + + $this->actingAs($this->admin) + ->put(route("speakers.update", $speaker), [ + "name" => "speaker", + "description" => "speaker description", + "linkedin_url" => "https://linkedin.com/", + "github_url" => "https://github.com/", + ]) + ->assertSessionHasNoErrors() + ->assertRedirect(); + + $this->assertDatabaseHas("speakers", [ + "name" => "speaker", + "description" => "speaker description", + "linkedin_url" => "https://linkedin.com/", + "github_url" => "https://github.com/", + ]); + } + + public function testUserCannotEditSpeaker(): void + { + $user = User::factory()->create(); + + $speaker = Speaker::factory()->create(); + + $this->actingAs($user) + ->get(route("speakers.edit", $speaker)) + ->assertForbidden(); + + $this->actingAs($user) + ->put(route("speakers.update", $speaker)) + ->assertForbidden(); + } +} diff --git a/tests/Feature/UserProfileTest.php b/tests/Feature/UserProfileTest.php deleted file mode 100644 index 885c85ee..00000000 --- a/tests/Feature/UserProfileTest.php +++ /dev/null @@ -1,75 +0,0 @@ -create(); - - $this->actingAs($user) - ->get(route("users.edit", $user)) - ->assertOk(); - - $this->actingAs($user) - ->put(route("users.update", $user), [ - "name" => "John Doe", - "email" => "john.doe@example.com", - ]) - ->assertSessionHasNoErrors() - ->assertRedirect(); - - $this->assertDatabaseHas("users", [ - "name" => "John Doe", - "email" => "john.doe@example.com", - ]); - } - - public function testUserCannotEditAnotherUserProfile(): void - { - $user = User::factory()->create(); - - $unauthorizedUser = User::factory()->create(); - - $this->actingAs($user) - ->get(route("users.edit", $unauthorizedUser)) - ->assertForbidden(); - - $this->actingAs($user) - ->put(route("users.update", $user)) - ->assertForbidden(); - } - - public function testUserProfileDataIsRequired(): void - { - $user = User::factory()->create(); - - $this->actingAs($user) - ->put(route("users.update", $user)) - ->assertInvalid([ - "name", - "email", - ]); - } - - public function testProfileDataIsRequired(): void - { - $user = User::factory()->create(); - - $this->actingAs($user) - ->put(route("users.update", $user)) - ->assertInvalid([ - "name", - "email", - ]); - } -}