diff --git a/src/tests/Feature/Controller/SignupTest.php b/src/tests/Feature/Controller/SignupTest.php index 3b91b1d4..3d4ae022 100644 --- a/src/tests/Feature/Controller/SignupTest.php +++ b/src/tests/Feature/Controller/SignupTest.php @@ -1,74 +1,197 @@ 'SignupControllerTest1@SignupControllerTest.com' ] ); $user->delete(); } /** - {@inheritDoc} - - @return void + * {@inheritDoc} + * + * @return void */ public function tearDown(): void { $user = User::firstOrCreate( [ 'email' => 'SignupControllerTest1@SignupControllerTest.com' ] ); $user->delete(); parent::tearDown(); } - public function testRegisterUser() + public function testSignupInitInvalidInput() { + // Empty input data + $data = []; + + $response = $this->post('/api/auth/signup/init', $data); + $json = $response->json(); + + $response->assertStatus(422); + + $this->assertSame('error', $json['status']); + $this->assertCount(2, $json['errors']); + $this->assertArrayHasKey('email', $json['errors']); + $this->assertArrayHasKey('name', $json['errors']); + + // Data with missing name $data = [ 'email' => 'UsersApiControllerTest1@UsersApiControllerTest.com', 'password' => 'simple123', 'password_confirmation' => 'simple123' ]; - $response = $this->post('/api/auth/register', $data); + $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('name', $json['errors']); + + // Data with invalid email (but not phone number) + $data = [ + 'email' => '@example.org', + 'name' => 'Signup User', + 'password' => 'simple123', + 'password_confirmation' => 'simple123' + ]; + + $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('email', $json['errors']); + + // TODO: Test phone validation + } + + public function testSignupInitValidInput() + { + $data = [ + 'email' => 'UsersApiControllerTest1@UsersApiControllerTest.com', + 'name' => 'Signup User', + 'password' => 'simple123', + 'password_confirmation' => 'simple123' + ]; + + $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']); + + // TODO: Test verification email/sms + + return [ + 'code' => $json['code'], + 'email' => $data['email'], + 'name' => $data['name'], + ]; } - public function testListUsers() + /** + * @depends testSignupInitValidInput + */ + public function testSignupVerifyInvalidInput(array $result) { - $user = User::firstOrCreate( - [ - 'email' => 'UsersApiControllerTest1@UsersApiControllerTest.com' - ] - ); + // Empty data + $data = []; + + $response = $this->post('/api/auth/signup/verify', $data); + $json = $response->json(); - $response = $this->actingAs($user)->get("api/v4/users"); + $response->assertStatus(422); + $this->assertCount(2, $json); + $this->assertSame('error', $json['status']); + $this->assertArrayHasKey('code', $json['errors']); + $this->assertArrayHasKey('short_code', $json['errors']); - $response->assertJsonCount(1); + // Data with existing code but missing short_code + $data = [ + 'code' => $result['code'], + ]; + + $response = $this->post('/api/auth/signup/verify', $data); + $json = $response->json(); + + $response->assertStatus(422); + $this->assertCount(2, $json); + $this->assertSame('error', $json['status']); + $this->assertArrayHasKey('short_code', $json['errors']); + + // Data with invalid short_code + $data = [ + 'code' => $result['code'], + 'short_code' => 'XXXX', + ]; + + $response = $this->post('/api/auth/signup/verify', $data); + $json = $response->json(); + + $response->assertStatus(422); + $this->assertCount(2, $json); + $this->assertSame('error', $json['status']); + $this->assertArrayHasKey('short_code', $json['errors']); + + // TODO: Test expired code + } + + /** + * @depends testSignupInitValidInput + */ + public function testSignupVerifyValidInput(array $result) + { + $code = SignupCode::find($result['code']); + $data = [ + 'code' => $code->code, + 'short_code' => $code->short_code, + ]; + + $response = $this->post('/api/auth/signup/verify', $data); + $json = $response->json(); $response->assertStatus(200); + $this->assertCount(3, $json); + $this->assertSame('success', $json['status']); + $this->assertSame($result['email'], $json['email']); + $this->assertSame($result['name'], $json['name']); + } + + public function testSignup() + { + // TODO } } diff --git a/src/tests/Feature/EntitlementTest.php b/src/tests/Feature/EntitlementTest.php index 06f255f6..5865c71a 100644 --- a/src/tests/Feature/EntitlementTest.php +++ b/src/tests/Feature/EntitlementTest.php @@ -1,115 +1,114 @@ 'entitlement-test@kolabnow.com'] ); $user = User::firstOrCreate( ['email' => 'entitled-user@custom-domain.com'] ); $entitlement = Entitlement::firstOrCreate( [ 'owner_id' => $owner->id, 'user_id' => $user->id ] ); $entitlement->delete(); $user->delete(); $owner->delete(); } public function testUserAddEntitlement() { $sku_domain = Sku::firstOrCreate( ['title' => 'domain'] ); $sku_mailbox = Sku::firstOrCreate( ['title' => 'mailbox'] ); $owner = User::firstOrCreate( ['email' => 'entitlement-test@kolabnow.com'] ); $user = User::firstOrCreate( ['email' => 'entitled-user@custom-domain.com'] ); - // FIXME: How is this assertion false?? - //$this->assertTrue($owner->id != $user->id); + $this->assertTrue($owner->id != $user->id); $wallets = $owner->wallets()->get(); $domain = Domain::firstOrCreate( [ 'namespace' => 'custom-domain.com', 'status' => Domain::STATUS_NEW, 'type' => Domain::TYPE_EXTERNAL, ] ); $entitlement_own_mailbox = Entitlement::firstOrCreate( [ 'owner_id' => $owner->id, 'entitleable_id' => $owner->id, 'entitleable_type' => User::class, 'wallet_id' => $wallets[0]->id, 'sku_id' => $sku_mailbox->id, 'description' => "Owner Mailbox Entitlement Test" ] ); $entitlement_domain = Entitlement::firstOrCreate( [ 'owner_id' => $owner->id, 'entitleable_id' => $domain->id, 'entitleable_type' => Domain::class, 'wallet_id' => $wallets[0]->id, 'sku_id' => $sku_domain->id, 'description' => "User Domain Entitlement Test" ] ); $entitlement_mailbox = Entitlement::firstOrCreate( [ 'owner_id' => $owner->id, 'entitleable_id' => $user->id, 'entitleable_type' => User::class, 'wallet_id' => $wallets[0]->id, 'sku_id' => $sku_mailbox->id, 'description' => "User Mailbox Entitlement Test" ] ); $owner->addEntitlement($entitlement_own_mailbox); $owner->addEntitlement($entitlement_domain); $owner->addEntitlement($entitlement_mailbox); $this->assertTrue($owner->entitlements()->count() == 3); $this->assertTrue($sku_domain->entitlements()->count() == 2); $this->assertTrue($sku_mailbox->entitlements()->count() == 3); $this->assertTrue($wallets[0]->entitlements()->count() == 3); $this->assertTrue($wallets[0]->fresh()->balance < 0.00); } }