Commit 79292bac authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

fix tests

parent 3bd86fb8
......@@ -3,16 +3,19 @@
namespace Source\UseCases\GroupUser\GetGroupUsers;
use Source\Entities\User;
use Source\Sanitize\Paginates;
use Source\UseCases\BasePresenter;
class APIPresenter extends BasePresenter implements Presenter
{
protected array $viewModel = [];
use Paginates;
protected array $users = [];
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->viewModel['users'] = array_map(function (User $user) {
$this->users = array_map(function (User $user) {
return $this->formatPartialUser($user);
}, $responseModel->getUsers());
}
......@@ -20,6 +23,11 @@ class APIPresenter extends BasePresenter implements Presenter
/** @inheritDoc */
public function getViewModel(): array
{
return $this->viewModel;
return $this->paginate($this->users);
}
public function raw(): array
{
return ['users' => $this->users];
}
}
......@@ -3,16 +3,19 @@
namespace Source\UseCases\GroupUser\GetUserGroups;
use Source\Entities\Group;
use Source\Sanitize\Paginates;
use Source\UseCases\BasePresenter;
class APIPresenter extends BasePresenter implements Presenter
{
protected array $viewModel = [];
use Paginates;
protected array $groups = [];
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->viewModel['groups'] = array_map(static function (Group $group) {
$this->groups = array_map(static function (Group $group) {
return [
'id' => $group->getId(),
'title' => $group->getTitle(),
......@@ -24,6 +27,11 @@ class APIPresenter extends BasePresenter implements Presenter
/** @inheritDoc */
public function getViewModel(): array
{
return $this->viewModel;
return $this->paginate($this->groups);
}
public function raw(): array
{
return ['groups' => $this->groups];
}
}
......@@ -71,6 +71,6 @@ class GetUsersForGroupApiTest extends AuthenticatesWithApplicationTestCase
$this->response->assertStatus(200);
$this->assertCount(1, $this->response->json('users'));
$this->assertCount(1, $this->response->json('data'));
}
}
......@@ -66,7 +66,7 @@ class GetCurrentUserGroupsApiTest extends AuthenticatesWithApplicationTestCase
$this->handleTest();
$this->response->assertStatus(200);
$this->response->assertJson(['groups' => [[
$this->response->assertJson(['data' => [[
'id' => $group->getId()
]]]);
}
......
......@@ -57,6 +57,7 @@ class GetGroupsForUserApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_gets_groups_for_a_user(): void
{
......@@ -71,6 +72,6 @@ class GetGroupsForUserApiTest extends AuthenticatesWithApplicationTestCase
$this->response->assertStatus(200);
$this->assertCount(1, $this->response->json('groups'));
$this->assertCount(1, $this->response->json('data'));
}
}
......@@ -24,15 +24,15 @@ class PresenterTest extends TestCase
}
/**
* @param \Source\Entities\Group[] $groups
* @param \Source\Entities\User[] $users
*/
public function handleTest(array $groups): void
public function handleTest(array $users): void
{
$this->model = new ResponseModel($groups);
$this->model = new ResponseModel($users);
$this->presenter->present($this->model);
$this->response = $this->presenter->getViewModel();
$this->response = $this->presenter->raw();
}
/**
......
......@@ -32,7 +32,7 @@ class PresenterTest extends TestCase
$this->presenter->present($this->model);
$this->response = $this->presenter->getViewModel();
$this->response = $this->presenter->raw();
}
/**
......
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