Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 5dd4a7e
Author: Anna-Sokolowska <[email protected]>
Date:   Wed May 11 15:39:03 2022 +0200

    #89 - cs-fix

commit 88dc366
Merge: 56b5dfd 86a33bb
Author: Anna-Sokolowska <[email protected]>
Date:   Wed May 11 13:33:24 2022 +0200

    Merge remote-tracking branch 'origin/#89-unit-tests' into #89-unit-tests

commit 56b5dfd
Author: Anna-Sokolowska <[email protected]>
Date:   Wed May 11 13:32:32 2022 +0200

    #89 - fix wrong admin invitation receiver

commit d6cd834
Author: Anna-Sokolowska <[email protected]>
Date:   Wed May 11 13:29:20 2022 +0200

    #89 - add organization profile scope bindings

commit 86a33bb
Author: Anna-Sokolowska <[email protected]>
Date:   Wed May 11 11:34:21 2022 +0200

    #89 - add cache views

commit d95551e
Author: Anna-Sokolowska <[email protected]>
Date:   Wed May 11 09:21:08 2022 +0200

    #89 - add .env.ci

commit 202c4d7
Author: Anna-Sokolowska <[email protected]>
Date:   Wed May 11 06:37:01 2022 +0200

    #89 - refactor tests

commit a851f81
Merge: 5ae0b73 e554018
Author: Anna-Sokolowska <[email protected]>
Date:   Tue May 10 19:57:25 2022 +0200

    Merge branch 'main' into #89-unit-tests

commit 5ae0b73
Author: Anna-Sokolowska <[email protected]>
Date:   Tue May 10 19:53:53 2022 +0200

    #89 - cs-fix

commit 7d7edd2
Merge: dbcba11 9a47c51
Author: Anna-Sokolowska <[email protected]>
Date:   Tue May 10 09:53:13 2022 +0200

    Merge branch 'main' into #89-unit-tests

commit dbcba11
Author: Anna-Sokolowska <[email protected]>
Date:   Tue May 10 09:41:43 2022 +0200

    #89 - basic features tests

commit 8120c8d
Merge: bd8c792 b24753d
Author: Anna-Sokolowska <[email protected]>
Date:   Sat May 7 20:40:04 2022 +0200

    Merge branch 'main' into #89-unit-tests

commit bd8c792
Author: Anna-Sokolowska <[email protected]>
Date:   Fri May 6 13:22:59 2022 +0200

    #89 - unit tests init
  • Loading branch information
MichalMyskow committed May 11, 2022
1 parent ca081ae commit 9fa1350
Show file tree
Hide file tree
Showing 29 changed files with 1,232 additions and 12 deletions.
18 changes: 18 additions & 0 deletions .env.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
APP_NAME=Laravel
APP_ENV=testing
APP_KEY=base64:fDr4dLzbpxwzo9eDpy8of5b6/Dt2Pnvnd3lng8cf348=
APP_DEBUG=true
APP_URL=http://localhost
APP_TIMEZONE='Europe/Warsaw'

LOG_CHANNEL=stack
LOG_LEVEL=debug

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=memcached
3 changes: 3 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ jobs:
- name: Run PHP linter
run: composer cs

- name: Cache views
run: php artisan view:cache

- name: Execute tests
run: php artisan test --env=ci
24 changes: 24 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);

$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
Blumilk\Meetup\Core\Http\Kernel::class
);

$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
Blumilk\Meetup\Core\Console\Kernel::class
);

$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
Blumilk\Meetup\Core\Exceptions\Handler::class
);

return $app;
2 changes: 2 additions & 0 deletions bootstrap/cache/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
</coverage>
<php>
<server name="APP_ENV" value="testing"/>
<server name="APP_URL" value="localhost"/>
<server name="DB_CONNECTION" value="testing"/>
<server name="APP_KEY" value="base64:fDr4dLzbpxwzo9eDpy8of5b6/Dt2Pnvnd3lng8cf348="/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="MAIL_MAILER" value="array"/>
Expand Down
12 changes: 6 additions & 6 deletions src/Http/Controllers/OrganizationProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@ public function store(StoreOrganizationProfileRequest $request, Organization $or
return redirect()->route("organizations.edit", $organization);
}

public function edit(Organization $organization, OrganizationProfile $profile): View
public function edit(Organization $organization, OrganizationProfile $organizationProfile): View
{
return view("organizations.profiles.edit")
->with([
"organization" => $organization,
"profile" => $profile,
"profile" => $organizationProfile,
"availableProfiles" => AvailableProfiles::casesToSelect(),
]);
}

public function update(UpdateOrganizationProfileRequest $request, Organization $organization, OrganizationProfile $profile): RedirectResponse
public function update(UpdateOrganizationProfileRequest $request, Organization $organization, OrganizationProfile $organizationProfile): RedirectResponse
{
$profile->update($request->validated());
$organizationProfile->update($request->validated());

return redirect()->route("organizations.edit", $organization);
}

