Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/SignupTest.php
Show First 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | class SignupTest extends TestCase | ||||
/** | /** | ||||
* Test signup initialization with valid input | * Test signup initialization with valid input | ||||
* | * | ||||
* @return array | * @return array | ||||
*/ | */ | ||||
public function testSignupInitValidInput() | public function testSignupInitValidInput() | ||||
{ | { | ||||
Queue::fake(); | $queue = Queue::fake(); | ||||
// Assert that no jobs were pushed... | // Assert that no jobs were pushed... | ||||
Queue::assertNothingPushed(); | $queue->assertNothingPushed(); | ||||
$data = [ | $data = [ | ||||
'email' => 'testuser@external.com', | 'email' => 'testuser@external.com', | ||||
'name' => 'Signup User', | 'name' => 'Signup User', | ||||
'plan' => 'individual', | 'plan' => 'individual', | ||||
]; | ]; | ||||
$response = $this->post('/api/auth/signup/init', $data); | $response = $this->post('/api/auth/signup/init', $data); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertCount(2, $json); | $this->assertCount(2, $json); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertNotEmpty($json['code']); | $this->assertNotEmpty($json['code']); | ||||
// 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'] | ||||
&& $code->data['plan'] === $data['plan'] | && $code->data['plan'] === $data['plan'] | ||||
&& $code->data['email'] === $data['email'] | && $code->data['email'] === $data['email'] | ||||
&& $code->data['name'] === $data['name']; | && $code->data['name'] === $data['name']; | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | class SignupTest extends TestCase | ||||
/** | /** | ||||
* Test last signup step with valid input (user creation) | * Test last signup step with valid input (user creation) | ||||
* | * | ||||
* @depends testSignupVerifyValidInput | * @depends testSignupVerifyValidInput | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function testSignupValidInput(array $result) | public function testSignupValidInput(array $result) | ||||
{ | { | ||||
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']); | ||||
$data = [ | $data = [ | ||||
'login' => 'SignupLogin', | 'login' => 'SignupLogin', | ||||
'domain' => $domain, | 'domain' => $domain, | ||||
'password' => 'test', | 'password' => 'test', | ||||
'password_confirmation' => 'test', | 'password_confirmation' => 'test', | ||||
'code' => $code->code, | 'code' => $code->code, | ||||
'short_code' => $code->short_code, | 'short_code' => $code->short_code, | ||||
]; | ]; | ||||
$response = $this->post('/api/auth/signup', $data); | $response = $this->post('/api/auth/signup', $data); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertCount(4, $json); | $this->assertCount(4, $json); | ||||
$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']); | ||||
Queue::assertPushed(\App\Jobs\UserCreate::class, 1); | $queue->assertPushed(\App\Jobs\UserCreate::class, 1); | ||||
Queue::assertPushed(\App\Jobs\UserCreate::class, function ($job) use ($data) { | $queue->assertPushed(\App\Jobs\UserCreate::class, function ($job) use ($data) { | ||||
$job_user = TestCase::getObjectProperty($job, 'user'); | $job_user = TestCase::getObjectProperty($job, 'user'); | ||||
return $job_user->email === \strtolower($data['login'] . '@' . $data['domain']); | return $job_user->email === \strtolower($data['login'] . '@' . $data['domain']); | ||||
}); | }); | ||||
// Check if the code has been removed | // Check if the code has been removed | ||||
$this->assertNull(SignupCode::where('code', $result['code'])->first()); | $this->assertNull(SignupCode::where('code', $result['code'])->first()); | ||||
Show All 14 Lines | class SignupTest extends TestCase | ||||
/** | /** | ||||
* Test signup for a group (custom domain) account | * Test signup for a group (custom domain) account | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function testSignupGroupAccount() | public function testSignupGroupAccount() | ||||
{ | { | ||||
Queue::fake(); | $queue = Queue::fake(); | ||||
// Initial signup request | // Initial signup request | ||||
$user_data = $data = [ | $user_data = $data = [ | ||||
'email' => 'testuser@external.com', | 'email' => 'testuser@external.com', | ||||
'name' => 'Signup User', | 'name' => 'Signup User', | ||||
'plan' => 'group', | 'plan' => 'group', | ||||
]; | ]; | ||||
$response = $this->withoutMiddleware()->post('/api/auth/signup/init', $data); | $response = $this->withoutMiddleware()->post('/api/auth/signup/init', $data); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertCount(2, $json); | $this->assertCount(2, $json); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertNotEmpty($json['code']); | $this->assertNotEmpty($json['code']); | ||||
// 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'] | ||||
&& $code->data['plan'] === $data['plan'] | && $code->data['plan'] === $data['plan'] | ||||
&& $code->data['email'] === $data['email'] | && $code->data['email'] === $data['email'] | ||||
&& $code->data['name'] === $data['name']; | && $code->data['name'] === $data['name']; | ||||
}); | }); | ||||
Show All 32 Lines | public function testSignupGroupAccount() | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertCount(4, $result); | $this->assertCount(4, $result); | ||||
$this->assertSame('success', $result['status']); | $this->assertSame('success', $result['status']); | ||||
$this->assertSame('bearer', $result['token_type']); | $this->assertSame('bearer', $result['token_type']); | ||||
$this->assertTrue(!empty($result['expires_in']) && is_int($result['expires_in']) && $result['expires_in'] > 0); | $this->assertTrue(!empty($result['expires_in']) && is_int($result['expires_in']) && $result['expires_in'] > 0); | ||||
$this->assertNotEmpty($result['access_token']); | $this->assertNotEmpty($result['access_token']); | ||||
Queue::assertPushed(\App\Jobs\DomainCreate::class, 1); | $queue->assertPushed(\App\Jobs\DomainCreate::class, 1); | ||||
Queue::assertPushed(\App\Jobs\DomainCreate::class, function ($job) use ($domain) { | $queue->assertPushed(\App\Jobs\DomainCreate::class, function ($job) use ($domain) { | ||||
$job_domain = TestCase::getObjectProperty($job, 'domain'); | $job_domain = TestCase::getObjectProperty($job, 'domain'); | ||||
return $job_domain->namespace === $domain; | return $job_domain->namespace === $domain; | ||||
}); | }); | ||||
Queue::assertPushed(\App\Jobs\UserCreate::class, 1); | $queue->assertPushed(\App\Jobs\UserCreate::class, 1); | ||||
Queue::assertPushed(\App\Jobs\UserCreate::class, function ($job) use ($data) { | $queue->assertPushed(\App\Jobs\UserCreate::class, function ($job) use ($data) { | ||||
$job_user = TestCase::getObjectProperty($job, 'user'); | $job_user = TestCase::getObjectProperty($job, 'user'); | ||||
return $job_user->email === $data['login'] . '@' . $data['domain']; | return $job_user->email === $data['login'] . '@' . $data['domain']; | ||||
}); | }); | ||||
// Check if the code has been removed | // Check if the code has been removed | ||||
$this->assertNull(SignupCode::find($code->id)); | $this->assertNull(SignupCode::find($code->id)); | ||||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |