Commit b3d1e5b0 authored by Jacob Priddy's avatar Jacob Priddy 👌

Fix tests and add tests to make sure door entries get logged

parent 9a0f9d7a
Pipeline #5601 canceled with stages
in 23 seconds
...@@ -37,7 +37,7 @@ class User extends Authenticatable ...@@ -37,7 +37,7 @@ class User extends Authenticatable
*/ */
public function entries(): HasMany public function entries(): HasMany
{ {
$this->hasMany(Entry::class); return $this->hasMany(Entry::class);
} }
/** /**
......
...@@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema; ...@@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
class CreateLogTable extends Migration class CreateEntriesTable extends Migration
{ {
/** /**
* Run the migrations. * Run the migrations.
......
...@@ -13,6 +13,14 @@ class InMemoryAttemptsRepository implements AttemptsRepository ...@@ -13,6 +13,14 @@ class InMemoryAttemptsRepository implements AttemptsRepository
*/ */
protected array $attempts = []; protected array $attempts = [];
/**
* @return \Source\Entities\Attempt[]
*/
public function all(): array
{
return $this->attempts;
}
/** /**
* @inheritDoc * @inheritDoc
*/ */
......
...@@ -13,6 +13,14 @@ class InMemoryEntriesRepository implements EntriesRepository ...@@ -13,6 +13,14 @@ class InMemoryEntriesRepository implements EntriesRepository
*/ */
protected array $entries = []; protected array $entries = [];
/**
* @return \Source\Entities\Entry[]
*/
public function all(): array
{
return $this->entries;
}
/** /**
* @inheritDoc * @inheritDoc
*/ */
......
...@@ -21,6 +21,7 @@ class DoorDatabaseTest extends DatabaseTestCase ...@@ -21,6 +21,7 @@ class DoorDatabaseTest extends DatabaseTestCase
/** /**
* @test * @test
* @throws \Source\Exceptions\EntityExistsException
*/ */
public function it_creates_and_finds_doors(): void public function it_creates_and_finds_doors(): void
{ {
......
...@@ -10,7 +10,9 @@ use Source\UseCases\Door\Access\Access; ...@@ -10,7 +10,9 @@ use Source\UseCases\Door\Access\Access;
use Source\Exceptions\AuthorizationException; use Source\Exceptions\AuthorizationException;
use Source\Exceptions\AuthenticationException; use Source\Exceptions\AuthenticationException;
use Source\Gateways\Users\InMemoryUsersRepository; use Source\Gateways\Users\InMemoryUsersRepository;
use Source\Gateways\Entries\InMemoryEntriesRepository;
use Source\Gateways\DoorUser\InMemoryDoorUserRepository; use Source\Gateways\DoorUser\InMemoryDoorUserRepository;
use Source\Gateways\Attempts\InMemoryAttemptsRepository;
class UseCaseTest extends TestCase class UseCaseTest extends TestCase
{ {
...@@ -33,16 +35,30 @@ class UseCaseTest extends TestCase ...@@ -33,16 +35,30 @@ class UseCaseTest extends TestCase
*/ */
protected Access $useCase; protected Access $useCase;
/**
* @var \Source\Gateways\Attempts\InMemoryAttemptsRepository
*/
protected InMemoryAttemptsRepository $attempts;
/**
* @var \Source\Gateways\Entries\InMemoryEntriesRepository
*/
protected InMemoryEntriesRepository $entries;
public function setUp(): void public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->users = new InMemoryUsersRepository(); $this->users = new InMemoryUsersRepository();
$this->doorUser = new InMemoryDoorUserRepository(); $this->doorUser = new InMemoryDoorUserRepository();
$this->attempts = new InMemoryAttemptsRepository();
$this->entries = new InMemoryEntriesRepository();
$this->useCase = new Access( $this->useCase = new Access(
self::EXPECTED_ACCESS_DOOR_ID, self::EXPECTED_ACCESS_DOOR_ID,
$this->users, $this->users,
$this->doorUser $this->doorUser,
$this->attempts,
$this->entries
); );
} }
...@@ -78,7 +94,13 @@ class UseCaseTest extends TestCase ...@@ -78,7 +94,13 @@ class UseCaseTest extends TestCase
public function it_will_not_check_for_non_existent_doors(): void public function it_will_not_check_for_non_existent_doors(): void
{ {
$this->expectException(AuthenticationException::class); $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(''); $this->handleTest('');
} }
...@@ -92,6 +114,9 @@ class UseCaseTest extends TestCase ...@@ -92,6 +114,9 @@ class UseCaseTest extends TestCase
$this->expectException(AuthorizationException::class); $this->expectException(AuthorizationException::class);
$this->users->create(self::createValidUser('doorcode')); $this->users->create(self::createValidUser('doorcode'));
$this->handleTest('asdf'); $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 ...@@ -104,6 +129,9 @@ class UseCaseTest extends TestCase
$this->expectException(AuthorizationException::class); $this->expectException(AuthorizationException::class);
$this->users->create(self::createValidUser('doorcode')); $this->users->create(self::createValidUser('doorcode'));
$this->handleTest('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 ...@@ -118,6 +146,9 @@ class UseCaseTest extends TestCase
$this->doorUser->addGroupToDoor(self::EXPECTED_ACCESS_DOOR_ID, 5); $this->doorUser->addGroupToDoor(self::EXPECTED_ACCESS_DOOR_ID, 5);
$this->doorUser->addGroupToUser(self::USER_ID, 9); $this->doorUser->addGroupToUser(self::USER_ID, 9);
$this->handleTest('doorcode'); $this->handleTest('doorcode');
$this->assertCount(1, $this->entries->all());
$this->assertFalse($this->entries->all()[0]->wasSuccessful());
} }
/** /**
...@@ -131,6 +162,8 @@ class UseCaseTest extends TestCase ...@@ -131,6 +162,8 @@ class UseCaseTest extends TestCase
$this->doorUser->addGroupToDoor(self::EXPECTED_ACCESS_DOOR_ID, 1); $this->doorUser->addGroupToDoor(self::EXPECTED_ACCESS_DOOR_ID, 1);
$this->doorUser->addGroupToUser(self::USER_ID, 1); $this->doorUser->addGroupToUser(self::USER_ID, 1);
$this->handleTest('doorcode'); $this->handleTest('doorcode');
$this->assertTrue(true);
$this->assertCount(1, $this->entries->all());
$this->assertTrue($this->entries->all()[0]->wasSuccessful());
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment