Commit 85a3a7c7 authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Add api tests for get all users

parent 8a4550a4
Pipeline #1151 passed with stages
in 1 minute and 43 seconds
<?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 GetAllUsersApiTest extends TestCase {
protected TestResponse $response;
protected InMemoryUsersRepository $usersRepository;
/**
* @throws BindingResolutionException
*/
public function setUp(): void {
parent::setUp();
$this->usersRepository = $this->app->make(UsersRepository::class);
}
protected function handleTest(): void {
$this->response = $this->getJson('/users');
}
/**
* @test
*/
public function it_returns_empty_when_no_users_are_added(): void {
$this->handleTest();
$this->response->assertStatus(200);
$this->response->assertExactJson(
[
'status' => 'success',
'code' => 200,
'users' => []
]
);
}
/**
* @test
*/
public function it_returns_users_in_the_repository(): void {
$user = new User(69, '', '', '', null, '', '', '', null, null, null);
$this->usersRepository->create($user);
$this->handleTest();
$this->response->assertStatus(200);
$this->response->assertJsonCount(1, 'users');
$this->response->assertJson(['status' => 'success']);
}
/**
* @throws Throwable
*/
public function tearDown(): void {
parent::tearDown();
$this->usersRepository->clear();
}
}
......@@ -26,7 +26,7 @@ class GetUserApiTest extends TestCase {
$this->usersRepository = $this->app->make(UsersRepository::class);
}
public function handleTest(string $userId): void {
protected function handleTest(string $userId): void {
$this->response = $this->getJson('/users/' . $userId);
}
......
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