Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/SignupTest.php
<?php | <?php | ||||
namespace Tests\Feature\Controller; | namespace Tests\Feature\Controller; | ||||
use App\Http\Controllers\API\SignupController; | use App\Http\Controllers\API\SignupController; | ||||
use App\Discount; | |||||
use App\Domain; | use App\Domain; | ||||
use App\SignupCode; | use App\SignupCode; | ||||
use App\User; | use App\User; | ||||
use Illuminate\Support\Facades\Queue; | use Illuminate\Support\Facades\Queue; | ||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class SignupTest extends TestCase | class SignupTest extends TestCase | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | class SignupTest extends TestCase | ||||
/** | /** | ||||
* Test fetching plans for signup | * Test fetching plans for signup | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function testSignupPlans() | public function testSignupPlans() | ||||
{ | { | ||||
// Note: this uses plans that already have been seeded into the DB | |||||
$response = $this->get('/api/auth/signup/plans'); | $response = $this->get('/api/auth/signup/plans'); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertCount(2, $json['plans']); | $this->assertCount(2, $json['plans']); | ||||
$this->assertArrayHasKey('title', $json['plans'][0]); | $this->assertArrayHasKey('title', $json['plans'][0]); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | public function testSignupInitInvalidInput() | ||||
$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 | |||||
$data = [ | |||||
'voucher' => '123456789012345678901234567890123', | |||||
'name' => 'Signup User', | |||||
'email' => 'valid@email.com', | |||||
]; | |||||
$response = $this->post('/api/auth/signup/init', $data); | |||||
$json = $response->json(); | |||||
$response->assertStatus(422); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertCount(1, $json['errors']); | |||||
$this->assertArrayHasKey('voucher', $json['errors']); | |||||
// TODO: Test phone validation | // TODO: Test phone validation | ||||
} | } | ||||
/** | /** | ||||
* Test signup initialization with valid input | * Test signup initialization with valid input | ||||
* | * | ||||
* @return array | * @return array | ||||
*/ | */ | ||||
Show All 26 Lines | public function testSignupInitValidInput() | ||||
$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']; | ||||
}); | }); | ||||
// Try the same with voucher | |||||
$data['voucher'] = 'TEST'; | |||||
$response = $this->post('/api/auth/signup/init', $data); | |||||
$json = $response->json(); | |||||
$response->assertStatus(200); | |||||
$this->assertCount(2, $json); | |||||
$this->assertSame('success', $json['status']); | |||||
$this->assertNotEmpty($json['code']); | |||||
// Assert the job has proper data assigned | |||||
Queue::assertPushed(\App\Jobs\SignupVerificationEmail::class, function ($job) use ($data, $json) { | |||||
$code = TestCase::getObjectProperty($job, 'code'); | |||||
return $code->code === $json['code'] | |||||
&& $code->data['plan'] === $data['plan'] | |||||
&& $code->data['email'] === $data['email'] | |||||
&& $code->data['voucher'] === $data['voucher'] | |||||
&& $code->data['name'] === $data['name']; | |||||
}); | |||||
return [ | return [ | ||||
'code' => $json['code'], | 'code' => $json['code'], | ||||
'email' => $data['email'], | 'email' => $data['email'], | ||||
'name' => $data['name'], | 'name' => $data['name'], | ||||
'plan' => $data['plan'], | 'plan' => $data['plan'], | ||||
'voucher' => $data['voucher'] | |||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* Test signup code verification with invalid input | * Test signup code verification with invalid input | ||||
* | * | ||||
* @depends testSignupInitValidInput | * @depends testSignupInitValidInput | ||||
* @return void | * @return void | ||||
▲ Show 20 Lines • Show All 56 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(5, $json); | $this->assertCount(6, $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['name'], $json['name']); | ||||
$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; | ||||
} | } | ||||
/** | /** | ||||
* Test last signup step with invalid input | * Test last signup step with invalid input | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | public function testSignupInvalidInput(array $result) | ||||
$response = $this->post('/api/auth/signup', $data); | $response = $this->post('/api/auth/signup', $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('short_code', $json['errors']); | $this->assertArrayHasKey('short_code', $json['errors']); | ||||
// Valid code, invalid login | |||||
$code = SignupCode::find($result['code']); | $code = SignupCode::find($result['code']); | ||||
// Data with invalid voucher | |||||
$data = [ | |||||
'login' => 'TestLogin', | |||||
'domain' => $domain, | |||||
'password' => 'test', | |||||
'password_confirmation' => 'test', | |||||
'code' => $result['code'], | |||||
'short_code' => $code->short_code, | |||||
'voucher' => 'XXX', | |||||
]; | |||||
$response = $this->post('/api/auth/signup', $data); | |||||
$json = $response->json(); | |||||
$response->assertStatus(422); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertCount(1, $json['errors']); | |||||
$this->assertArrayHasKey('voucher', $json['errors']); | |||||
// Valid code, invalid login | |||||
$data = [ | $data = [ | ||||
'login' => 'żżżżżż', | 'login' => 'żżżżżż', | ||||
'domain' => $domain, | 'domain' => $domain, | ||||
'password' => 'test', | 'password' => 'test', | ||||
'password_confirmation' => 'test', | 'password_confirmation' => 'test', | ||||
'code' => $result['code'], | 'code' => $result['code'], | ||||
'short_code' => $code->short_code, | 'short_code' => $code->short_code, | ||||
]; | ]; | ||||
Show All 22 Lines | public function testSignupValidInput(array $result) | ||||
$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, | ||||
'voucher' => 'TEST', | |||||
]; | ]; | ||||
$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']); | ||||
Show All 16 Lines | public function testSignupValidInput(array $result) | ||||
$this->assertNotEmpty($user); | $this->assertNotEmpty($user); | ||||
$this->assertSame($identity, $user->email); | $this->assertSame($identity, $user->email); | ||||
$this->assertSame($result['name'], $user->name); | $this->assertSame($result['name'], $user->name); | ||||
// Check external email in user settings | // Check external email in user settings | ||||
$this->assertSame($result['email'], $user->getSetting('external_email')); | $this->assertSame($result['email'], $user->getSetting('external_email')); | ||||
// Discount | |||||
$discount = Discount::where('code', 'TEST')->first(); | |||||
$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 | ||||
* | * | ||||
Show All 37 Lines | public function testSignupGroupAccount() | ||||
'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(5, $result); | $this->assertCount(6, $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['name'], $result['name']); | ||||
$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 = [ | ||||
'login' => $login, | 'login' => $login, | ||||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |