Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/SignupCodeTest.php
Show All 10 Lines | class SignupCodeTest extends TestCase | ||||
/** | /** | ||||
* Test SignupCode creation | * Test SignupCode creation | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function testSignupCodeCreate() | public function testSignupCodeCreate() | ||||
{ | { | ||||
$data = [ | $data = [ | ||||
'data' => [ | |||||
'email' => 'User@email.org', | 'email' => 'User@email.org', | ||||
] | |||||
]; | ]; | ||||
$now = Carbon::now(); | $now = Carbon::now(); | ||||
$code = SignupCode::create($data); | $code = SignupCode::create($data); | ||||
$code_length = env('VERIFICATION_CODE_LENGTH', SignupCode::SHORTCODE_LENGTH); | $code_length = env('VERIFICATION_CODE_LENGTH', SignupCode::SHORTCODE_LENGTH); | ||||
$exp = Carbon::now()->addHours(env('SIGNUP_CODE_EXPIRY', SignupCode::CODE_EXP_HOURS)); | $exp = Carbon::now()->addHours(env('SIGNUP_CODE_EXPIRY', SignupCode::CODE_EXP_HOURS)); | ||||
$this->assertFalse($code->isExpired()); | $this->assertFalse($code->isExpired()); | ||||
$this->assertTrue(strlen($code->code) === SignupCode::CODE_LENGTH); | $this->assertTrue(strlen($code->code) === SignupCode::CODE_LENGTH); | ||||
$this->assertTrue(strlen($code->short_code) === $code_length); | $this->assertTrue(strlen($code->short_code) === $code_length); | ||||
$this->assertSame($data['data'], $code->data); | $this->assertSame($data['email'], $code->email); | ||||
$this->assertSame('User', $code->local_part); | |||||
$this->assertSame('email.org', $code->domain_part); | |||||
$this->assertSame('127.0.0.1', $code->ip_address); | |||||
$this->assertInstanceOf(Carbon::class, $code->expires_at); | $this->assertInstanceOf(Carbon::class, $code->expires_at); | ||||
$this->assertSame($code->expires_at->toDateTimeString(), $exp->toDateTimeString()); | $this->assertSame($code->expires_at->toDateTimeString(), $exp->toDateTimeString()); | ||||
$inst = SignupCode::find($code->code); | $inst = SignupCode::find($code->code); | ||||
$this->assertInstanceOf(SignupCode::class, $inst); | $this->assertInstanceOf(SignupCode::class, $inst); | ||||
$this->assertSame($inst->code, $code->code); | $this->assertSame($inst->code, $code->code); | ||||
$inst->email = 'other@email.com'; | |||||
$inst->save(); | |||||
$this->assertSame('other', $inst->local_part); | |||||
$this->assertSame('email.com', $inst->domain_part); | |||||
} | } | ||||
} | } |