diff --git a/src/web/backend/app/User.php b/src/web/backend/app/User.php index 56d38052a9d555165ccef97e27b83fa7f1f5e42f..ee2732b1ebb8e880f1293fe2565a01f8a61fe705 100644 --- a/src/web/backend/app/User.php +++ b/src/web/backend/app/User.php @@ -37,7 +37,7 @@ class User extends Authenticatable */ public function entries(): HasMany { - $this->hasMany(Entry::class); + return $this->hasMany(Entry::class); } /** diff --git a/src/web/backend/database/migrations/2020_01_10_083534_create_entries_table.php b/src/web/backend/database/migrations/2020_01_10_083534_create_entries_table.php index ad0a5018a97caf1fee79123bb1be983afe0cfd2d..18778c7eb214dadf6a7defbd311093031467c6f7 100644 --- a/src/web/backend/database/migrations/2020_01_10_083534_create_entries_table.php +++ b/src/web/backend/database/migrations/2020_01_10_083534_create_entries_table.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreateLogTable extends Migration +class CreateEntriesTable extends Migration { /** * Run the migrations. diff --git a/src/web/backend/src/Gateways/Attempts/InMemoryAttemptsRepository.php b/src/web/backend/src/Gateways/Attempts/InMemoryAttemptsRepository.php index c722e568e87390dbd4aa4789d56ffe3ebd8975c2..c8c40b848cee12332ccea9dea59f0b5e206e96d6 100644 --- a/src/web/backend/src/Gateways/Attempts/InMemoryAttemptsRepository.php +++ b/src/web/backend/src/Gateways/Attempts/InMemoryAttemptsRepository.php @@ -13,6 +13,14 @@ class InMemoryAttemptsRepository implements AttemptsRepository */ protected array $attempts = []; + /** + * @return \Source\Entities\Attempt[] + */ + public function all(): array + { + return $this->attempts; + } + /** * @inheritDoc */ diff --git a/src/web/backend/src/Gateways/Entries/InMemoryEntriesRepository.php b/src/web/backend/src/Gateways/Entries/InMemoryEntriesRepository.php index d2c075ea6b15369d72ae07c061a1cee372519011..02a907afc40489bc6834133d310d6c696677b100 100644 --- a/src/web/backend/src/Gateways/Entries/InMemoryEntriesRepository.php +++ b/src/web/backend/src/Gateways/Entries/InMemoryEntriesRepository.php @@ -13,6 +13,14 @@ class InMemoryEntriesRepository implements EntriesRepository */ protected array $entries = []; + /** + * @return \Source\Entities\Entry[] + */ + public function all(): array + { + return $this->entries; + } + /** * @inheritDoc */ diff --git a/src/web/backend/tests/Database/DoorDatabaseTest.php b/src/web/backend/tests/Database/DoorDatabaseTest.php index b464477acd043c83c9e19435553a47635808ca62..aaecfe29672657f64a14cbcd9e35c5e27eeeada9 100644 --- a/src/web/backend/tests/Database/DoorDatabaseTest.php +++ b/src/web/backend/tests/Database/DoorDatabaseTest.php @@ -21,6 +21,7 @@ class DoorDatabaseTest extends DatabaseTestCase /** * @test + * @throws \Source\Exceptions\EntityExistsException */ public function it_creates_and_finds_doors(): void { diff --git a/src/web/backend/tests/Unit/Source/UseCases/Door/Access/UseCaseTest.php b/src/web/backend/tests/Unit/Source/UseCases/Door/Access/UseCaseTest.php index 1103445f663318ce5bfefdfcefe0bd2a9d75eabe..a4d67f07a6ab5be70a87d678045076bdeaa33dbf 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Door/Access/UseCaseTest.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Door/Access/UseCaseTest.php @@ -10,7 +10,9 @@ use Source\UseCases\Door\Access\Access; use Source\Exceptions\AuthorizationException; use Source\Exceptions\AuthenticationException; use Source\Gateways\Users\InMemoryUsersRepository; +use Source\Gateways\Entries\InMemoryEntriesRepository; use Source\Gateways\DoorUser\InMemoryDoorUserRepository; +use Source\Gateways\Attempts\InMemoryAttemptsRepository; class UseCaseTest extends TestCase { @@ -33,16 +35,30 @@ class UseCaseTest extends TestCase */ protected Access $useCase; + /** + * @var \Source\Gateways\Attempts\InMemoryAttemptsRepository + */ + protected InMemoryAttemptsRepository $attempts; + + /** + * @var \Source\Gateways\Entries\InMemoryEntriesRepository + */ + protected InMemoryEntriesRepository $entries; + public function setUp(): void { parent::setUp(); $this->users = new InMemoryUsersRepository(); $this->doorUser = new InMemoryDoorUserRepository(); + $this->attempts = new InMemoryAttemptsRepository(); + $this->entries = new InMemoryEntriesRepository(); $this->useCase = new Access( self::EXPECTED_ACCESS_DOOR_ID, $this->users, - $this->doorUser + $this->doorUser, + $this->attempts, + $this->entries ); } @@ -78,7 +94,13 @@ class UseCaseTest extends TestCase public function it_will_not_check_for_non_existent_doors(): void { $this->expectException(AuthenticationException::class); - $this->useCase = new Access(null, $this->users, $this->doorUser); + $this->useCase = new Access( + null, + $this->users, + $this->doorUser, + $this->attempts, + $this->entries + ); $this->handleTest(''); } @@ -92,6 +114,9 @@ class UseCaseTest extends TestCase $this->expectException(AuthorizationException::class); $this->users->create(self::createValidUser('doorcode')); $this->handleTest('asdf'); + + $this->assertCount(1, $this->attempts->all()); + $this->assertEquals(self::EXPECTED_ACCESS_DOOR_ID, $this->attempts->all()[0]->getDoorId()); } /** @@ -104,6 +129,9 @@ class UseCaseTest extends TestCase $this->expectException(AuthorizationException::class); $this->users->create(self::createValidUser('doorcode')); $this->handleTest('doorcode'); + + $this->assertCount(1, $this->entries->all()); + $this->assertFalse($this->entries->all()[0]->wasSuccessful()); } /** @@ -118,6 +146,9 @@ class UseCaseTest extends TestCase $this->doorUser->addGroupToDoor(self::EXPECTED_ACCESS_DOOR_ID, 5); $this->doorUser->addGroupToUser(self::USER_ID, 9); $this->handleTest('doorcode'); + + $this->assertCount(1, $this->entries->all()); + $this->assertFalse($this->entries->all()[0]->wasSuccessful()); } /** @@ -131,6 +162,8 @@ class UseCaseTest extends TestCase $this->doorUser->addGroupToDoor(self::EXPECTED_ACCESS_DOOR_ID, 1); $this->doorUser->addGroupToUser(self::USER_ID, 1); $this->handleTest('doorcode'); - $this->assertTrue(true); + + $this->assertCount(1, $this->entries->all()); + $this->assertTrue($this->entries->all()[0]->wasSuccessful()); } }