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

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
*/
public function entries(): HasMany
{
$this->hasMany(Entry::class);
return $this->hasMany(Entry::class);
}
/**
......
......@@ -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.
......
......@@ -13,6 +13,14 @@ class InMemoryAttemptsRepository implements AttemptsRepository
*/
protected array $attempts = [];
/**
* @return \Source\Entities\Attempt[]
*/
public function all(): array
{
return $this->attempts;
}
/**
* @inheritDoc
*/
......
......@@ -13,6 +13,14 @@ class InMemoryEntriesRepository implements EntriesRepository
*/
protected array $entries = [];
/**
* @return \Source\Entities\Entry[]
*/
public function all(): array
{
return $this->entries;
}
/**
* @inheritDoc
*/
......
......@@ -21,6 +21,7 @@ class DoorDatabaseTest extends DatabaseTestCase
/**
* @test
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_creates_and_finds_doors(): void
{
......
......@@ -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());
}
}
Supports Markdown
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