Skip to content

Commit 4b21461

Browse files
committed
test(Consumer): update ConsumerTest for bulkReceive email and notification fixes
- Inject IConfig mock into Consumer constructor (6th arg added by fix) - Update testBulkReceiveNoMailWhenSettingDisabled: notification must not fire when isDefaultEnabledNotification() returns false (old test encoded the null !== false bug) - Update testBulkReceiveMultipleUsersWithMixedSettings: only users with an explicit true DB entry get a notification; absent entries now fall back to isDefaultEnabledNotification() instead of always sending - Update testBulkReceiveWithISetting: ISetting (non-ActivitySettings) now yields defaultPushEnabled=false, so no notification is sent - Add testBulkReceiveNoMailWhenAdminEmailDisabled: verifies that when the admin sets enable_email=no, getValuesByUsers is never called and no mail is queued even if the activity type has mail enabled by default AI-Assisted-By: claude-sonnet-4-6
1 parent bb20dc9 commit 4b21461

1 file changed

Lines changed: 53 additions & 8 deletions

File tree

tests/ConsumerTest.php

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use OCP\Activity\IManager;
3434
use OCP\Activity\ISetting;
3535
use OCP\Config\IUserConfig;
36+
use OCP\IConfig;
3637
use OCP\IDBConnection;
3738
use OCP\IL10N;
3839
use OCP\L10N\IFactory;
@@ -53,6 +54,7 @@ class ConsumerTest extends TestCase {
5354
protected NotificationGenerator&MockObject $notificationGenerator;
5455
protected UserSettings $userSettings;
5556
private IUserConfig&MockObject $userConfig;
57+
private IConfig&MockObject $config;
5658
private IEvent $event;
5759
private Consumer $consumer;
5860

@@ -70,6 +72,8 @@ protected function setUp(): void {
7072
$this->notificationGenerator = $this->createMock(NotificationGenerator::class);
7173
$this->l10nFactory = $this->createMock(IFactory::class);
7274
$this->userConfig = $this->createMock(IUserConfig::class);
75+
$this->config = $this->createMock(IConfig::class);
76+
$this->config->method('getAppValue')->willReturn('yes');
7377

7478
$this->data->method('send')
7579
->willReturn(1);
@@ -95,6 +99,7 @@ protected function setUp(): void {
9599
$this->userSettings,
96100
$this->notificationGenerator,
97101
$this->userConfig,
102+
$this->config,
98103
);
99104

100105
$this->event = Server::get(IManager::class)->generateEvent();
@@ -143,6 +148,7 @@ public function testReceiveStream(string $type, string $author, string $affected
143148
$this->userSettings,
144149
$this->notificationGenerator,
145150
$this->userConfig,
151+
$this->config,
146152
);
147153
$event = Server::get(IManager::class)->generateEvent();
148154
$event->setApp('test')
@@ -322,9 +328,7 @@ public function testBulkReceiveNoMailWhenSettingDisabled(): void {
322328

323329
$this->data->expects($this->never())
324330
->method('storeMail');
325-
// Notification is still sent because $notificationSetting defaults to null
326-
// and null !== false, so the default is to send notifications
327-
$this->notificationGenerator->expects($this->once())
331+
$this->notificationGenerator->expects($this->never())
328332
->method('sendNotificationForEvent');
329333

330334
$this->consumer->bulkReceive($this->event, ['affectedUser'], $settings);
@@ -434,8 +438,8 @@ public function testBulkReceiveMultipleUsersWithMixedSettings(): void {
434438
return [];
435439
});
436440

437-
// user1 and user2 get notifications (user2 has null setting which defaults to send), author is skipped
438-
$this->notificationGenerator->expects($this->exactly(2))
441+
// only user1 has an explicit notification=true in DB; user2 has no entry so falls back to isDefaultEnabledNotification()=false
442+
$this->notificationGenerator->expects($this->once())
439443
->method('sendNotificationForEvent');
440444
// user2 gets email, author is skipped
441445
$this->data->expects($this->once())
@@ -445,6 +449,48 @@ public function testBulkReceiveMultipleUsersWithMixedSettings(): void {
445449
$this->consumer->bulkReceive($this->event, ['user1', 'user2', 'author'], $settings);
446450
}
447451

452+
public function testBulkReceiveNoMailWhenAdminEmailDisabled(): void {
453+
$time = time();
454+
$this->event->setApp('activity')
455+
->setType('type')
456+
->setAuthor('author')
457+
->setTimestamp($time)
458+
->setSubject('subject', ['subjectParam1'])
459+
->setMessage('message', ['messageParam1'])
460+
->setObject('', 0, 'file')
461+
->setLink('link');
462+
463+
$config = $this->createMock(IConfig::class);
464+
$config->method('getAppValue')->willReturn('no');
465+
466+
$consumer = new Consumer(
467+
$this->data,
468+
$this->activityManager,
469+
$this->userSettings,
470+
$this->notificationGenerator,
471+
$this->userConfig,
472+
$config,
473+
);
474+
475+
$settings = $this->createMock(ActivitySettings::class);
476+
$settings->method('canChangeMail')->willReturn(true);
477+
$settings->method('isDefaultEnabledMail')->willReturn(true);
478+
$settings->method('canChangeNotification')->willReturn(false);
479+
$settings->method('isDefaultEnabledNotification')->willReturn(false);
480+
481+
$this->data->expects($this->once())
482+
->method('bulkSend')
483+
->willReturn([1 => 'affectedUser']);
484+
485+
$this->userConfig->expects($this->never())
486+
->method('getValuesByUsers');
487+
488+
$this->data->expects($this->never())
489+
->method('storeMail');
490+
491+
$consumer->bulkReceive($this->event, ['affectedUser'], $settings);
492+
}
493+
448494
public function testBulkReceiveWithISetting(): void {
449495
$this->event->setApp('activity')
450496
->setType('type')
@@ -463,9 +509,8 @@ public function testBulkReceiveWithISetting(): void {
463509
->method('bulkSend')
464510
->willReturn([1 => 'affectedUser']);
465511

466-
// Notification is still sent because $notificationSetting defaults to null (not false)
467-
// when ISetting is used (canChangeNotification not available), and null !== false
468-
$this->notificationGenerator->expects($this->once())
512+
// ISetting is not ActivitySettings so $defaultPushEnabled is false — no notification sent
513+
$this->notificationGenerator->expects($this->never())
469514
->method('sendNotificationForEvent');
470515
$this->data->expects($this->never())
471516
->method('storeMail');

0 commit comments

Comments
 (0)