Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/SignupTest.php
Show First 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | public function testSignupInitInvalidInput(): void | ||||
$response = $this->post('/api/auth/signup/init', $data); | $response = $this->post('/api/auth/signup/init', $data); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(422); | $response->assertStatus(422); | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertCount(1, $json['errors']); | $this->assertCount(1, $json['errors']); | ||||
$this->assertSame("The specified email address is invalid.", $json['errors']['email']); | $this->assertSame(["The specified email address is invalid."], $json['errors']['email']); | ||||
SignupCode::truncate(); | SignupCode::truncate(); | ||||
// Email address limit check | // Email address limit check | ||||
$data = [ | $data = [ | ||||
'email' => 'test@example.org', | 'email' => 'test@example.org', | ||||
'first_name' => 'Signup', | 'first_name' => 'Signup', | ||||
'last_name' => 'User', | 'last_name' => 'User', | ||||
Show All 10 Lines | public function testSignupInitInvalidInput(): void | ||||
$response = $this->post('/api/auth/signup/init', $data); | $response = $this->post('/api/auth/signup/init', $data); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(422); | $response->assertStatus(422); | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertCount(1, $json['errors']); | $this->assertCount(1, $json['errors']); | ||||
// TODO: This probably should be a different message? | // TODO: This probably should be a different message? | ||||
$this->assertSame("The specified email address is invalid.", $json['errors']['email']); | $this->assertSame(["The specified email address is invalid."], $json['errors']['email']); | ||||
// IP address limit check | // IP address limit check | ||||
$data = [ | $data = [ | ||||
'email' => 'ip@example.org', | 'email' => 'ip@example.org', | ||||
'first_name' => 'Signup', | 'first_name' => 'Signup', | ||||
'last_name' => 'User', | 'last_name' => 'User', | ||||
]; | ]; | ||||
Show All 10 Lines | public function testSignupInitInvalidInput(): void | ||||
$response = $this->post('/api/auth/signup/init', $data, ['REMOTE_ADDR' => '10.1.1.1']); | $response = $this->post('/api/auth/signup/init', $data, ['REMOTE_ADDR' => '10.1.1.1']); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(422); | $response->assertStatus(422); | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertCount(1, $json['errors']); | $this->assertCount(1, $json['errors']); | ||||
// TODO: This probably should be a different message? | // TODO: This probably should be a different message? | ||||
$this->assertSame("The specified email address is invalid.", $json['errors']['email']); | $this->assertSame(["The specified email address is invalid."], $json['errors']['email']); | ||||
// TODO: Test phone validation | // TODO: Test phone validation | ||||
} | } | ||||
/** | /** | ||||
* Test signup initialization with valid input | * Test signup initialization with valid input | ||||
*/ | */ | ||||
public function testSignupInitValidInput(): array | public function testSignupInitValidInput(): array | ||||
Show All 9 Lines | public function testSignupInitValidInput(): array | ||||
'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); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertCount(2, $json); | |||||
$this->assertCount(3, $json); | |||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame('email', $json['mode']); | |||||
$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->plan === $data['plan'] | && $code->plan === $data['plan'] | ||||
&& $code->email === $data['email'] | && $code->email === $data['email'] | ||||
&& $code->first_name === $data['first_name'] | && $code->first_name === $data['first_name'] | ||||
&& $code->last_name === $data['last_name']; | && $code->last_name === $data['last_name']; | ||||
}); | }); | ||||
// Try the same with voucher | // Try the same with voucher | ||||
$data['voucher'] = 'TEST'; | $data['voucher'] = 'TEST'; | ||||
$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(3, $json); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame('email', $json['mode']); | |||||
$this->assertNotEmpty($json['code']); | $this->assertNotEmpty($json['code']); | ||||
// 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->plan === $data['plan'] | && $code->plan === $data['plan'] | ||||
▲ Show 20 Lines • Show All 302 Lines • ▼ Show 20 Lines | public function testSignupGroupAccount(): void | ||||
'last_name' => 'User', | 'last_name' => '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(3, $json); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame('email', $json['mode']); | |||||
$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'); | ||||
▲ Show 20 Lines • Show All 249 Lines • Show Last 20 Lines |