Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Mar 22, 2022
1 parent e4551bd commit 72134e6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lib/Db/BoardMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function findAllByUser(string $userId, ?int $limit = null, ?int $offset =

// shared with user
$qb->resetQueryParts();
$qb->selectDistinct('b.id', 'title', 'owner', 'color', 'archived', 'deleted_at', 'last_modified')
$qb->select('b.id', 'title', 'owner', 'color', 'archived', 'deleted_at', 'last_modified')
//->selectAlias('1', 'shared')
->from('deck_boards', 'b')
->innerJoin('b', 'deck_board_acl', 'acl', $qb->expr()->eq('b.id', 'acl.board_id'))
Expand Down Expand Up @@ -492,9 +492,9 @@ public function transferOwnership($ownerId, $newOwnerId) {
}

/**
* Reset Cache for a
* Reset Cache for a
* given board or a given user
*
*
* @param int|null $boardId
* @param int|null $userId
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ public function addAcl($boardId, $type, $participant, $edit, $share, $manage) {
$this->boardMapper->mapAcl($newAcl);
$this->changeHelper->boardChanged($boardId);

$board = $this->find($boardId);
$board = $this->boardMapper->find($boardId);
$this->clearBoardFromCache($board);

// TODO: use the dispatched event for this
Expand Down Expand Up @@ -731,7 +731,7 @@ private function clearBoardsCache() {
/**
* Clean a given board data
* from the Cache
*
*
* @param OCA\Deck\Db\Board $board
*/
private function clearBoardFromCache(Board $board) {
Expand Down
1 change: 1 addition & 0 deletions lib/Service/PermissionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public function findUsers($boardId, $refresh = false) {
if (array_key_exists((string) $boardId, $this->users) && !$refresh) {
return $this->users[(string) $boardId];
}

try {
$board = $this->boardMapper->find($boardId);
} catch (DoesNotExistException $e) {
Expand Down
28 changes: 14 additions & 14 deletions tests/unit/Service/BoardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function testFind() {
->method('find')
->with(1)
->willReturn($b1);
$this->permissionService->expects($this->once())
$this->permissionService->expects($this->any())
->method('findUsers')
->willReturn([
'admin' => 'admin',
Expand Down Expand Up @@ -258,6 +258,11 @@ public function testAddAcl() {
->method('insert')
->with($acl)
->willReturn($acl);
$this->permissionService->expects($this->any())
->method('findUsers')
->willReturn([
'admin' => 'admin',
]);
$this->assertEquals($acl, $this->service->addAcl(
123, 'user', 'admin', true, true, true
));
Expand Down Expand Up @@ -306,7 +311,7 @@ public function testAddAclExtendPermission($currentUserAcl, $providedAcl, $resul
->method('checkPermission')
->withConsecutive(
[$this->boardMapper, 123, Acl::PERMISSION_SHARE, null],
[$this->boardMapper, 123, Acl::PERMISSION_MANAGE, null]
[$this->boardMapper, 123, Acl::PERMISSION_MANAGE, null]
);
} else {
$this->aclMapper->expects($this->once())
Expand All @@ -329,20 +334,10 @@ public function testAddAclExtendPermission($currentUserAcl, $providedAcl, $resul
$this->permissionService->expects($this->exactly(3))
->method('userCan')
->willReturnOnConsecutiveCalls(
$currentUserAcl[0],
$currentUserAcl[1],
$currentUserAcl[0],
$currentUserAcl[1],
$currentUserAcl[2]
);

/* $this->permissionService->expects($this->at(2))
->method('userCan')
->willReturn($currentUserAcl[0]);
$this->permissionService->expects($this->at(3))
->method('userCan')
->willReturn($currentUserAcl[1]);
$this->permissionService->expects($this->at(4))
->method('userCan')
->willReturn($currentUserAcl[2]); */
}

$user = $this->createMock(IUser::class);
Expand All @@ -357,6 +352,11 @@ public function testAddAclExtendPermission($currentUserAcl, $providedAcl, $resul
$acl->resolveRelation('participant', function ($participant) use (&$user) {
return null;
});
$this->permissionService->expects($this->any())
->method('findUsers')
->willReturn([
'admin' => 'admin',
]);
$this->notificationHelper->expects($this->once())
->method('sendBoardShared');
$expected = clone $acl;
Expand Down

0 comments on commit 72134e6

Please sign in to comment.