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

add door tests

parent 60b655cc
......@@ -2,13 +2,10 @@
namespace App;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Door extends Authenticatable
{
use SoftDeletes;
protected $fillable = [
'*'
];
......
......@@ -12,13 +12,13 @@ class DatabaseDoorsRepository implements DoorsRepository
*/
public function create(Door $door): Door
{
$dbDoor = \App\Door::create(
[
'location' => $door->getLocation(),
'name' => $door->getName(),
'token' => hash('sha256', $door->getToken()),
]
);
$dbDoor = new \App\Door();
$dbDoor->location = $door->getLocation();
$dbDoor->name = $door->getName();
$dbDoor->api_token = hash('sha512', $door->getToken());
$dbDoor->save();
return new Door(
$dbDoor->id,
......@@ -35,7 +35,7 @@ class DatabaseDoorsRepository implements DoorsRepository
*/
public function getByToken(string $token): ?Door
{
$dbDoor = \App\Door::where('api_token', hash('sha256', $token))->first();
$dbDoor = \App\Door::where('api_token', hash('sha512', $token))->first();
if (!$dbDoor) {
return null;
......
<?php
namespace Tests\Database;
use Source\Entities\Door;
use Tests\DatabaseTestCase;
use Source\Gateways\Doors\DatabaseDoorsRepository;
class DoorDatabaseTest extends DatabaseTestCase
{
protected DatabaseDoorsRepository $doors;
public function setUp(): void
{
parent::setUp();
$this->doors = new DatabaseDoorsRepository();
}
/**
* @test
*/
public function it_creates_and_finds_doors(): void
{
$door = $this->doors->create(new Door(0, 'loc', 'name', 'token'));
$this->assertEquals($door, $this->doors->getByToken('token'));
$this->assertNull($this->doors->getByToken('reee'));
}
}
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