Files
nextcloud-workflow-deck-aut…/tests/Unit/Service/NotificationPolicyTest.php
T
Patrick Niebeling 578b235f08
Build package / unit-tests (push) Failing after 20s
Build package / xml-lint (push) Successful in 46s
Build package / php-lint (8.4) (push) Successful in 1m30s
Build package / php-lint (8.5) (push) Successful in 1m36s
Build package / package (push) Skipped
Notify board members about moved cards according to their Deck setting
Replaces the yes/no notify_email flag with notify_mode:
- off:   no mail
- owner: only the board owner, as before (migrated from notify_email=1)
- board: everyone with access to the board, filtered by their own Deck
         "Notifications" setting for it (board:<id>:notify-due: off /
         assigned / all), mirroring Deck's NotificationHelper rules

Recipients are resolved via PermissionService::findUsers() (owner, ACL,
groups and circles expanded), AssignmentMapper::isUserAssigned() and
IConfig, none of which reads Deck's frozen $userId. If they cannot be
resolved, no mail is sent rather than one to the wrong people.

Moved cards are collected over the whole run and each recipient gets a
single digest mail afterwards, in their own language.

Bumps to 35.2.0 so the migrations run.
2026-09-30 10:31:45 +02:00

57 lines
2.2 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'));
}
}