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 = Queue::fake(); | 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 223 Lines • ▼ Show 20 Lines | public function testSignupValidInput(array $result) | ||||
$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 = Queue::fake(); | 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 |