-
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 #24 from nextapps-be/feature/only-purge-expired-codes
Only purge old expired codes
- Loading branch information
Showing
2 changed files
with
34 additions
and
8 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 |
---|---|---|
|
@@ -8,24 +8,47 @@ | |
class PruneCommandTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_cleans_the_verification_code_table() | ||
public function it_deletes_old_expired_code() | ||
{ | ||
VerificationCode::create([ | ||
$verificationCode = VerificationCode::create([ | ||
'code' => 'ABC123', | ||
'verifiable' => '[email protected]', | ||
'created_at' => now()->subHours(5), | ||
'expires_at' => now()->subHour(), | ||
]); | ||
VerificationCode::where('id', $verificationCode->id)->update(['created_at' => now()->subHours(5)]); | ||
|
||
$this->artisan('verification-code:prune', ['--hours' => 3]); | ||
|
||
$this->assertNull(VerificationCode::find($verificationCode->id)); | ||
} | ||
|
||
/** @test */ | ||
public function it_does_not_delete_old_but_not_expired_code() | ||
{ | ||
$verificationCode = VerificationCode::create([ | ||
'code' => '123ABC', | ||
'code' => 'ABC123', | ||
'verifiable' => '[email protected]', | ||
'expires_at' => now()->addHour(), | ||
]); | ||
VerificationCode::where('id', $verificationCode->id)->update(['created_at' => now()->subHours(5)]); | ||
|
||
$this->artisan('verification-code:prune', ['--hours' => 3]); | ||
|
||
$dbVerificationCodes = VerificationCode::all(); | ||
$this->assertNotNull(VerificationCode::find($verificationCode->id)); | ||
} | ||
|
||
/** @test */ | ||
public function it_does_not_delete_code_that_is_not_old_enough() | ||
{ | ||
$verificationCode = VerificationCode::create([ | ||
'code' => 'ABC123', | ||
'verifiable' => '[email protected]', | ||
'expires_at' => now()->subHour(), | ||
]); | ||
VerificationCode::where('id', $verificationCode->id)->update(['created_at' => now()->subHours(2)]); | ||
|
||
$this->artisan('verification-code:prune', ['--hours' => 3]); | ||
|
||
$this->assertCount(1, $dbVerificationCodes); | ||
$this->assertEquals($verificationCode->id, $dbVerificationCodes->first()->id); | ||
$this->assertNotNull(VerificationCode::find($verificationCode->id)); | ||
} | ||
} |