-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from ECFMP/approaching-flow-measure-messages
feat: notified flow measure messages
- Loading branch information
Showing
13 changed files
with
541 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app/Discord/FlowMeasure/Message/FlowMeasureActivatedWithoutRecipientsMessage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace App\Discord\FlowMeasure\Message; | ||
|
||
use App\Discord\FlowMeasure\Description\EventName; | ||
use App\Discord\FlowMeasure\Field\ArrivalAirports; | ||
use App\Discord\FlowMeasure\Field\DepartureAirports; | ||
use App\Discord\FlowMeasure\Field\EndTime; | ||
use App\Discord\FlowMeasure\Field\Filters\AdditionalFilterParser; | ||
use App\Discord\FlowMeasure\Field\Reason; | ||
use App\Discord\FlowMeasure\Field\Restriction; | ||
use App\Discord\FlowMeasure\Field\StartTime; | ||
use App\Discord\FlowMeasure\Title\IdentifierAndStatus; | ||
use App\Discord\Message\Embed\BlankField; | ||
use App\Discord\Message\Embed\Colour; | ||
use App\Discord\Message\Embed\Embed; | ||
use App\Discord\Message\Embed\EmbedCollection; | ||
use App\Discord\Message\Embed\Field; | ||
use App\Discord\Message\Embed\FieldProviderInterface; | ||
use App\Discord\Message\MessageInterface; | ||
use App\Models\FlowMeasure; | ||
|
||
class FlowMeasureActivatedWithoutRecipientsMessage implements MessageInterface | ||
{ | ||
private readonly FlowMeasure $measure; | ||
|
||
public function __construct(FlowMeasure $measure) | ||
{ | ||
$this->measure = $measure; | ||
} | ||
|
||
public function content(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function embeds(): EmbedCollection | ||
{ | ||
return (new EmbedCollection())->add( | ||
Embed::make()->withColour(Colour::ACTIVATED) | ||
->withTitle(new IdentifierAndStatus($this->measure)) | ||
->withDescription(new EventName($this->measure)) | ||
->withField(Field::makeInline(new Restriction($this->measure))) | ||
->withField(Field::makeInline(new StartTime($this->measure))) | ||
->withField(Field::makeInline(new EndTime($this->measure))) | ||
->withField(Field::makeInline(new DepartureAirports($this->measure))) | ||
->withField(Field::makeInline(new ArrivalAirports($this->measure))) | ||
->withField(Field::makeInline(BlankField::make())) | ||
->withFields( | ||
AdditionalFilterParser::parseAdditionalFilters($this->measure)->map( | ||
fn(FieldProviderInterface $provider) => Field::make($provider) | ||
) | ||
) | ||
->withField( | ||
Field::make(new Reason($this->measure)) | ||
) | ||
); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
app/Discord/FlowMeasure/Message/FlowMeasureNotifiedMessage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace App\Discord\FlowMeasure\Message; | ||
|
||
use App\Discord\FlowMeasure\Description\EventNameAndInterestedParties; | ||
use App\Discord\FlowMeasure\Field\ArrivalAirports; | ||
use App\Discord\FlowMeasure\Field\DepartureAirports; | ||
use App\Discord\FlowMeasure\Field\EndTime; | ||
use App\Discord\FlowMeasure\Field\Filters\AdditionalFilterParser; | ||
use App\Discord\FlowMeasure\Field\Reason; | ||
use App\Discord\FlowMeasure\Field\Restriction; | ||
use App\Discord\FlowMeasure\Field\StartTime; | ||
use App\Discord\FlowMeasure\Title\IdentifierAndStatus; | ||
use App\Discord\Message\Embed\BlankField; | ||
use App\Discord\Message\Embed\Colour; | ||
use App\Discord\Message\Embed\Embed; | ||
use App\Discord\Message\Embed\EmbedCollection; | ||
use App\Discord\Message\Embed\Field; | ||
use App\Discord\Message\Embed\FieldProviderInterface; | ||
use App\Discord\Message\MessageInterface; | ||
use App\Models\FlowMeasure; | ||
|
||
class FlowMeasureNotifiedMessage implements MessageInterface | ||
{ | ||
private readonly FlowMeasure $measure; | ||
|
||
public function __construct(FlowMeasure $measure) | ||
{ | ||
$this->measure = $measure; | ||
} | ||
|
||
public function content(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function embeds(): EmbedCollection | ||
{ | ||
return (new EmbedCollection())->add( | ||
Embed::make()->withColour(Colour::NOTIFIED) | ||
->withTitle(new IdentifierAndStatus($this->measure)) | ||
->withDescription(new EventNameAndInterestedParties($this->measure)) | ||
->withField(Field::makeInline(new Restriction($this->measure))) | ||
->withField(Field::makeInline(new StartTime($this->measure))) | ||
->withField(Field::makeInline(new EndTime($this->measure))) | ||
->withField(Field::makeInline(new DepartureAirports($this->measure))) | ||
->withField(Field::makeInline(new ArrivalAirports($this->measure))) | ||
->withField(Field::makeInline(BlankField::make())) | ||
->withFields( | ||
AdditionalFilterParser::parseAdditionalFilters($this->measure)->map( | ||
fn(FieldProviderInterface $provider) => Field::make($provider) | ||
) | ||
) | ||
->withField( | ||
Field::make(new Reason($this->measure)) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
tests/Discord/FlowMeasure/Message/FlowMeasureActivatedWithoutRecipientsMessageTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Tests\Discord\FlowMeasure\Message; | ||
|
||
use App\Discord\FlowMeasure\Message\FlowMeasureActivatedWithoutRecipientsMessage; | ||
use App\Discord\Message\Embed\Colour; | ||
use App\Models\DiscordTag; | ||
use App\Models\FlightInformationRegion; | ||
use App\Models\FlowMeasure; | ||
use Carbon\Carbon; | ||
use Tests\TestCase; | ||
|
||
class FlowMeasureActivatedWithoutRecipientsMessageTest extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
Carbon::setTestNow(Carbon::parse('2022-05-22T14:59:23Z')); | ||
} | ||
|
||
public function testItHasNoContent() | ||
{ | ||
$measure = FlowMeasure::factory()->create(); | ||
|
||
$this->assertEquals( | ||
'', | ||
(new FlowMeasureActivatedWithoutRecipientsMessage($measure))->content() | ||
); | ||
} | ||
|
||
public function testItHasEmbeds() | ||
{ | ||
$measure = FlowMeasure::factory() | ||
->withTimes(Carbon::parse('2022-05-22T14:54:23Z'), Carbon::parse('2022-05-22T16:37:22Z')) | ||
->withEvent() | ||
->withAdditionalFilter(['type' => 'level_below', 'value' => 220])->create(); | ||
|
||
$fir = FlightInformationRegion::factory()->has(DiscordTag::factory()->count(2))->create(); | ||
$measure->notifiedFlightInformationRegions()->sync([$fir->id]); | ||
|
||
$this->assertEquals( | ||
[ | ||
[ | ||
'title' => $measure->identifier . ' - ' . 'Active', | ||
'color' => Colour::ACTIVATED->value, | ||
'description' => $measure->event->name, | ||
'fields' => [ | ||
[ | ||
'name' => 'Minimum Departure Interval [MDI]', | ||
'value' => '2 Minutes', | ||
'inline' => true, | ||
], | ||
[ | ||
'name' => 'Start Time', | ||
'value' => '22/05 1454Z', | ||
'inline' => true, | ||
], | ||
[ | ||
'name' => 'End Time', | ||
'value' => '1637Z', | ||
'inline' => true, | ||
], | ||
[ | ||
'name' => 'Departure Airports', | ||
'value' => 'EG**', | ||
'inline' => true, | ||
], | ||
[ | ||
'name' => 'Arrival Airports', | ||
'value' => 'EHAM', | ||
'inline' => true, | ||
], | ||
[ | ||
'name' => "\u{200b}", | ||
'value' => "\u{200b}", | ||
'inline' => true, | ||
], | ||
[ | ||
'name' => 'Level at or Below', | ||
'value' => '220', | ||
'inline' => false, | ||
], | ||
[ | ||
'name' => 'Reason', | ||
'value' => $measure->reason, | ||
'inline' => false, | ||
], | ||
], | ||
], | ||
], | ||
(new FlowMeasureActivatedWithoutRecipientsMessage($measure))->embeds()->toArray() | ||
); | ||
} | ||
} |
Oops, something went wrong.