public function destroy(Organization $organization, OrganizationProfile $profile): RedirectResponse
public function destroy(Organization $organization, OrganizationProfile $organizationProfile): RedirectResponse
{
$profile->delete();
$organizationProfile->delete();

return back();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Routing/WebRouting.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public function wire(): void
$this->router->controller(OrganizationProfileController::class)->group(function (): void {
$this->router->get("/organizations/{organization}/profiles/create", "create")->name("organizations.profiles.create");
$this->router->post("/organizations/{organization}/profiles", "store")->name("organizations.profiles.store");
$this->router->get("/organizations/{organization}/profiles/{profile}/edit", "edit")->name("organizations.profiles.edit");
$this->router->put("/organizations/{organization}/profiles/{profile}", "update")->name("organizations.profiles.update");
$this->router->delete("/organizations/{organization}/profiles/{profile}", "destroy")->name("organizations.profiles.destroy");
$this->router->get("/organizations/{organization}/profiles/{organizationProfile}/edit", "edit")->name("organizations.profiles.edit")->scopeBindings();
$this->router->put("/organizations/{organization}/profiles/{organizationProfile}", "update")->name("organizations.profiles.update")->scopeBindings();
$this->router->delete("/organizations/{organization}/profiles/{organizationProfile}", "destroy")->name("organizations.profiles.destroy")->scopeBindings();
});

$this->router->controller(SpeakersController::class)->group(function (): void {
Expand Down
3 changes: 2 additions & 1 deletion src/Services/InvitationsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

use Blumilk\Meetup\Core\Models\User;
use Blumilk\Meetup\Core\Notifications\InvitationEmailNotification;
use Illuminate\Support\Facades\Notification;

class InvitationsService
{
public function sendInvitation(User $senderUser, string $email): void
{
$senderUser->notify(new InvitationEmailNotification($senderUser, $email));
Notification::route("mail", $email)->notify(new InvitationEmailNotification($senderUser, $email));
}
}
20 changes: 20 additions & 0 deletions tests/CreatesApplication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Tests;

use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Application;

trait CreatesApplication
{
public function createApplication(): Application
{
$app = require __DIR__ . "/../bootstrap/app.php";

$app->make(Kernel::class)->bootstrap();

return $app;
}
}
57 changes: 57 additions & 0 deletions tests/Feature/ContactTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace Tests\Feature;

use Blumilk\Meetup\Core\Models\Contact;
use Blumilk\Meetup\Core\Notifications\ContactEmailNotification;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;

class ContactTest extends TestCase
{
use RefreshDatabase;

public function testUserCanSeeContactPage(): void
{
$this->get("/contact")
->assertOk();
}

public function testUserCanSendContactForm(): void
{
Notification::fake();

$this->post("/contact", [
"name" => "John",
"email" => "[email protected]",
"subject" => "Test subject",
"message" => "Test message",
])
->assertSessionHasNoErrors();

$this->assertDatabaseHas("contacts", [
"name" => "John",
"email" => "[email protected]",
"subject" => "Test subject",
"message" => "Test message",
]);

$contact = Contact::query()->first();

Notification::assertSentTo([$contact], ContactEmailNotification::class);
}

public function testContactFormDataIsRequired(): void
{
$this->post("/contact")
->assertInvalid([
"name",
"email",
"subject",
"message",
]);
}
}
59 changes: 59 additions & 0 deletions tests/Feature/InviteAdminTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace Tests\Feature;

use Blumilk\Meetup\Core\Models\User;
use Blumilk\Meetup\Core\Notifications\InvitationEmailNotification;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Spatie\Permission\Models\Role;
use Tests\TestCase;

class InviteAdminTest extends TestCase
{
use RefreshDatabase;

public User $admin;

protected function setUp(): void
{
parent::setUp();

Role::create(["name" => "admin"]);
$this->admin = User::factory()->create()->assignRole("admin");
}

public function testAdminCanSeeSendInvitationPage(): void
{
$this->actingAs($this->admin)
->get("/invitation")
->assertOk();
}

public function testAdminCanSendInvitation(): void
{
Notification::fake();

$this->actingAs($this->admin)
->post("/invitation", [
"email" => "[email protected]",
])
->assertSessionHasNoErrors();

Notification::assertSentOnDemand(
InvitationEmailNotification::class,
fn ($notification, $channels, $notifiable) => $notifiable->routes["mail"] === "[email protected]",
);
}

public function testUserCannotSendInvitation(): void
{
$user = User::factory()->create();

$this->actingAs($user)
->get("/invitation")
->assertLocation("/");
}
}
71 changes: 71 additions & 0 deletions tests/Feature/Meetups/BrowseMeetupsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

namespace Tests\Feature\Meetups;

use Blumilk\Meetup\Core\Models\Meetup;
use Blumilk\Meetup\Core\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Spatie\Permission\Models\Role;
use Tests\TestCase;

class BrowseMeetupsTest extends TestCase
{
use RefreshDatabase;

public User $admin;

protected function setUp(): void
{
parent::setUp();

Role::create(["name" => "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);
}
}
}
Loading

0 comments on commit 9fa1350

Please sign in to comment.