-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: changed thread pk type (#688)
- Loading branch information
Showing
5 changed files
with
163 additions
and
3 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
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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories\Discord; | ||
|
||
use App\Models\Discord\DiscordThread; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* Class DiscordThreadFactory. | ||
* | ||
* @method DiscordThread createOne($attributes = []) | ||
* @method DiscordThread makeOne($attributes = []) | ||
* | ||
* @extends Factory<DiscordThread> | ||
*/ | ||
class DiscordThreadFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var class-string<DiscordThread> | ||
*/ | ||
protected $model = DiscordThread::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition(): array | ||
{ | ||
return [ | ||
DiscordThread::ATTRIBUTE_NAME => fake()->words(3, true), | ||
DiscordThread::ATTRIBUTE_ID => fake()->words(3, true), | ||
]; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Feature\Jobs\Discord; | ||
|
||
use App\Constants\FeatureConstants; | ||
use App\Events\Discord\DiscordThread\DiscordThreadDeleted; | ||
use App\Events\Discord\DiscordThread\DiscordThreadUpdated; | ||
use App\Jobs\SendDiscordNotificationJob; | ||
use App\Models\Discord\DiscordThread; | ||
use App\Models\Wiki\Anime; | ||
use Illuminate\Support\Facades\Bus; | ||
use Illuminate\Support\Facades\Event; | ||
use Laravel\Pennant\Feature; | ||
use Tests\TestCase; | ||
|
||
/** | ||
* Class DiscordThreadTest. | ||
*/ | ||
class DiscordThreadTest extends TestCase | ||
{ | ||
/** | ||
* When a thread is deleted, a SendDiscordNotification job shall be dispatched. | ||
* | ||
* @return void | ||
*/ | ||
public function testThreadDeletedSendsDiscordNotification(): void | ||
{ | ||
$thread = DiscordThread::factory() | ||
->for(Anime::factory()) | ||
->createOne(); | ||
|
||
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); | ||
Bus::fake(SendDiscordNotificationJob::class); | ||
Event::fakeExcept(DiscordThreadDeleted::class); | ||
|
||
$thread->delete(); | ||
|
||
Bus::assertDispatched(SendDiscordNotificationJob::class); | ||
} | ||
|
||
/** | ||
* When a thread is updated, a SendDiscordNotification job shall be dispatched. | ||
* | ||
* @return void | ||
*/ | ||
public function testThreadUpdatedSendsDiscordNotification(): void | ||
{ | ||
$thread = DiscordThread::factory() | ||
->for(Anime::factory()) | ||
->createOne(); | ||
|
||
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); | ||
Bus::fake(SendDiscordNotificationJob::class); | ||
Event::fakeExcept(DiscordThreadUpdated::class); | ||
|
||
$changes = DiscordThread::factory() | ||
->for(Anime::factory()) | ||
->makeOne(); | ||
|
||
$thread->fill($changes->getAttributes()); | ||
$thread->save(); | ||
|
||
Bus::assertDispatched(SendDiscordNotificationJob::class); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use App\Models\Discord\DiscordThread; | ||
use App\Models\Wiki\Anime; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Tests\TestCase; | ||
|
||
/** | ||
* Class DiscordThreadTest. | ||
*/ | ||
class DiscordThreadTest extends TestCase | ||
{ | ||
use WithFaker; | ||
|
||
/** | ||
* Thread shall be nameable. | ||
* | ||
* @return void | ||
*/ | ||
public function testNameable(): void | ||
{ | ||
$thread = DiscordThread::factory() | ||
->for(Anime::factory()) | ||
->createOne(); | ||
|
||
static::assertIsString($thread->getName()); | ||
} | ||
|
||
/** | ||
* Thread shall have subtitle. | ||
* | ||
* @return void | ||
*/ | ||
public function testHasSubtitle(): void | ||
{ | ||
$thread = DiscordThread::factory() | ||
->for(Anime::factory()) | ||
->createOne(); | ||
|
||
static::assertIsString($thread->getSubtitle()); | ||
} | ||
} |