Skip to content

Commit

Permalink
fix: tests related to new discord funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
blt950 committed Jan 12, 2025
1 parent 63c1d14 commit a102a30
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/Helpers/EventHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ enum EventHelper: string
case MONTH = 'month';
case YEAR = 'year';

/**
* Get the interval labels for the event types.
*/
public static function labels(): array
{
return [
Expand All @@ -23,6 +26,10 @@ public static function labels(): array
];
}

/**
* Get code to mention a Discord role.
* @codeCoverageIgnore
*/
public static function discordMention(): string
{
if (config('discord.mention_role') === null) {
Expand All @@ -32,9 +39,17 @@ public static function discordMention(): string
return '<@&'.config('discord.mention_role').'>';
}

/**
* Post a message to Discord.
* @codeCoverageIgnore
*/
public static function discordPost(string $text, string $title, string $content, ?string $image, Carbon $timestamp, ?Carbon $expireMessageAt = null): bool
{
$webhookUrl = config('discord.webhook');
if($webhookUrl === null) {
return false;
}

$payload = [
'content' => $text,
'embeds' => [
Expand Down Expand Up @@ -70,9 +85,17 @@ public static function discordPost(string $text, string $title, string $content,
return $messageId !== null;
}

/**
* Delete a message from Discord.
* @codeCoverageIgnore
*/
public static function discordDelete(int $messageId): void
{
$webhookUrl = config('discord.webhook');
if($webhookUrl === null) {
return;
}

Http::delete($webhookUrl."/messages/{$messageId}");
}
}
1 change: 1 addition & 0 deletions tests/Feature/Models/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function test_normal_event_can_be_created(): void
'recurrence_unit' => null,
'recurrence_end_date' => null,
'image' => $image,
'published' => true,
]);

$response->assertRedirect(route('events.index'));
Expand Down

0 comments on commit a102a30

Please sign in to comment.