From 090d99a360398bab8fcf5d1274e2bcbff5729c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 11 Oct 2017 13:17:50 +0200 Subject: [PATCH] Frontend: fix warnings in withoutAssignedUsers filter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- js/filters/withoutAssignedUsers.js | 10 ++- .../database/AssignedUsersMapperTest.php | 3 + tests/unit/Service/CardServiceTest.php | 71 +++++++++++++++++++ 3 files changed, 81 insertions(+), 3 deletions(-) diff --git a/js/filters/withoutAssignedUsers.js b/js/filters/withoutAssignedUsers.js index 0b8507bae..ac8056242 100644 --- a/js/filters/withoutAssignedUsers.js +++ b/js/filters/withoutAssignedUsers.js @@ -20,10 +20,13 @@ * */ -/** +/* global app */ +/* global angular */ + +/* * Remove all assignedUsers from users list */ -app.filter('withoutAssignedUsers', function ($filter) { +app.filter('withoutAssignedUsers', function () { return function (users, assignedUsers) { var _result = []; angular.forEach(users, function (user) { @@ -33,8 +36,9 @@ app.filter('withoutAssignedUsers', function ($filter) { _found = true; } }); - if (_found === false) + if (_found === false) { _result.push(user); + } }); return _result; }; diff --git a/tests/integration/database/AssignedUsersMapperTest.php b/tests/integration/database/AssignedUsersMapperTest.php index 679dbc040..434e23cf7 100644 --- a/tests/integration/database/AssignedUsersMapperTest.php +++ b/tests/integration/database/AssignedUsersMapperTest.php @@ -102,6 +102,9 @@ class AssignedUsersMapperTest extends \Test\TestCase { $this->stacks = $stacks; } + /** + * @covers ::__construct + */ public function testConstructor() { $this->assertAttributeInstanceOf(IDBConnection::class, 'db', $this->assignedUsersMapper); $this->assertAttributeEquals(AssignedUsers::class, 'entityClass', $this->assignedUsersMapper); diff --git a/tests/unit/Service/CardServiceTest.php b/tests/unit/Service/CardServiceTest.php index 19af7be46..69a66889e 100644 --- a/tests/unit/Service/CardServiceTest.php +++ b/tests/unit/Service/CardServiceTest.php @@ -24,10 +24,12 @@ namespace OCA\Deck\Service; +use OCA\Deck\Db\AssignedUsers; use OCA\Deck\Db\AssignedUsersMapper; use OCA\Deck\Db\Card; use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\StackMapper; +use OCA\Deck\NotFoundException; use OCA\Deck\StatusException; use Test\TestCase; @@ -240,5 +242,74 @@ class CardServiceTest extends TestCase { $this->cardService->removeLabel(123, 999); } + public function testAssignUser() { + $assignments = []; + $this->assignedUsersMapper->expects($this->once()) + ->method('find') + ->with(123) + ->willReturn($assignments); + $assignment = new AssignedUsers(); + $assignment->setCardId(123); + $assignment->setParticipant('admin'); + $this->assignedUsersMapper->expects($this->once()) + ->method('insert') + ->with($assignment) + ->willReturn($assignment); + $actual = $this->cardService->assignUser(123, 'admin'); + $this->assertEquals($assignment, $actual); + } + + public function testAssignUserExisting() { + $assignment = new AssignedUsers(); + $assignment->setCardId(123); + $assignment->setParticipant('admin'); + $assignments = [ + $assignment + ]; + $this->assignedUsersMapper->expects($this->once()) + ->method('find') + ->with(123) + ->willReturn($assignments); + $actual = $this->cardService->assignUser(123, 'admin'); + $this->assertFalse($actual); + } + + public function testUnassignUserExisting() { + $assignment = new AssignedUsers(); + $assignment->setCardId(123); + $assignment->setParticipant('admin'); + $assignments = [ + $assignment + ]; + $this->assignedUsersMapper->expects($this->once()) + ->method('find') + ->with(123) + ->willReturn($assignments); + $this->assignedUsersMapper->expects($this->once()) + ->method('delete') + ->with($assignment) + ->willReturn($assignment); + $actual = $this->cardService->unassignUser(123, 'admin'); + $this->assertEquals($assignment, $actual); + } + + /** + * @expectedException \OCA\Deck\NotFoundException + */ + public function testUnassignUserNotExisting() { + $assignment = new AssignedUsers(); + $assignment->setCardId(123); + $assignment->setParticipant('admin'); + $assignments = [ + $assignment + ]; + $this->assignedUsersMapper->expects($this->once()) + ->method('find') + ->with(123) + ->willReturn($assignments); + $actual = $this->cardService->unassignUser(123, 'user'); + $this->assertEquals($assignment, $actual); + } + } \ No newline at end of file