Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Due date notification setting per board #2430

Merged
merged 15 commits into from
Nov 9, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/integration/database/AssignedUsersMapperTest.php
Original file line number Diff line number Diff line change
@@ -189,6 +189,44 @@ public function testMapParticipant() {
$this->assertEquals('invalid-username', $assignment->resolveParticipant());
}

public function testIsUserAssigned() {
$assignment = new AssignedUsers();
$assignment->setCardId($this->cards[1]->getId());
$assignment->setParticipant(self::TEST_USER4);
$assignment->setType(AssignedUsers::TYPE_USER);
$this->assertFalse($this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER4));

$assignment = $this->assignedUsersMapper->insert($assignment);
$actual = $this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER4);
$this->assignedUsersMapper->delete($assignment);
$this->assertTrue($actual);

$this->assertFalse($this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER4));
}

public function testIsUserAssignedGroup() {
$assignment = new AssignedUsers();
$assignment->setCardId($this->cards[1]->getId());
$assignment->setParticipant('group');
$assignment->setType(AssignedUsers::TYPE_GROUP);
$this->assertFalse($this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER1));
$this->assertFalse($this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER2));
$this->assertFalse($this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER3));
$this->assertFalse($this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER4));

$assignment = $this->assignedUsersMapper->insert($assignment);
$this->assertTrue($this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER1));
$this->assertTrue($this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER2));
$this->assertTrue($this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER3));
$this->assertFalse($this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER4));
$this->assignedUsersMapper->delete($assignment);

$this->assertFalse($this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER1));
$this->assertFalse($this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER2));
$this->assertFalse($this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER3));
$this->assertFalse($this->assignedUsersMapper->isUserAssigned($this->cards[1]->getId(), self::TEST_USER4));
}

public function tearDown(): void {
$this->boardService->deleteForce($this->board->getId());
parent::tearDown();
228 changes: 204 additions & 24 deletions tests/unit/Notification/NotificationHelperTest.php
Original file line number Diff line number Diff line change
@@ -41,6 +41,19 @@
use OCP\Notification\INotification;
use PHPUnit\Framework\MockObject\MockObject;

class DummyUser extends \OC\User\User {

private $uid;

public function __construct($uid) {
$this->uid = $uid;
}

public function getUID() {
return $this->uid;
}
}

class NotificationHelperTest extends \Test\TestCase {

/** @var CardMapper|MockObject */
@@ -115,34 +128,19 @@ public function testSendCardDuedate() {
->with('asd', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL);

$card = $this->createMock(Card::class);
$card->expects($this->at(0))
->method('__call')
->with('getNotified', [])
->willReturn(false);
$card->expects($this->at(1))
->method('__call')
->with('getId', [])
->willReturn(123);
for ($i=0; $i<3; $i++) {
$card->expects($this->at($i*3+2))
->method('__call')
->with('getId', [])
->willReturn(123);
$card->expects($this->at($i*3+3))
->method('__call', [])
->with('getTitle')
->willReturn('MyCardTitle');
}
$card = Card::fromParams([
'notified' => false,
'id' => 123,
'title' => 'MyCardTitle'
]);
$this->cardMapper->expects($this->once())
->method('findBoardId')
->with(123)
->willReturn(234);
$board = $this->createMock(Board::class);
$board->expects($this->any())
->method('__call')
->with('getTitle', [])
->willReturn('MyBoardTitle');
$board = Board::fromParams([
'id' => 123,
'title' => 'MyBoardTitle'
]);
$this->boardMapper->expects($this->once())
->method('find')
->with(234)
@@ -208,6 +206,188 @@ public function testSendCardDuedate() {
$this->notificationHelper->sendCardDuedate($card);
}

public function testSendCardDuedateAssigned() {
$this->config->expects($this->at(0))
->method('getUserValue')
->with('foo', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED);
$this->config->expects($this->at(1))
->method('getUserValue')
->with('bar', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED);
$this->config->expects($this->at(2))
->method('getUserValue')
->with('asd', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED);

$users = [
new DummyUser('foo'), new DummyUser('bar'), new DummyUser('asd')
];
$card = Card::fromParams([
'notified' => false,
'id' => 123,
'title' => 'MyCardTitle'
]);
$card->setAssignedUsers([
new User($users[0])
]);
$this->cardMapper->expects($this->once())
->method('findBoardId')
->with(123)
->willReturn(234);
$board = Board::fromParams([
'id' => 123,
'title' => 'MyBoardTitle'
]);
$this->boardMapper->expects($this->once())
->method('find')
->with(234)
->willReturn($board);


$this->permissionService->expects($this->once())
->method('findUsers')
->with(234)
->willReturn($users);

$this->assignedUsersMapper->expects($this->exactly(3))
->method('isUserAssigned')
->willReturn(true);


$n1 = $this->createMock(INotification::class);
$n2 = $this->createMock(INotification::class);
$n3 = $this->createMock(INotification::class);

$n1->expects($this->once())->method('setApp')->with('deck')->willReturn($n1);
$n1->expects($this->once())->method('setUser')->with('foo')->willReturn($n1);
$n1->expects($this->once())->method('setObject')->with('card', 123)->willReturn($n1);
$n1->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n1);
$n1->expects($this->once())->method('setDateTime')->willReturn($n1);

$n2->expects($this->once())->method('setApp')->with('deck')->willReturn($n2);
$n2->expects($this->once())->method('setUser')->with('bar')->willReturn($n2);
$n2->expects($this->once())->method('setObject')->with('card', 123)->willReturn($n2);
$n2->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n2);
$n2->expects($this->once())->method('setDateTime')->willReturn($n2);

$n3->expects($this->once())->method('setApp')->with('deck')->willReturn($n3);
$n3->expects($this->once())->method('setUser')->with('asd')->willReturn($n3);
$n3->expects($this->once())->method('setObject')->with('card', 123)->willReturn($n3);
$n3->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n3);
$n3->expects($this->once())->method('setDateTime')->willReturn($n3);

$this->notificationManager->expects($this->at(0))
->method('createNotification')
->willReturn($n1);
$this->notificationManager->expects($this->at(1))
->method('notify')
->with($n1);
$this->notificationManager->expects($this->at(2))
->method('createNotification')
->willReturn($n2);
$this->notificationManager->expects($this->at(3))
->method('notify')
->with($n2);
$this->notificationManager->expects($this->at(4))
->method('createNotification')
->willReturn($n3);
$this->notificationManager->expects($this->at(5))
->method('notify')
->with($n3);

$this->cardMapper->expects($this->once())
->method('markNotified')
->with($card);

$this->notificationHelper->sendCardDuedate($card);
}


public function testSendCardDuedateNever() {
$this->config->expects($this->at(0))
->method('getUserValue')
->with('foo', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED);
$this->config->expects($this->at(1))
->method('getUserValue')
->with('bar', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED);
$this->config->expects($this->at(2))
->method('getUserValue')
->with('asd', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_OFF);

$users = [
new DummyUser('foo'), new DummyUser('bar'), new DummyUser('asd')
];
$card = Card::fromParams([
'notified' => false,
'id' => 123,
'title' => 'MyCardTitle'
]);
$card->setAssignedUsers([
new User($users[0])
]);
$this->cardMapper->expects($this->once())
->method('findBoardId')
->with(123)
->willReturn(234);
$board = Board::fromParams([
'id' => 123,
'title' => 'MyBoardTitle'
]);
$this->boardMapper->expects($this->once())
->method('find')
->with(234)
->willReturn($board);


$this->permissionService->expects($this->once())
->method('findUsers')
->with(234)
->willReturn($users);

$this->assignedUsersMapper->expects($this->exactly(2))
->method('isUserAssigned')
->willReturn(true);


$n1 = $this->createMock(INotification::class);
$n2 = $this->createMock(INotification::class);

$n1->expects($this->once())->method('setApp')->with('deck')->willReturn($n1);
$n1->expects($this->once())->method('setUser')->with('foo')->willReturn($n1);
$n1->expects($this->once())->method('setObject')->with('card', 123)->willReturn($n1);
$n1->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n1);
$n1->expects($this->once())->method('setDateTime')->willReturn($n1);

$n2->expects($this->once())->method('setApp')->with('deck')->willReturn($n2);
$n2->expects($this->once())->method('setUser')->with('bar')->willReturn($n2);
$n2->expects($this->once())->method('setObject')->with('card', 123)->willReturn($n2);
$n2->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n2);
$n2->expects($this->once())->method('setDateTime')->willReturn($n2);

$this->notificationManager->expects($this->at(0))
->method('createNotification')
->willReturn($n1);
$this->notificationManager->expects($this->at(1))
->method('notify')
->with($n1);
$this->notificationManager->expects($this->at(2))
->method('createNotification')
->willReturn($n2);
$this->notificationManager->expects($this->at(3))
->method('notify')
->with($n2);

$this->cardMapper->expects($this->once())
->method('markNotified')
->with($card);

$this->notificationHelper->sendCardDuedate($card);
}

public function testSendCardAssignedUser() {
$board = new Board();
$board->setId(123);