-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
4cc2f52
commit 8e3e751
Showing
4 changed files
with
131 additions
and
18 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
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,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Unit; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Tests\TestCase; | ||
use Toby\Eloquent\Models\User; | ||
use Toby\Infrastructure\Slack\Rules\SlackUserExistsRule; | ||
|
||
class SlackUserExistsRuleTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
protected SlackUserExistsRule $rule; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->rule = $this->app->make(SlackUserExistsRule::class); | ||
} | ||
|
||
public function testItPassesIfSlackUserExists(): void | ||
{ | ||
$slackId = "U03AZBA3RKL"; | ||
$user = User::factory()->hasProfile(["slack_id" => $slackId])->create(); | ||
|
||
$fail = false; | ||
|
||
$this->rule->validate("user", $slackId, function () use (&$fail): void { | ||
$fail = true; | ||
}); | ||
|
||
$this->assertFalse($fail, "User $user->name does not exist in toby"); | ||
} | ||
|
||
public function testItFailsIfSlackUserDoesNotExist(): void | ||
{ | ||
$user = User::factory()->hasProfile()->create(); | ||
|
||
$invalidValues = [ | ||
"U03AZBA3RKL", | ||
null, | ||
]; | ||
|
||
foreach ($invalidValues as $value) { | ||
$fail = false; | ||
$this->rule->validate("user", null, function () use (&$fail): void { | ||
$fail = true; | ||
}); | ||
$this->assertTrue($fail, "User $user->name does not exist in toby"); | ||
} | ||
} | ||
} |
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,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Unit; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Carbon; | ||
use Tests\TestCase; | ||
use Tests\Traits\InteractsWithYearPeriods; | ||
use Toby\Infrastructure\Http\Rules\YearPeriodExists; | ||
|
||
class YearPeriodExistsRuleTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
use InteractsWithYearPeriods; | ||
|
||
protected YearPeriodExists $rule; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->rule = $this->app->make(YearPeriodExists::class); | ||
} | ||
|
||
public function testItPassesIfYearPeriodExists(): void | ||
{ | ||
$now = Carbon::now(); | ||
Carbon::setTestNow($now); | ||
|
||
$this->createCurrentYearPeriod(); | ||
|
||
$fail = false; | ||
$value = $now->year; | ||
|
||
$this->rule->validate("year", $value, function () use (&$fail): void { | ||
$fail = true; | ||
}); | ||
$this->assertFalse($fail, "The year period for given year does not exist."); | ||
} | ||
|
||
public function testItFailsIfYearPeriodDoesNotExist(): void | ||
{ | ||
$now = Carbon::now(); | ||
Carbon::setTestNow($now); | ||
|
||
$invalidValues = [ | ||
$now->year, | ||
null, | ||
]; | ||
|
||
foreach ($invalidValues as $value) { | ||
$fail = false; | ||
$this->rule->validate("year", $value, static function () use (&$fail): void { | ||
$fail = true; | ||
}); | ||
$this->assertTrue($fail, "The year period for given year does not exist."); | ||
} | ||
} | ||
} |