-
-
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.
Allow to customize how invite codes are generated
- Loading branch information
1 parent
7a71ecf
commit 2478b21
Showing
4 changed files
with
80 additions
and
6 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
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 |
---|---|---|
|
@@ -3,9 +3,11 @@ | |
namespace Junges\InviteCodes\Tests; | ||
|
||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\Support\Str; | ||
use Junges\InviteCodes\Contracts\InviteContract; | ||
use Junges\InviteCodes\Events\InviteRedeemedEvent; | ||
use Junges\InviteCodes\Facades\InviteCodes; | ||
use Junges\InviteCodes\Models\Invite; | ||
|
||
class FactoryTest extends TestCase | ||
{ | ||
|
@@ -42,4 +44,30 @@ public function test_macro(): void | |
$this->assertInstanceOf(InviteContract::class, $invite); | ||
$this->assertTrue($invite->usageRestrictedToEmail('[email protected]')); | ||
} | ||
|
||
public function test_it_can_run_quietly(): void | ||
{ | ||
Event::fake(); | ||
|
||
Invite::query()->create([ | ||
'code' => $code = Str::random(), | ||
]); | ||
|
||
InviteCodes::quietly(static function () use ($code) { | ||
InviteCodes::redeem($code); | ||
}); | ||
|
||
Event::assertNotDispatched(InviteRedeemedEvent::class); | ||
} | ||
|
||
public function test_it_can_customize_how_invite_code_is_created(): void | ||
{ | ||
InviteCodes::createInviteCodeUsing(static function () { | ||
return 'PREFIX-12345'; | ||
}); | ||
|
||
$invite = InviteCodes::create()->save(); | ||
|
||
$this->assertSame('PREFIX-12345', $invite->code); | ||
} | ||
} |