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

Get user api tests

parent 9f94ad8b
Pipeline #965 passed with stages
in 1 minute and 37 seconds
......@@ -85,4 +85,11 @@ class InMemoryUsersRepository implements UsersRepository {
public function exists(string $userId): bool {
return $this->get($userId) !== null;
}
/**
* Clears the repository
*/
public function clear(): void {
$this->users = [];
}
}
<?php
namespace Tests\Feature\Api\Users;
use Throwable;
use Tests\TestCase;
use Source\Entities\User;
use Source\Gateways\Users\UsersRepository;
use Illuminate\Foundation\Testing\TestResponse;
use Source\Gateways\Users\InMemoryUsersRepository;
use Illuminate\Contracts\Container\BindingResolutionException;
class GetUserApiTest extends TestCase {
protected TestResponse $response;
protected InMemoryUsersRepository $usersRepository;
/**
* @throws BindingResolutionException
*/
public function setUp(): void {
parent::setUp();
$this->usersRepository = $this->app->make(UsersRepository::class);
}
public function handleTest(string $userId): void {
$this->response = $this->getJson('/users/' . $userId);
}
/** @test */
public function it_returns_404_on_non_existent_user(): void {
$this->handleTest('asdfasdfasdfasd');
$this->response->assertStatus(404);
$this->response->assertExactJson(
[
'status' => 'error',
'code' => 404,
'message' => 'Entity not found',
]
);
}
/**
* @test
*/
public function it_returns_a_user(): void {
$user = new User(69, '', '', '', null, '', '', '', null, null, null);
$this->usersRepository->create($user);
$this->handleTest('69');
$this->response->assertJson(['status' => 'success']);
}
/**
* @throws Throwable
*/
public function tearDown(): void {
parent::tearDown();
$this->usersRepository->clear();
}
}
......@@ -135,7 +135,6 @@ class UseCaseTest extends TestCase {
* @throws EntityNotFoundException
*/
public function it_will_overwrite_pass_and_door_code(): void {
$user = new User(69, '', '', '', null, '', '', '', null, null, null);
$updatedUser = new User(0, '', '', '', null, '', '', '', null, null, null);
......
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