Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/SignupTest.php
Show First 20 Lines • Show All 274 Lines • ▼ Show 20 Lines | public function testSignupInitValidInput(): array | ||||
$data = [ | $data = [ | ||||
'email' => 'testuser@external.com', | 'email' => 'testuser@external.com', | ||||
'first_name' => 'Signup', | 'first_name' => 'Signup', | ||||
'last_name' => 'User', | 'last_name' => 'User', | ||||
'plan' => 'individual', | 'plan' => 'individual', | ||||
]; | ]; | ||||
$response = $this->post('/api/auth/signup/init', $data); | $response = $this->post('/api/auth/signup/init', $data, ['REMOTE_ADDR' => '10.1.1.2']); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertCount(3, $json); | $this->assertCount(3, $json); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame('email', $json['mode']); | $this->assertSame('email', $json['mode']); | ||||
$this->assertNotEmpty($json['code']); | $this->assertNotEmpty($json['code']); | ||||
$code = SignupCode::find($json['code']); | |||||
$this->assertSame('10.1.1.2', $code->ip_address); | |||||
$this->assertSame(null, $code->verify_ip_address); | |||||
$this->assertSame(null, $code->submit_ip_address); | |||||
// Assert the email sending job was pushed once | // Assert the email sending job was pushed once | ||||
Queue::assertPushed(\App\Jobs\SignupVerificationEmail::class, 1); | Queue::assertPushed(\App\Jobs\SignupVerificationEmail::class, 1); | ||||
// Assert the job has proper data assigned | // Assert the job has proper data assigned | ||||
Queue::assertPushed(\App\Jobs\SignupVerificationEmail::class, function ($job) use ($data, $json) { | Queue::assertPushed(\App\Jobs\SignupVerificationEmail::class, function ($job) use ($data, $json) { | ||||
$code = TestCase::getObjectProperty($job, 'code'); | $code = TestCase::getObjectProperty($job, 'code'); | ||||
return $code->code === $json['code'] | return $code->code === $json['code'] | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | class SignupTest extends TestCase | ||||
/** | /** | ||||
* Test signup code verification with valid input | * Test signup code verification with valid input | ||||
* | * | ||||
* @depends testSignupInitValidInput | * @depends testSignupInitValidInput | ||||
*/ | */ | ||||
public function testSignupVerifyValidInput(array $result): array | public function testSignupVerifyValidInput(array $result): array | ||||
{ | { | ||||
$code = SignupCode::find($result['code']); | $code = SignupCode::find($result['code']); | ||||
$code->ip_address = '10.1.1.2'; | |||||
$code->save(); | |||||
$data = [ | $data = [ | ||||
'code' => $code->code, | 'code' => $code->code, | ||||
'short_code' => $code->short_code, | 'short_code' => $code->short_code, | ||||
]; | ]; | ||||
$response = $this->post('/api/auth/signup/verify', $data); | $response = $this->post('/api/auth/signup/verify', $data, ['REMOTE_ADDR' => '10.1.1.3']); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertCount(7, $json); | $this->assertCount(7, $json); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame($result['email'], $json['email']); | $this->assertSame($result['email'], $json['email']); | ||||
$this->assertSame($result['first_name'], $json['first_name']); | $this->assertSame($result['first_name'], $json['first_name']); | ||||
$this->assertSame($result['last_name'], $json['last_name']); | $this->assertSame($result['last_name'], $json['last_name']); | ||||
$this->assertSame($result['voucher'], $json['voucher']); | $this->assertSame($result['voucher'], $json['voucher']); | ||||
$this->assertSame(false, $json['is_domain']); | $this->assertSame(false, $json['is_domain']); | ||||
$this->assertTrue(is_array($json['domains']) && !empty($json['domains'])); | $this->assertTrue(is_array($json['domains']) && !empty($json['domains'])); | ||||
$code->refresh(); | |||||
$this->assertSame('10.1.1.2', $code->ip_address); | |||||
$this->assertSame('10.1.1.3', $code->verify_ip_address); | |||||
$this->assertSame(null, $code->submit_ip_address); | |||||
return $result; | return $result; | ||||
} | } | ||||
/** | /** | ||||
* Test last signup step with invalid input | * Test last signup step with invalid input | ||||
* | * | ||||
* @depends testSignupVerifyValidInput | * @depends testSignupVerifyValidInput | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | class SignupTest extends TestCase | ||||
*/ | */ | ||||
public function testSignupValidInput(array $result): void | public function testSignupValidInput(array $result): void | ||||
{ | { | ||||
$queue = Queue::fake(); | $queue = Queue::fake(); | ||||
$domain = $this->getPublicDomain(); | $domain = $this->getPublicDomain(); | ||||
$identity = \strtolower('SignupLogin@') . $domain; | $identity = \strtolower('SignupLogin@') . $domain; | ||||
$code = SignupCode::find($result['code']); | $code = SignupCode::find($result['code']); | ||||
$code->ip_address = '10.1.1.2'; | |||||
$code->verify_ip_address = '10.1.1.3'; | |||||
$code->save(); | |||||
$data = [ | $data = [ | ||||
'login' => 'SignupLogin', | 'login' => 'SignupLogin', | ||||
'domain' => $domain, | 'domain' => $domain, | ||||
'password' => 'testtest', | 'password' => 'testtest', | ||||
'password_confirmation' => 'testtest', | 'password_confirmation' => 'testtest', | ||||
'code' => $code->code, | 'code' => $code->code, | ||||
'short_code' => $code->short_code, | 'short_code' => $code->short_code, | ||||
'voucher' => 'TEST', | 'voucher' => 'TEST', | ||||
]; | ]; | ||||
$response = $this->post('/api/auth/signup', $data); | $response = $this->post('/api/auth/signup', $data, ['REMOTE_ADDR' => '10.1.1.4']); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame('bearer', $json['token_type']); | $this->assertSame('bearer', $json['token_type']); | ||||
$this->assertTrue(!empty($json['expires_in']) && is_int($json['expires_in']) && $json['expires_in'] > 0); | $this->assertTrue(!empty($json['expires_in']) && is_int($json['expires_in']) && $json['expires_in'] > 0); | ||||
$this->assertNotEmpty($json['access_token']); | $this->assertNotEmpty($json['access_token']); | ||||
$this->assertSame($identity, $json['email']); | $this->assertSame($identity, $json['email']); | ||||
Queue::assertPushed(\App\Jobs\User\CreateJob::class, 1); | Queue::assertPushed(\App\Jobs\User\CreateJob::class, 1); | ||||
Queue::assertPushed( | Queue::assertPushed( | ||||
\App\Jobs\User\CreateJob::class, | \App\Jobs\User\CreateJob::class, | ||||
function ($job) use ($data) { | function ($job) use ($data) { | ||||
$userEmail = TestCase::getObjectProperty($job, 'userEmail'); | $userEmail = TestCase::getObjectProperty($job, 'userEmail'); | ||||
return $userEmail === \strtolower($data['login'] . '@' . $data['domain']); | return $userEmail === \strtolower($data['login'] . '@' . $data['domain']); | ||||
} | } | ||||
); | ); | ||||
// Check if the code has been removed | $code->refresh(); | ||||
$this->assertNull(SignupCode::where('code', $result['code'])->first()); | |||||
// Check if the user has been created | // Check if the user has been created | ||||
$user = User::where('email', $identity)->first(); | $user = User::where('email', $identity)->first(); | ||||
$this->assertNotEmpty($user); | $this->assertNotEmpty($user); | ||||
$this->assertSame($identity, $user->email); | $this->assertSame($identity, $user->email); | ||||
// Check if the code has been updated and soft-deleted | |||||
$this->assertTrue($code->trashed()); | |||||
$this->assertSame('10.1.1.2', $code->ip_address); | |||||
$this->assertSame('10.1.1.3', $code->verify_ip_address); | |||||
$this->assertSame('10.1.1.4', $code->submit_ip_address); | |||||
$this->assertSame($user->id, $code->user_id); | |||||
// Check user settings | // Check user settings | ||||
$this->assertSame($result['first_name'], $user->getSetting('first_name')); | $this->assertSame($result['first_name'], $user->getSetting('first_name')); | ||||
$this->assertSame($result['last_name'], $user->getSetting('last_name')); | $this->assertSame($result['last_name'], $user->getSetting('last_name')); | ||||
$this->assertSame($result['email'], $user->getSetting('external_email')); | $this->assertSame($result['email'], $user->getSetting('external_email')); | ||||
// Discount | // Discount | ||||
$discount = Discount::where('code', 'TEST')->first(); | $discount = Discount::where('code', 'TEST')->first(); | ||||
$this->assertSame($discount->id, $user->wallets()->first()->discount_id); | $this->assertSame($discount->id, $user->wallets()->first()->discount_id); | ||||
▲ Show 20 Lines • Show All 285 Lines • Show Last 20 Lines |