Skip to content

Commit

Permalink
fix: allow organisations without protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Jan 23, 2024
1 parent b70ca76 commit 72cec02
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
8 changes: 4 additions & 4 deletions app/Console/Commands/ProcessProtocolsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ private function handleExpiringProtocols(): void

$this->organisations
->filter(
fn (Organisation $organisation) => $organisation
fn (Organisation $organisation) => (bool) $organisation
->last_protocol_expires_at
?->isSameDay($checkDate) ?? true
?->isSameDay($checkDate)
)
->each(function (Organisation $organisation) {
$this->sendNotification(ExpiringProtocol::class, $organisation);
Expand All @@ -119,9 +119,9 @@ private function handleExpiredProtocols(): void

$this->organisations
->filter(
fn (Organisation $organisation) => $organisation
fn (Organisation $organisation) => (bool) $organisation
->last_protocol_expires_at
?->lte($checkDate) ?? true
?->lte($checkDate)
)
->each(function (Organisation $organisation) {
$organisation->setInactive();
Expand Down
38 changes: 33 additions & 5 deletions tests/Feature/ProtocolsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Console\Commands\ProcessProtocolsCommand;
use App\Enum\UserRole;
use App\Models\Document;
use App\Models\Organisation;
use App\Models\User;
use App\Notifications\ExpiredProtocol;
use App\Notifications\ExpiringProtocol;
Expand Down Expand Up @@ -35,6 +36,14 @@ protected function setUp(): void
->create();
}

protected function getPlatformAdmins(): Collection
{
return User::query()
->withoutGlobalScopes()
->role(UserRole::PLATFORM_ADMIN)
->get();
}

/** @test */
public function it_does_not_send_notifications_for_protocols_expiring_in_less_than_30_days(): void
{
Expand Down Expand Up @@ -190,11 +199,30 @@ public function it_sends_notifications_for_protocols_that_have_expired_in_the_pa
);
}

private function getPlatformAdmins(): Collection
/** @test */
public function it_does_not_send_notifications_for_organisations_without_protocols(): void
{
return User::query()
->withoutGlobalScopes()
->role(UserRole::PLATFORM_ADMIN)
->get();
$organisation = Organisation::factory()
->create();

$this->artisan(ProcessProtocolsCommand::class)
->assertSuccessful();

Notification::assertNotSentTo(
$organisation,
ExpiringProtocol::class
);

Notification::assertNotSentTo(
$organisation
->users
->where('role', UserRole::ORG_ADMIN),
ExpiringProtocol::class
);

Notification::assertNotSentTo(
$this->getPlatformAdmins(),
SummaryExpiringProtocols::class
);
}
}

0 comments on commit 72cec02

Please sign in to comment.