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\Discount; | ||||
use App\Domain; | use App\Domain; | ||||
use App\Plan; | |||||
use App\Package; | |||||
use App\SignupCode; | use App\SignupCode; | ||||
use App\SignupInvitation as SI; | use App\SignupInvitation as SI; | ||||
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 All 15 Lines | public function setUp(): void | ||||
$this->deleteTestUser("admin@external.com"); | $this->deleteTestUser("admin@external.com"); | ||||
$this->deleteTestUser("test-inv@kolabnow.com"); | $this->deleteTestUser("test-inv@kolabnow.com"); | ||||
$this->deleteTestDomain('external.com'); | $this->deleteTestDomain('external.com'); | ||||
$this->deleteTestDomain('signup-domain.com'); | $this->deleteTestDomain('signup-domain.com'); | ||||
$this->deleteTestGroup('group-test@kolabnow.com'); | $this->deleteTestGroup('group-test@kolabnow.com'); | ||||
SI::truncate(); | SI::truncate(); | ||||
Plan::where('title', 'test')->delete(); | |||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser("SignupControllerTest1@$this->domain"); | $this->deleteTestUser("SignupControllerTest1@$this->domain"); | ||||
$this->deleteTestUser("signuplogin@$this->domain"); | $this->deleteTestUser("signuplogin@$this->domain"); | ||||
$this->deleteTestUser("admin@external.com"); | $this->deleteTestUser("admin@external.com"); | ||||
$this->deleteTestUser("test-inv@kolabnow.com"); | $this->deleteTestUser("test-inv@kolabnow.com"); | ||||
$this->deleteTestDomain('external.com'); | $this->deleteTestDomain('external.com'); | ||||
$this->deleteTestDomain('signup-domain.com'); | $this->deleteTestDomain('signup-domain.com'); | ||||
$this->deleteTestGroup('group-test@kolabnow.com'); | $this->deleteTestGroup('group-test@kolabnow.com'); | ||||
SI::truncate(); | SI::truncate(); | ||||
Plan::where('title', 'test')->delete(); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Return a public domain for signup tests | * Return a public domain for signup tests | ||||
*/ | */ | ||||
private function getPublicDomain(): string | private function getPublicDomain(): string | ||||
Show All 12 Lines | private function getPublicDomain(): string | ||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
return $this->domain; | return $this->domain; | ||||
} | } | ||||
/** | /** | ||||
* Test fetching public domains for signup | |||||
*/ | |||||
public function testSignupDomains(): void | |||||
{ | |||||
$response = $this->get('/api/auth/signup/domains'); | |||||
$json = $response->json(); | |||||
$response->assertStatus(200); | |||||
$this->assertCount(2, $json); | |||||
$this->assertSame('success', $json['status']); | |||||
$this->assertSame(Domain::getPublicDomains(), $json['domains']); | |||||
} | |||||
/** | |||||
* Test fetching plans for signup | * Test fetching plans for signup | ||||
*/ | */ | ||||
public function testSignupPlans(): void | public function testSignupPlans(): void | ||||
{ | { | ||||
$individual = Plan::withEnvTenantContext()->where('title', 'individual')->first(); | |||||
$group = Plan::withEnvTenantContext()->where('title', 'group')->first(); | |||||
$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->assertSame($individual->title, $json['plans'][0]['title']); | ||||
$this->assertArrayHasKey('name', $json['plans'][0]); | $this->assertSame($individual->name, $json['plans'][0]['name']); | ||||
$this->assertArrayHasKey('description', $json['plans'][0]); | $this->assertSame($individual->description, $json['plans'][0]['description']); | ||||
$this->assertFalse($json['plans'][0]['isDomain']); | |||||
$this->assertArrayHasKey('button', $json['plans'][0]); | $this->assertArrayHasKey('button', $json['plans'][0]); | ||||
$this->assertSame($group->title, $json['plans'][1]['title']); | |||||
$this->assertSame($group->name, $json['plans'][1]['name']); | |||||
$this->assertSame($group->description, $json['plans'][1]['description']); | |||||
$this->assertTrue($json['plans'][1]['isDomain']); | |||||
$this->assertArrayHasKey('button', $json['plans'][1]); | |||||
} | } | ||||
/** | /** | ||||
* Test fetching invitation | * Test fetching invitation | ||||
*/ | */ | ||||
public function testSignupInvitations(): void | public function testSignupInvitations(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
▲ Show 20 Lines • Show All 650 Lines • ▼ Show 20 Lines | public function testSignupGroupAccount(): void | ||||
// TODO: Check domain record | // 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 | ||||
} | } | ||||
/** | /** | ||||
* Test signup with mode=mandate | |||||
*/ | |||||
public function testSignupMandateMode(): void | |||||
{ | |||||
Queue::fake(); | |||||
$plan = Plan::create([ | |||||
'title' => 'test', | |||||
'name' => 'Test Account', | |||||
'description' => 'Test', | |||||
'free_months' => 1, | |||||
'discount_qty' => 0, | |||||
'discount_rate' => 0, | |||||
'mode' => 'mandate', | |||||
]); | |||||
$packages = [ | |||||
Package::where(['title' => 'kolab', 'tenant_id' => \config('app.tenant_id')])->first() | |||||
]; | |||||
$plan->packages()->saveMany($packages); | |||||
$post = [ | |||||
'plan' => 'abc', | |||||
'login' => 'test-inv', | |||||
'domain' => 'kolabnow.com', | |||||
'password' => 'testtest', | |||||
'password_confirmation' => 'testtest', | |||||
]; | |||||
// Test invalid plan identifier | |||||
$response = $this->post('/api/auth/signup', $post); | |||||
$response->assertStatus(422); | |||||
$json = $response->json(); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertCount(1, $json['errors']); | |||||
$this->assertSame("The selected plan is invalid.", $json['errors']['plan']); | |||||
// Test valid input | |||||
$post['plan'] = $plan->title; | |||||
$response = $this->post('/api/auth/signup', $post); | |||||
$json = $response->json(); | |||||
$response->assertStatus(200); | |||||
$this->assertSame('success', $json['status']); | |||||
$this->assertNotEmpty($json['access_token']); | |||||
$this->assertSame('test-inv@kolabnow.com', $json['email']); | |||||
$this->assertTrue($json['isLocked']); | |||||
$user = User::where('email', 'test-inv@kolabnow.com')->first(); | |||||
$this->assertNotEmpty($user); | |||||
$this->assertSame($plan->id, $user->getSetting('plan_id')); | |||||
} | |||||
/** | |||||
* Test signup via invitation | * Test signup via invitation | ||||
*/ | */ | ||||
public function testSignupViaInvitation(): void | public function testSignupViaInvitation(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
$invitation = SI::create(['email' => 'email1@ext.com']); | $invitation = SI::create(['email' => 'email1@ext.com']); | ||||
▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines |