Build package / xml-lint (push) Successful in 33s
Build package / php-lint (8.5) (push) Successful in 1m48s
Build package / php-lint (8.4) (push) Successful in 1m50s
Build package / unit-tests (push) Successful in 1m52s
Build package / package (push) Successful in 1m38s
Each workflow now has a notify channel (mail, notification or both) next to its recipient mode. Notifications go out per card through OCP\Notification\IManager, so they show up in the bell and as push on the mobile and desktop clients. Without the notifications app nothing is sent. The one-off "workflow disabled" notice is sent as a notification as well. Existing workflows keep mail (migration Version1004). Bumps to 35.3.0 so the migration runs.
83 lines
3.3 KiB
PHP
83 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\WorkflowDeckAutomation\Tests\Unit\Service;
|
|
|
|
use OCA\WorkflowDeckAutomation\Service\NotificationPolicy;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class NotificationPolicyTest extends TestCase {
|
|
public function testOffNeverNotifies(): void {
|
|
$this->assertFalse(NotificationPolicy::shouldNotify('off', false, true));
|
|
// Not even the owner of an unshared board — "off" is "off" in Deck too.
|
|
$this->assertFalse(NotificationPolicy::shouldNotify('off', true, true));
|
|
}
|
|
|
|
public function testAllAlwaysNotifies(): void {
|
|
$this->assertTrue(NotificationPolicy::shouldNotify('all', false, false));
|
|
$this->assertTrue(NotificationPolicy::shouldNotify('all', true, false));
|
|
}
|
|
|
|
public function testAssignedNotifiesOnlyAssignedUsers(): void {
|
|
$this->assertTrue(NotificationPolicy::shouldNotify('assigned', false, true));
|
|
$this->assertFalse(NotificationPolicy::shouldNotify('assigned', false, false));
|
|
}
|
|
|
|
public function testOwnerOfUnsharedBoardIsNotifiedWithAssigned(): void {
|
|
$this->assertTrue(NotificationPolicy::shouldNotify('assigned', true, false));
|
|
}
|
|
|
|
public function testUnknownSettingFallsBackToDeckDefault(): void {
|
|
$this->assertTrue(NotificationPolicy::shouldNotify('', false, true));
|
|
$this->assertFalse(NotificationPolicy::shouldNotify('bogus', false, false));
|
|
$this->assertTrue(NotificationPolicy::shouldNotify('bogus', true, false));
|
|
}
|
|
|
|
public function testAssignmentIsOnlyLookedUpWhenItMatters(): void {
|
|
$lookup = function (): bool {
|
|
$this->fail('assignment lookup must not run');
|
|
};
|
|
$this->assertFalse(NotificationPolicy::shouldNotify('off', false, $lookup));
|
|
$this->assertTrue(NotificationPolicy::shouldNotify('all', false, $lookup));
|
|
$this->assertTrue(NotificationPolicy::shouldNotify('assigned', true, $lookup));
|
|
|
|
$this->assertTrue(NotificationPolicy::shouldNotify('assigned', false, static fn (): bool => true));
|
|
$this->assertFalse(NotificationPolicy::shouldNotify('assigned', false, static fn (): bool => false));
|
|
}
|
|
|
|
public function testModes(): void {
|
|
foreach (['off', 'owner', 'board'] as $mode) {
|
|
$this->assertTrue(NotificationPolicy::isValidMode($mode));
|
|
}
|
|
$this->assertFalse(NotificationPolicy::isValidMode(''));
|
|
$this->assertFalse(NotificationPolicy::isValidMode('all'));
|
|
}
|
|
|
|
public function testChannels(): void {
|
|
foreach (['mail', 'notification', 'both'] as $channel) {
|
|
$this->assertTrue(NotificationPolicy::isValidChannel($channel));
|
|
}
|
|
$this->assertFalse(NotificationPolicy::isValidChannel(''));
|
|
$this->assertFalse(NotificationPolicy::isValidChannel('push'));
|
|
}
|
|
|
|
public function testChannelDecidesMailAndNotification(): void {
|
|
$this->assertTrue(NotificationPolicy::sendsMail('mail'));
|
|
$this->assertFalse(NotificationPolicy::sendsNotification('mail'));
|
|
|
|
$this->assertFalse(NotificationPolicy::sendsMail('notification'));
|
|
$this->assertTrue(NotificationPolicy::sendsNotification('notification'));
|
|
|
|
$this->assertTrue(NotificationPolicy::sendsMail('both'));
|
|
$this->assertTrue(NotificationPolicy::sendsNotification('both'));
|
|
}
|
|
|
|
public function testUnknownChannelFallsBackToMail(): void {
|
|
$this->assertTrue(NotificationPolicy::sendsMail(''));
|
|
$this->assertFalse(NotificationPolicy::sendsNotification(''));
|
|
$this->assertTrue(NotificationPolicy::sendsMail('bogus'));
|
|
$this->assertFalse(NotificationPolicy::sendsNotification('bogus'));
|
|
}
|
|
}
|