-
Notifications
You must be signed in to change notification settings - Fork 19
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 #23 from nextapps-be/feature/allow_verification_wi…
…thout_code_removal
- Loading branch information
Showing
7 changed files
with
94 additions
and
5 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,18 @@ | ||
<?php | ||
|
||
namespace NextApps\VerificationCode\Console; | ||
|
||
use Illuminate\Console\Command; | ||
use NextApps\VerificationCode\Models\VerificationCode; | ||
|
||
class PruneCommand extends Command | ||
{ | ||
protected $signature = 'verification-code:prune {--hours=24 : The number of hours to retain verification codes}'; | ||
|
||
protected $description = 'Prune old verification codes'; | ||
|
||
public function handle() : void | ||
{ | ||
VerificationCode::where('created_at', '<=', now()->subHours($this->option('hours')))->delete(); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace NextApps\VerificationCode\Tests\Feature; | ||
|
||
use NextApps\VerificationCode\Models\VerificationCode; | ||
use NextApps\VerificationCode\Tests\TestCase; | ||
|
||
class PruneCommandTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_cleans_the_verification_code_table() | ||
{ | ||
VerificationCode::create([ | ||
'code' => 'ABC123', | ||
'verifiable' => '[email protected]', | ||
'created_at' => now()->subHours(5), | ||
]); | ||
|
||
$verificationCode = VerificationCode::create([ | ||
'code' => '123ABC', | ||
'verifiable' => '[email protected]', | ||
]); | ||
|
||
$this->artisan('verification-code:prune', ['--hours' => 3]); | ||
|
||
$dbVerificationCodes = VerificationCode::all(); | ||
|
||
$this->assertCount(1, $dbVerificationCodes); | ||
$this->assertEquals($verificationCode->id, $dbVerificationCodes->first()->id); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -57,6 +57,18 @@ public function it_deletes_code_if_used_for_verification() | |
$this->assertNull(VerificationCode::find($verificationCode->id)); | ||
} | ||
|
||
/** @test */ | ||
public function it_does_not_delete_code_if_cleanup_is_false() | ||
{ | ||
$verificationCode = VerificationCode::create([ | ||
'code' => 'ABC123', | ||
'verifiable' => '[email protected]', | ||
]); | ||
|
||
VerificationCodeFacade::verify('ABC123', '[email protected]', false); | ||
$this->assertNotNull(VerificationCode::find($verificationCode->id)); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_true_if_test_code_used_by_test_verifiable() | ||
{ | ||
|