Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/SignupTest.php
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | public function testSignupInitInvalidInput() | ||||
$data = []; | $data = []; | ||||
$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(2, $json['errors']); | $this->assertCount(1, $json['errors']); | ||||
$this->assertArrayHasKey('email', $json['errors']); | $this->assertArrayHasKey('email', $json['errors']); | ||||
$this->assertArrayHasKey('name', $json['errors']); | |||||
// Data with missing name | // Data with missing name | ||||
$data = [ | $data = [ | ||||
'email' => 'UsersApiControllerTest1@UsersApiControllerTest.com', | 'email' => 'UsersApiControllerTest1@UsersApiControllerTest.com', | ||||
'first_name' => str_repeat('a', 250), | |||||
'last_name' => str_repeat('a', 250), | |||||
]; | ]; | ||||
$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(2, $json['errors']); | ||||
$this->assertArrayHasKey('name', $json['errors']); | $this->assertArrayHasKey('first_name', $json['errors']); | ||||
$this->assertArrayHasKey('last_name', $json['errors']); | |||||
// Data with invalid email (but not phone number) | // Data with invalid email (but not phone number) | ||||
$data = [ | $data = [ | ||||
'email' => '@example.org', | 'email' => '@example.org', | ||||
'name' => 'Signup User', | 'first_name' => 'Signup', | ||||
'last_name' => 'User', | |||||
]; | ]; | ||||
$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->assertArrayHasKey('email', $json['errors']); | $this->assertArrayHasKey('email', $json['errors']); | ||||
// Sanity check on voucher code | // Sanity check on voucher code, last/first name is optional | ||||
$data = [ | $data = [ | ||||
'voucher' => '123456789012345678901234567890123', | 'voucher' => '123456789012345678901234567890123', | ||||
'name' => 'Signup User', | |||||
'email' => 'valid@email.com', | 'email' => 'valid@email.com', | ||||
]; | ]; | ||||
$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); | ||||
Show All 13 Lines | class SignupTest extends TestCase | ||||
{ | { | ||||
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', | 'first_name' => 'Signup', | ||||
'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(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['first_name'] === $data['first_name'] | ||||
&& $code->data['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(2, $json); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$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->data['plan'] === $data['plan'] | && $code->data['plan'] === $data['plan'] | ||||
&& $code->data['email'] === $data['email'] | && $code->data['email'] === $data['email'] | ||||
&& $code->data['voucher'] === $data['voucher'] | && $code->data['voucher'] === $data['voucher'] | ||||
&& $code->data['name'] === $data['name']; | && $code->data['first_name'] === $data['first_name'] | ||||
&& $code->data['last_name'] === $data['last_name']; | |||||
}); | }); | ||||
return [ | return [ | ||||
'code' => $json['code'], | 'code' => $json['code'], | ||||
'email' => $data['email'], | 'email' => $data['email'], | ||||
'name' => $data['name'], | 'first_name' => $data['first_name'], | ||||
'last_name' => $data['last_name'], | |||||
'plan' => $data['plan'], | 'plan' => $data['plan'], | ||||
'voucher' => $data['voucher'] | 'voucher' => $data['voucher'] | ||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* Test signup code verification with invalid input | * Test signup code verification with invalid input | ||||
* | * | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | public function testSignupVerifyValidInput(array $result) | ||||
'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); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertCount(6, $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['name'], $json['name']); | $this->assertSame($result['first_name'], $json['first_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'])); | ||||
return $result; | return $result; | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | public function testSignupValidInput(array $result) | ||||
// 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()); | ||||
// 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); | ||||
$this->assertSame($result['name'], $user->name); | |||||
// Check external email in user settings | // Check user settings | ||||
$this->assertSame($result['first_name'], $user->getSetting('first_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); | ||||
// TODO: Check SKUs/Plan | // TODO: Check SKUs/Plan | ||||
// TODO: Check if the access token works | // TODO: Check if the access token works | ||||
} | } | ||||
/** | /** | ||||
* 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::fake(); | ||||
// Initial signup request | // Initial signup request | ||||
$user_data = $data = [ | $user_data = $data = [ | ||||
'email' => 'testuser@external.com', | 'email' => 'testuser@external.com', | ||||
'name' => 'Signup User', | 'first_name' => 'Signup', | ||||
'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(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['first_name'] === $data['first_name'] | ||||
&& $code->data['last_name'] === $data['last_name']; | |||||
}); | }); | ||||
// Verify the code | // Verify the code | ||||
$code = SignupCode::find($json['code']); | $code = SignupCode::find($json['code']); | ||||
$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); | ||||
$result = $response->json(); | $result = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertCount(6, $result); | $this->assertCount(7, $result); | ||||
$this->assertSame('success', $result['status']); | $this->assertSame('success', $result['status']); | ||||
$this->assertSame($user_data['email'], $result['email']); | $this->assertSame($user_data['email'], $result['email']); | ||||
$this->assertSame($user_data['name'], $result['name']); | $this->assertSame($user_data['first_name'], $result['first_name']); | ||||
$this->assertSame($user_data['last_name'], $result['last_name']); | |||||
$this->assertSame(null, $result['voucher']); | $this->assertSame(null, $result['voucher']); | ||||
$this->assertSame(true, $result['is_domain']); | $this->assertSame(true, $result['is_domain']); | ||||
$this->assertSame([], $result['domains']); | $this->assertSame([], $result['domains']); | ||||
// Final signup request | // Final signup request | ||||
$login = 'admin'; | $login = 'admin'; | ||||
$domain = 'external.com'; | $domain = 'external.com'; | ||||
$data = [ | $data = [ | ||||
Show All 31 Lines | public function testSignupGroupAccount() | ||||
// 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)); | ||||
// Check if the user has been created | // Check if the user has been created | ||||
$user = User::where('email', $login . '@' . $domain)->first(); | $user = User::where('email', $login . '@' . $domain)->first(); | ||||
$this->assertNotEmpty($user); | $this->assertNotEmpty($user); | ||||
$this->assertSame($user_data['name'], $user->name); | |||||
// Check domain record | |||||
// Check external email in user settings | // Check user settings | ||||
$this->assertSame($user_data['email'], $user->getSetting('external_email')); | $this->assertSame($user_data['email'], $user->getSetting('external_email')); | ||||
$this->assertSame($user_data['first_name'], $user->getSetting('first_name')); | |||||
$this->assertSame($user_data['last_name'], $user->getSetting('last_name')); | |||||
// TODO: Check domain record | |||||
// TODO: Check SKUs/Plan | // TODO: Check SKUs/Plan | ||||
// TODO: Check if the access token works | // TODO: Check if the access token works | ||||
} | } | ||||
/** | /** | ||||
* List of login/domain validation cases for testValidateLogin() | * List of login/domain validation cases for testValidateLogin() | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |