Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
Doorcode
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Guardians of the Kretschmar Elock System
Doorcode
Commits
1e919b34
Commit
1e919b34
authored
Mar 03, 2020
by
Jacob Priddy
👌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add use case for getting users in a group as well as tests for it
parent
446b906b
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
389 additions
and
59 deletions
+389
-59
src/web/backend/app/Providers/AppServiceProvider.php
src/web/backend/app/Providers/AppServiceProvider.php
+2
-0
src/web/backend/src/Gateways/GroupUser/InMemoryGroupUserRepository.php
...nd/src/Gateways/GroupUser/InMemoryGroupUserRepository.php
+4
-0
src/web/backend/src/UseCases/BasePresenter.php
src/web/backend/src/UseCases/BasePresenter.php
+27
-45
src/web/backend/src/UseCases/GroupUser/GetGroupUsers/APIPresenter.php
...end/src/UseCases/GroupUser/GetGroupUsers/APIPresenter.php
+25
-0
src/web/backend/src/UseCases/GroupUser/GetGroupUsers/GetGroupUsers.php
...nd/src/UseCases/GroupUser/GetGroupUsers/GetGroupUsers.php
+30
-0
src/web/backend/src/UseCases/GroupUser/GetGroupUsers/GetGroupUsersUseCase.php
...UseCases/GroupUser/GetGroupUsers/GetGroupUsersUseCase.php
+14
-0
src/web/backend/src/UseCases/GroupUser/GetGroupUsers/GetGroupUsersUseCaseServiceProvider.php
...ser/GetGroupUsers/GetGroupUsersUseCaseServiceProvider.php
+44
-0
src/web/backend/src/UseCases/GroupUser/GetGroupUsers/Presenter.php
...ackend/src/UseCases/GroupUser/GetGroupUsers/Presenter.php
+17
-0
src/web/backend/src/UseCases/GroupUser/GetGroupUsers/ResponseModel.php
...nd/src/UseCases/GroupUser/GetGroupUsers/ResponseModel.php
+24
-0
src/web/backend/src/UseCases/Users/Authenticate/APIPresenter.php
.../backend/src/UseCases/Users/Authenticate/APIPresenter.php
+1
-1
src/web/backend/src/UseCases/Users/CreateUser/APIPresenter.php
...eb/backend/src/UseCases/Users/CreateUser/APIPresenter.php
+1
-1
src/web/backend/src/UseCases/Users/GetAllUsers/APIPresenter.php
...b/backend/src/UseCases/Users/GetAllUsers/APIPresenter.php
+2
-9
src/web/backend/src/UseCases/Users/GetUser/APIPresenter.php
src/web/backend/src/UseCases/Users/GetUser/APIPresenter.php
+1
-1
src/web/backend/src/UseCases/Users/UpdateUser/APIPresenter.php
...eb/backend/src/UseCases/Users/UpdateUser/APIPresenter.php
+1
-1
src/web/backend/tests/Unit/Source/UseCases/GroupUser/GetGroupUsers/PresenterStub.php
...Source/UseCases/GroupUser/GetGroupUsers/PresenterStub.php
+30
-0
src/web/backend/tests/Unit/Source/UseCases/GroupUser/GetGroupUsers/PresenterTest.php
...Source/UseCases/GroupUser/GetGroupUsers/PresenterTest.php
+70
-0
src/web/backend/tests/Unit/Source/UseCases/GroupUser/GetGroupUsers/UseCaseTest.php
...t/Source/UseCases/GroupUser/GetGroupUsers/UseCaseTest.php
+95
-0
src/web/backend/tests/Unit/Source/UseCases/GroupUser/GetUserGroups/UseCaseTest.php
...t/Source/UseCases/GroupUser/GetUserGroups/UseCaseTest.php
+1
-1
No files found.
src/web/backend/app/Providers/AppServiceProvider.php
View file @
1e919b34
...
...
@@ -22,6 +22,7 @@ use Source\UseCases\Groups\UpdateGroup\UpdateGroupUseCaseServiceProvider;
use
Source\UseCases\Token\Authenticate\AuthenticateUseCaseServiceProvider
;
use
Source\UseCases\Groups\GetAllGroups\GetAllGroupsUseCaseServiceProvider
;
use
Source\UseCases\GroupUser\GetUserGroups\GetUserGroupsUseCaseServiceProvider
;
use
Source\UseCases\GroupUser\GetGroupUsers\GetGroupUsersUseCaseServiceProvider
;
use
Source\UseCases\GroupUser\AddUserToGroup\AddUserToGroupUseCaseServiceProvider
;
use
Source\UseCases\GroupUser\RemoveUserFromGroup\RemoveUserFromGroupUseCaseServiceProvider
;
use
Source\UseCases\Doors\Authenticate\AuthenticateUseCaseServiceProvider
as
DoorAuthenticateUseCaseServiceProvider
;
...
...
@@ -62,6 +63,7 @@ class AppServiceProvider extends ServiceProvider
// GroupUser
GetUserGroupsUseCaseServiceProvider
::
class
,
GetGroupUsersUseCaseServiceProvider
::
class
,
AddUserToGroupUseCaseServiceProvider
::
class
,
RemoveUserFromGroupUseCaseServiceProvider
::
class
,
...
...
src/web/backend/src/Gateways/GroupUser/InMemoryGroupUserRepository.php
View file @
1e919b34
...
...
@@ -61,6 +61,10 @@ class InMemoryGroupUserRepository implements GroupUserRepository
*/
public
function
getUsersForGroup
(
string
$groupId
):
array
{
if
(
!
$this
->
groups
->
exists
(
$groupId
))
{
throw
new
EntityNotFoundException
();
}
$users
=
[];
/**
...
...
src/web/backend/src/UseCases/BasePresenter.php
View file @
1e919b34
...
...
@@ -9,35 +9,6 @@ use Source\Entities\Group;
abstract
class
BasePresenter
{
/**
* @param bool|null $bool
* @param string $true
* @param string $false
* @return string
*/
public
function
formatBool
(
?bool
$bool
,
string
$true
=
'Yes'
,
string
$false
=
'No'
):
?string
{
if
(
$bool
===
null
)
{
return
null
;
}
return
$bool
?
$true
:
$false
;
}
/**
* @param Carbon|null $time
* @param string $format
* @return string|null
*/
public
function
formatTime
(
?Carbon
$time
,
string
$format
=
'g:i A'
):
?string
{
if
(
$time
===
null
)
{
return
null
;
}
return
$time
->
format
(
$format
);
}
/**
* @param Carbon|null $datetime
* @param string $format
...
...
@@ -53,10 +24,10 @@ abstract class BasePresenter
}
/**
* @param User $user
* @param
\Source\Entities\
User $user
* @return array
*/
public
function
formatUser
(
User
$user
):
array
public
function
format
Full
User
(
User
$user
):
array
{
return
[
'id'
=>
$user
->
getId
(),
...
...
@@ -71,6 +42,31 @@ abstract class BasePresenter
];
}
/**
* @param \Source\Entities\User $user
* @return array
*/
public
function
formatPartialUser
(
User
$user
):
array
{
$expired
=
false
;
if
(
$user
->
getExpiresAt
())
{
$expired
=
$user
->
getExpiresAt
()
<
Carbon
::
now
();
}
return
[
'id'
=>
$user
->
getId
(),
'first_name'
=>
$user
->
getFirstName
(),
'last_name'
=>
$user
->
getLastName
(),
'display_name'
=>
$user
->
getDisplayName
(),
'email'
=>
$user
->
getEmail
(),
'expired'
=>
$expired
,
];
}
/**
* @param \Source\Entities\Group $group
* @return array
*/
public
function
formatGroup
(
Group
$group
):
array
{
return
[
...
...
@@ -81,18 +77,4 @@ abstract class BasePresenter
'updated_at'
=>
$this
->
formatDateTime
(
$group
->
getUpdatedAt
()),
];
}
/**
* @param Carbon|null $date
* @param string $format
* @return string|null
*/
public
function
formatDate
(
?Carbon
$date
,
string
$format
=
'M j, Y'
):
?string
{
if
(
$date
===
null
)
{
return
null
;
}
return
$date
->
format
(
$format
);
}
}
src/web/backend/src/UseCases/GroupUser/GetGroupUsers/APIPresenter.php
0 → 100644
View file @
1e919b34
<?php
namespace
Source\UseCases\GroupUser\GetGroupUsers
;
use
Source\Entities\User
;
use
Source\UseCases\BasePresenter
;
class
APIPresenter
extends
BasePresenter
implements
Presenter
{
protected
array
$viewModel
=
[];
/** @inheritDoc */
public
function
present
(
ResponseModel
$responseModel
):
void
{
$this
->
viewModel
[
'users'
]
=
array_map
(
function
(
User
$user
)
{
return
$this
->
formatPartialUser
(
$user
);
},
$responseModel
->
getUsers
());
}
/** @inheritDoc */
public
function
getViewModel
():
array
{
return
$this
->
viewModel
;
}
}
src/web/backend/src/UseCases/GroupUser/GetGroupUsers/GetGroupUsers.php
0 → 100644
View file @
1e919b34
<?php
namespace
Source\UseCases\GroupUser\GetGroupUsers
;
use
Source\Gateways\GroupUser\GroupUserRepository
;
class
GetGroupUsers
implements
GetGroupUsersUseCase
{
/**
* @var \Source\Gateways\GroupUser\GroupUserRepository
*/
protected
GroupUserRepository
$repository
;
public
function
__construct
(
GroupUserRepository
$repository
)
{
$this
->
repository
=
$repository
;
}
/**
* @inheritDoc
*/
public
function
getUsersForGroup
(
string
$groupId
,
Presenter
$presenter
):
void
{
$users
=
$this
->
repository
->
getUsersForGroup
(
$groupId
);
$response
=
new
ResponseModel
(
$users
);
$presenter
->
present
(
$response
);
}
}
src/web/backend/src/UseCases/GroupUser/GetGroupUsers/GetGroupUsersUseCase.php
0 → 100644
View file @
1e919b34
<?php
namespace
Source\UseCases\GroupUser\GetGroupUsers
;
interface
GetGroupUsersUseCase
{
/**
* @param string $groupId
* @param \Source\UseCases\GroupUser\GetGroupUsers\Presenter $presenter
* @throws \Source\Exceptions\EntityNotFoundException
*/
public
function
getUsersForGroup
(
string
$groupId
,
Presenter
$presenter
):
void
;
}
src/web/backend/src/UseCases/GroupUser/GetGroupUsers/GetGroupUsersUseCaseServiceProvider.php
0 → 100644
View file @
1e919b34
<?php
namespace
Source\UseCases\GroupUser\GetGroupUsers
;
use
Illuminate\Contracts\Foundation\Application
;
use
Source\Gateways\GroupUser\GroupUserRepository
;
use
Illuminate\Contracts\Support\DeferrableProvider
;
use
Illuminate\Support\ServiceProvider
;
/**
* Service provider must be registered in AppServiceProvider
*/
class
GetGroupUsersUseCaseServiceProvider
extends
ServiceProvider
implements
DeferrableProvider
{
/**
* Register any application services.
*
* @return void
*/
public
function
register
()
{
$this
->
app
->
bind
(
GetGroupUsersUseCase
::
class
,
static
function
(
Application
$app
)
{
return
new
GetGroupUsers
(
$app
->
make
(
GroupUserRepository
::
class
));
});
}
/**
* Bootstrap any application services.
*
* @return void
*/
public
function
boot
():
void
{
}
/**
* @return array
*/
public
function
provides
()
{
return
[
GetGroupUsersUseCase
::
class
];
}
}
src/web/backend/src/UseCases/GroupUser/GetGroupUsers/Presenter.php
0 → 100644
View file @
1e919b34
<?php
namespace
Source\UseCases\GroupUser\GetGroupUsers
;
interface
Presenter
{
/**
* @param ResponseModel $responseModel
* @return void
*/
public
function
present
(
ResponseModel
$responseModel
):
void
;
/**
* @return array
*/
public
function
getViewModel
():
array
;
}
src/web/backend/src/UseCases/GroupUser/GetGroupUsers/ResponseModel.php
0 → 100644
View file @
1e919b34
<?php
namespace
Source\UseCases\GroupUser\GetGroupUsers
;
class
ResponseModel
{
/**
* @var \Source\Entities\User[]
*/
protected
array
$users
;
/**
* @param \Source\Entities\User[] $users
*/
public
function
__construct
(
array
$users
)
{
$this
->
users
=
$users
;
}
public
function
getUsers
():
array
{
return
$this
->
users
;
}
}
src/web/backend/src/UseCases/Users/Authenticate/APIPresenter.php
View file @
1e919b34
...
...
@@ -23,7 +23,7 @@ class APIPresenter extends BasePresenter implements Presenter
}
$this
->
viewModel
[
'user'
]
=
$this
->
formatUser
(
$user
);
$this
->
viewModel
[
'user'
]
=
$this
->
format
Full
User
(
$user
);
$this
->
viewModel
[
'token'
]
=
[
'value'
=>
$token
->
getTokenString
(),
'expires_at'
=>
$this
->
formatDateTime
(
$token
->
getExpiresAt
()),
...
...
src/web/backend/src/UseCases/Users/CreateUser/APIPresenter.php
View file @
1e919b34
...
...
@@ -11,7 +11,7 @@ class APIPresenter extends BasePresenter implements Presenter
/** @inheritDoc */
public
function
present
(
ResponseModel
$responseModel
):
void
{
$this
->
viewModel
[
'user'
]
=
$this
->
formatUser
(
$responseModel
->
getUser
());
$this
->
viewModel
[
'user'
]
=
$this
->
format
Full
User
(
$responseModel
->
getUser
());
}
/** @inheritDoc */
...
...
src/web/backend/src/UseCases/Users/GetAllUsers/APIPresenter.php
View file @
1e919b34
...
...
@@ -13,15 +13,8 @@ class APIPresenter extends BasePresenter implements Presenter
/** @inheritDoc */
public
function
present
(
ResponseModel
$responseModel
):
void
{
$this
->
viewModel
[
'users'
]
=
array_map
(
static
function
(
User
$user
)
{
return
[
'id'
=>
$user
->
getId
(),
'first_name'
=>
$user
->
getFirstName
(),
'last_name'
=>
$user
->
getLastName
(),
'display_name'
=>
$user
->
getDisplayName
(),
'email'
=>
$user
->
getEmail
(),
'expired'
=>
$user
->
getExpiresAt
()
<
Carbon
::
now
(),
];
$this
->
viewModel
[
'users'
]
=
array_map
(
function
(
User
$user
)
{
return
$this
->
formatPartialUser
(
$user
);
},
$responseModel
->
getUsers
());
}
...
...
src/web/backend/src/UseCases/Users/GetUser/APIPresenter.php
View file @
1e919b34
...
...
@@ -11,7 +11,7 @@ class APIPresenter extends BasePresenter implements Presenter
/** @inheritDoc */
public
function
present
(
ResponseModel
$responseModel
):
void
{
$this
->
viewModel
[
'user'
]
=
$this
->
formatUser
(
$responseModel
->
getUser
());
$this
->
viewModel
[
'user'
]
=
$this
->
format
Full
User
(
$responseModel
->
getUser
());
}
/** @inheritDoc */
...
...
src/web/backend/src/UseCases/Users/UpdateUser/APIPresenter.php
View file @
1e919b34
...
...
@@ -17,7 +17,7 @@ class APIPresenter extends BasePresenter implements Presenter
if
(
$responseModel
->
hasError
())
{
$this
->
viewModel
[
'message'
]
=
$responseModel
->
getError
();
}
else
{
$this
->
viewModel
[
'user'
]
=
$this
->
formatUser
(
$responseModel
->
getUser
());
$this
->
viewModel
[
'user'
]
=
$this
->
format
Full
User
(
$responseModel
->
getUser
());
}
}
...
...
src/web/backend/tests/Unit/Source/UseCases/GroupUser/GetGroupUsers/PresenterStub.php
0 → 100644
View file @
1e919b34
<?php
namespace
Tests\Unit\Source\UseCases\GroupUser\GetGroupUsers
;
use
Source\UseCases\GroupUser\GetGroupUsers\Presenter
;
use
Source\UseCases\GroupUser\GetGroupUsers\ResponseModel
;
class
PresenterStub
implements
Presenter
{
public
ResponseModel
$response
;
protected
bool
$presenterCalled
=
false
;
public
function
present
(
ResponseModel
$responseModel
):
void
{
$this
->
presenterCalled
=
true
;
$this
->
response
=
$responseModel
;
}
public
function
wasPresenterCalled
():
bool
{
return
$this
->
presenterCalled
;
}
public
function
getViewModel
():
array
{
return
[];
}
}
src/web/backend/tests/Unit/Source/UseCases/GroupUser/GetGroupUsers/PresenterTest.php
0 → 100644
View file @
1e919b34
<?php
namespace
Tests\Unit\Source\UseCases\GroupUser\GetGroupUsers
;
use
Source\Entities\User
;
use
PHPUnit\Framework\TestCase
;
use
Source\UseCases\GroupUser\GetGroupUsers\APIPresenter
;
use
Source\UseCases\GroupUser\GetGroupUsers\ResponseModel
;
class
PresenterTest
extends
TestCase
{
protected
APIPresenter
$presenter
;
protected
ResponseModel
$model
;
protected
array
$response
;
public
function
setUp
():
void
{
parent
::
setUp
();
$this
->
presenter
=
new
APIPresenter
();
}
/**
* @param \Source\Entities\Group[] $groups
*/
public
function
handleTest
(
array
$groups
):
void
{
$this
->
model
=
new
ResponseModel
(
$groups
);
$this
->
presenter
->
present
(
$this
->
model
);
$this
->
response
=
$this
->
presenter
->
getViewModel
();
}
/**
* @test
*/
public
function
it_formats_users_when_empty
():
void
{
$this
->
handleTest
([]);
$this
->
assertEquals
([
'users'
=>
[]],
$this
->
response
);
}
/** @test */
public
function
it_formats_a_user
():
void
{
$users
=
[
new
User
(
1
,
''
,
''
,
''
,
''
,
''
,
''
,
''
),
];
$this
->
handleTest
(
$users
);
$this
->
assertCount
(
1
,
$this
->
response
[
'users'
]);
$this
->
assertEquals
([
'users'
=>
[
[
'id'
=>
1
,
'first_name'
=>
''
,
'last_name'
=>
''
,
'display_name'
=>
''
,
'email'
=>
''
,
'expired'
=>
false
,
],
]],
$this
->
response
);
}
}
src/web/backend/tests/Unit/Source/UseCases/GroupUser/GetGroupUsers/UseCaseTest.php
0 → 100644
View file @
1e919b34
<?php
namespace
Tests\Unit\Source\UseCases\GroupUser\GetGroupUsers
;
use
Source\Entities\User
;
use
Source\Entities\Group
;
use
PHPUnit\Framework\TestCase
;
use
Source\Gateways\Users\UsersRepository
;
use
Source\Gateways\Groups\GroupsRepository
;
use
Source\Exceptions\EntityNotFoundException
;
use
Source\Gateways\GroupUser\GroupUserRepository
;
use
Source\Gateways\Users\InMemoryUsersRepository
;
use
Source\Gateways\Groups\InMemoryGroupsRepository
;
use
Source\Gateways\GroupUser\InMemoryGroupUserRepository
;
use
Source\UseCases\GroupUser\GetGroupUsers\ResponseModel
;
use
Source\UseCases\GroupUser\GetGroupUsers\GetGroupUsers
;
class
UseCaseTest
extends
TestCase
{
protected
ResponseModel
$response
;
protected
PresenterStub
$presenter
;
protected
GroupUserRepository
$repository
;
protected
GetGroupUsers
$useCase
;
protected
UsersRepository
$users
;
protected
GroupsRepository
$groups
;
public
function
setUp
():
void
{
parent
::
setUp
();
$this
->
users
=
new
InMemoryUsersRepository
();
$this
->
groups
=
new
InMemoryGroupsRepository
();
$this
->
repository
=
new
InMemoryGroupUserRepository
(
$this
->
users
,
$this
->
groups
);
$this
->
useCase
=
new
GetGroupUsers
(
$this
->
repository
);
$this
->
presenter
=
new
PresenterStub
();
}
/**
* @param string $groupId
* @throws \Source\Exceptions\EntityNotFoundException
*/
protected
function
handleTest
(
string
$groupId
):
void
{
$this
->
useCase
->
getUsersForGroup
(
$groupId
,
$this
->
presenter
);
$this
->
response
=
$this
->
presenter
->
response
;
}
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
*/
public
function
it_cannot_get_users_for_non_existent_group
():
void
{
$this
->
expectException
(
EntityNotFoundException
::
class
);
$this
->
handleTest
(
'asdf'
);
}
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
*/
public
function
it_gets_users_for_a_group
():
void
{
$user
=
$this
->
users
->
create
(
new
User
(
0
,
''
,
''
,
''
,
''
,
''
,
''
,
''
));
$group
=
$this
->
groups
->
create
(
new
Group
(
0
,
''
,
''
));
$this
->
repository
->
addUserToGroup
(
$user
->
getId
(),
$group
->
getId
());
$this
->
handleTest
(
$group
->
getId
());
$this
->
assertEquals
([
$user
],
$this
->
response
->
getUsers
());
}
}
src/web/backend/tests/Unit/Source/UseCases/GroupUser/GetUserGroups/UseCaseTest.php
View file @
1e919b34
...
...
@@ -56,7 +56,7 @@ class UseCaseTest extends TestCase
* @test
* @throws \Source\Exceptions\EntityNotFoundException
*/
public
function
it_cannot_get_groups_for_non_exist
i
ent_user
():
void
public
function
it_cannot_get_groups_for_non_existent_user
():
void
{
$this
->
expectException
(
EntityNotFoundException
::
class
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment