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

refactor: remove old webhook code #446

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 2 additions & 5 deletions app/Discord/FlowMeasure/Webhook/WebhookMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Discord\FlowMeasure\Webhook;

use App\Discord\FlowMeasure\Webhook\Filter\FilterInterface;
use App\Discord\Webhook\EcfmpWebhook;
use App\Discord\Webhook\WebhookInterface;
use App\Models\FlightInformationRegion;
use App\Models\FlowMeasure;
Expand All @@ -12,17 +11,15 @@
class WebhookMapper implements MapperInterface
{
private readonly FilterInterface $filter;
private readonly EcfmpWebhook $ecfmpWebhook;

public function __construct(FilterInterface $filter, EcfmpWebhook $ecfmpWebhook)
public function __construct(FilterInterface $filter)
{
$this->filter = $filter;
$this->ecfmpWebhook = $ecfmpWebhook;
}

public function mapToWebhooks(FlowMeasure $measure): Collection
{
return Collection::make([$this->ecfmpWebhook])
return Collection::make()
->merge(
$measure->notifiedFlightInformationRegions->map(
fn (FlightInformationRegion $fir) => $fir->divisionDiscordWebhooks
Expand Down
21 changes: 0 additions & 21 deletions app/Discord/Webhook/EcfmpWebhook.php

This file was deleted.

2 changes: 0 additions & 2 deletions app/Providers/DiscordServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use App\Discord\FlowMeasure\Webhook\Filter\WithdrawnWebhookFilter;
use App\Discord\FlowMeasure\Webhook\WebhookMapper;
use App\Discord\Message\Sender\DivisionWebhookSender;
use App\Discord\Webhook\EcfmpWebhook;
use App\Repository\FlowMeasureNotification\ActiveRepository;
use App\Repository\FlowMeasureNotification\ExpiredRepository;
use App\Repository\FlowMeasureNotification\NotifiedRepository;
Expand All @@ -43,7 +42,6 @@ public function register(): void
$this->app->singleton(DiscordWebhookInterface::class, function () {
return new DiscordWebhookSender();
});
$this->app->singleton(EcfmpWebhook::class);
$this->app->singleton(
DivisionWebhookSender::class,
fn () => new DivisionWebhookSender(
Expand Down
133 changes: 42 additions & 91 deletions tests/Discord/FlowMeasure/Helper/NotificationReissuerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Tests\Discord\FlowMeasure\Helper;

use App\Discord\FlowMeasure\Helper\NotificationReissuer;
use App\Discord\Webhook\EcfmpWebhook;
use App\Enums\DiscordNotificationType as DiscordNotificationTypeEnum;
use App\Models\DivisionDiscordNotification;
use App\Models\DiscordNotificationType;
Expand All @@ -14,11 +13,14 @@
class NotificationReissuerTest extends TestCase
{
private readonly FlowMeasure $flowMeasure;
private readonly DivisionDiscordWebhook $webhook;

public function setUp(): void
{
parent::setUp();
$this->flowMeasure = FlowMeasure::factory()->create();
$this->webhook = DivisionDiscordWebhook::factory()
->create();
}

public function testItHasAType()
Expand All @@ -29,7 +31,7 @@ public function testItHasAType()
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_NOTIFIED,
new EcfmpWebhook()
$this->webhook
)
)->type()
);
Expand All @@ -43,15 +45,17 @@ public function testItHasAFlowMeasure()
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_NOTIFIED,
new EcfmpWebhook()
$this->webhook
)
)->measure()
);
}

public function testItsAReissueIfItsNotifiedAndTheIdentifierHasChanged()
{
$previousNotification = DivisionDiscordNotification::factory()->create();
$previousNotification = DivisionDiscordNotification::factory()
->toDivisionWebhook($this->webhook)
->create();
$this->flowMeasure->divisionDiscordNotifications()->sync(
[
$previousNotification->id => [
Expand All @@ -68,15 +72,17 @@ public function testItsAReissueIfItsNotifiedAndTheIdentifierHasChanged()
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_NOTIFIED,
new EcfmpWebhook()
$this->webhook
)
)->isReissuedNotification()
);
}

public function testItsAReissueIfItsActivatedAndTheIdentifierHasChanged()
{
$previousNotification = DivisionDiscordNotification::factory()->create();
$previousNotification = DivisionDiscordNotification::factory()
->toDivisionWebhook($this->webhook)
->create();
$this->flowMeasure->divisionDiscordNotifications()->sync(
[
$previousNotification->id => [
Expand All @@ -93,15 +99,17 @@ public function testItsAReissueIfItsActivatedAndTheIdentifierHasChanged()
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED,
new EcfmpWebhook()
$this->webhook
)
)->isReissuedNotification()
);
}

public function testItsAReissueIfItWasNotifiedAndTheIdentifierHasChangedForActivation()
{
$previousNotification = DivisionDiscordNotification::factory()->create();
$previousNotification = DivisionDiscordNotification::factory()
->toDivisionWebhook($this->webhook)
->create();
$this->flowMeasure->divisionDiscordNotifications()->sync(
[
$previousNotification->id => [
Expand All @@ -118,45 +126,7 @@ public function testItsAReissueIfItWasNotifiedAndTheIdentifierHasChangedForActiv
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED,
new EcfmpWebhook()
)
)->isReissuedNotification()
);
}

public function testItsAReissueIfItsNotifiedOnAEcfmpWebhook()
{
$previousNotificationEcfmp = DivisionDiscordNotification::factory()
->create();

$divisionWebhook = DivisionDiscordWebhook::factory()->create();
$previousDivisionNotification = DivisionDiscordNotification::factory()
->toDivisionWebhook($divisionWebhook)
->create();

$this->flowMeasure->divisionDiscordNotifications()->sync(
[
$previousNotificationEcfmp->id => [
'discord_notification_type_id' => DiscordNotificationType::idFromEnum(
DiscordNotificationTypeEnum::FLOW_MEASURE_NOTIFIED
),
'notified_as' => 'notthis',
],
$previousDivisionNotification->id => [
'discord_notification_type_id' => DiscordNotificationType::idFromEnum(
DiscordNotificationTypeEnum::FLOW_MEASURE_NOTIFIED
),
'notified_as' => $this->flowMeasure->identifier,
],
]
);

$this->assertTrue(
(
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_NOTIFIED,
new EcfmpWebhook()
$this->webhook
)
)->isReissuedNotification()
);
Expand All @@ -169,9 +139,8 @@ public function testItsAReissueIfItsNotifiedOnADifferentDivisionWebhook()
->toDivisionWebhook($otherDivisionWebhook)
->create();

$divisionWebhook = DivisionDiscordWebhook::factory()->create();
$previousDivisionNotification = DivisionDiscordNotification::factory()
->toDivisionWebhook($divisionWebhook)
->toDivisionWebhook($this->webhook)
->create();

$this->flowMeasure->divisionDiscordNotifications()->sync(
Expand All @@ -196,7 +165,7 @@ public function testItsAReissueIfItsNotifiedOnADifferentDivisionWebhook()
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_NOTIFIED,
$divisionWebhook
$this->webhook
)
)->isReissuedNotification()
);
Expand All @@ -209,9 +178,8 @@ public function testItsAReissueIfItsActivatedOnADifferentDivisionWebhook()
->toDivisionWebhook($otherDivisionWebhook)
->create();

$divisionWebhook = DivisionDiscordWebhook::factory()->create();
$previousDivisionNotification = DivisionDiscordNotification::factory()
->toDivisionWebhook($divisionWebhook)
->toDivisionWebhook($this->webhook)
->create();

$this->flowMeasure->divisionDiscordNotifications()->sync(
Expand All @@ -236,42 +204,17 @@ public function testItsAReissueIfItsActivatedOnADifferentDivisionWebhook()
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED,
$divisionWebhook
$this->webhook
)
)->isReissuedNotification()
);
}

public function testItsAReissueIfItsActivatedOnAEcfmpWebhook()
public function testItIsNotAReissueIfItsNotifiedAndTheIdentifierHasNotChanged()
{
$previousNotification = DivisionDiscordNotification::factory()
->toDivisionWebhook($this->webhook)
->create();

$this->flowMeasure->divisionDiscordNotifications()->sync(
[
$previousNotification->id => [
'discord_notification_type_id' => DiscordNotificationType::idFromEnum(
DiscordNotificationTypeEnum::FLOW_MEASURE_NOTIFIED
),
'notified_as' => 'nothis',
],
]
);

$this->assertTrue(
(
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_NOTIFIED,
new EcfmpWebhook()
)
)->isReissuedNotification()
);
}

public function testItIsNotAReissueIfItsNotifiedAndTheIdentifierHasNotChanged()
{
$previousNotification = DivisionDiscordNotification::factory()->create();
$this->flowMeasure->divisionDiscordNotifications()->sync(
[
$previousNotification->id => [
Expand All @@ -288,15 +231,17 @@ public function testItIsNotAReissueIfItsNotifiedAndTheIdentifierHasNotChanged()
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_NOTIFIED,
new EcfmpWebhook()
$this->webhook
)
)->isReissuedNotification()
);
}

public function testItIsNotAReissueIfItsActivatedAndTheIdentifierHasNotChanged()
{
$previousNotification = DivisionDiscordNotification::factory()->create();
$previousNotification = DivisionDiscordNotification::factory()
->toDivisionWebhook($this->webhook)
->create();
$this->flowMeasure->divisionDiscordNotifications()->sync(
[
$previousNotification->id => [
Expand All @@ -313,15 +258,17 @@ public function testItIsNotAReissueIfItsActivatedAndTheIdentifierHasNotChanged()
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED,
new EcfmpWebhook()
$this->webhook
)
)->isReissuedNotification()
);
}

public function testItIsNotAReissueIfItsNotifiedAndThenActivatedTheIdentifierHasNotChanged()
{
$previousNotification = DivisionDiscordNotification::factory()->create();
$previousNotification = DivisionDiscordNotification::factory()
->toDivisionWebhook($this->webhook)
->create();
$this->flowMeasure->divisionDiscordNotifications()->sync(
[
$previousNotification->id => [
Expand All @@ -338,7 +285,7 @@ public function testItIsNotAReissueIfItsNotifiedAndThenActivatedTheIdentifierHas
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED,
new EcfmpWebhook()
$this->webhook
)
)->isReissuedNotification()
);
Expand All @@ -351,7 +298,7 @@ public function testItIsNotAReissueIfItsNotifiedAndNeverBeenNotified()
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_NOTIFIED,
new EcfmpWebhook()
$this->webhook
)
)->isReissuedNotification()
);
Expand All @@ -364,15 +311,17 @@ public function testItIsNotAReissueIfItsNotifiedAndNeverBeenActivated()
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED,
new EcfmpWebhook()
$this->webhook
)
)->isReissuedNotification()
);
}

public function testItIsNotAReissueIfItsWithdrawn()
{
$previousNotification = DivisionDiscordNotification::factory()->create();
$previousNotification = DivisionDiscordNotification::factory()
->toDivisionWebhook($this->webhook)
->create();
$this->flowMeasure->divisionDiscordNotifications()->sync(
[
$previousNotification->id => [
Expand All @@ -389,15 +338,17 @@ public function testItIsNotAReissueIfItsWithdrawn()
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_WITHDRAWN,
new EcfmpWebhook()
$this->webhook
)
)->isReissuedNotification()
);
}

public function testItIsNotAReissueIfItsExpired()
{
$previousNotification = DivisionDiscordNotification::factory()->create();
$previousNotification = DivisionDiscordNotification::factory()
->toDivisionWebhook($this->webhook)
->create();
$this->flowMeasure->divisionDiscordNotifications()->sync(
[
$previousNotification->id => [
Expand All @@ -414,7 +365,7 @@ public function testItIsNotAReissueIfItsExpired()
new NotificationReissuer(
$this->flowMeasure,
DiscordNotificationTypeEnum::FLOW_MEASURE_EXPIRED,
new EcfmpWebhook()
$this->webhook
)
)->isReissuedNotification()
);
Expand Down
Loading