Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show All 27 Lines | public function setUp(): void | ||||
$this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | ||||
$this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | $this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | ||||
$this->deleteTestUser('john2.doe2@kolab.org'); | $this->deleteTestUser('john2.doe2@kolab.org'); | ||||
$this->deleteTestDomain('userscontroller.com'); | $this->deleteTestDomain('userscontroller.com'); | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$wallet->discount()->dissociate(); | $wallet->discount()->dissociate(); | ||||
$wallet->settings()->whereIn('key', ['mollie_id', 'stripe_id'])->delete(); | |||||
$wallet->save(); | $wallet->save(); | ||||
$user->status |= User::STATUS_IMAP_READY; | $user->status |= User::STATUS_IMAP_READY; | ||||
$user->save(); | $user->save(); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('UsersControllerTest1@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$this->deleteTestUser('UsersControllerTest2@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest2@userscontroller.com'); | ||||
$this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | ||||
$this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | $this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | ||||
$this->deleteTestUser('john2.doe2@kolab.org'); | $this->deleteTestUser('john2.doe2@kolab.org'); | ||||
$this->deleteTestDomain('userscontroller.com'); | $this->deleteTestDomain('userscontroller.com'); | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$wallet->discount()->dissociate(); | $wallet->discount()->dissociate(); | ||||
$wallet->settings()->whereIn('key', ['mollie_id', 'stripe_id'])->delete(); | |||||
$wallet->save(); | $wallet->save(); | ||||
$user->status |= User::STATUS_IMAP_READY; | $user->status |= User::STATUS_IMAP_READY; | ||||
$user->save(); | $user->save(); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 247 Lines • ▼ Show 20 Lines | public function testStatus(): void | ||||
// Now "reboot" the process and verify the user in imap syncronously | // Now "reboot" the process and verify the user in imap syncronously | ||||
$response = $this->actingAs($john)->get("/api/v4/users/{$john->id}/status?refresh=1"); | $response = $this->actingAs($john)->get("/api/v4/users/{$john->id}/status?refresh=1"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertTrue($json['isImapReady']); | $this->assertTrue($json['isImapReady']); | ||||
$this->assertFalse($json['isReady']); | $this->assertTrue($json['isReady']); | ||||
$this->assertCount(7, $json['process']); | $this->assertCount(7, $json['process']); | ||||
$this->assertSame('user-imap-ready', $json['process'][2]['label']); | $this->assertSame('user-imap-ready', $json['process'][2]['label']); | ||||
$this->assertSame(true, $json['process'][2]['state']); | $this->assertSame(true, $json['process'][2]['state']); | ||||
$this->assertSame('domain-confirmed', $json['process'][6]['label']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame(false, $json['process'][6]['state']); | $this->assertSame('Setup process finished successfully.', $json['message']); | ||||
$this->assertSame('error', $json['status']); | |||||
$this->assertSame('Failed to verify an ownership of a domain.', $json['message']); | |||||
// TODO: Test completing all process steps | |||||
} | } | ||||
/** | /** | ||||
* Test UsersController::statusInfo() | * Test UsersController::statusInfo() | ||||
*/ | */ | ||||
public function testStatusInfo(): void | public function testStatusInfo(): void | ||||
{ | { | ||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | $user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | ||||
▲ Show 20 Lines • Show All 386 Lines • ▼ Show 20 Lines | public function testUpdateEntitlements(): void | ||||
$this->markTestIncomplete(); | $this->markTestIncomplete(); | ||||
} | } | ||||
/** | /** | ||||
* Test user data response used in show and info actions | * Test user data response used in show and info actions | ||||
*/ | */ | ||||
public function testUserResponse(): void | public function testUserResponse(): void | ||||
{ | { | ||||
$provider = \config('payment_provider') ?: 'mollie'; | |||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$result = $this->invokeMethod(new UsersController(), 'userResponse', [$user]); | $result = $this->invokeMethod(new UsersController(), 'userResponse', [$user]); | ||||
$this->assertEquals($user->id, $result['id']); | $this->assertEquals($user->id, $result['id']); | ||||
$this->assertEquals($user->email, $result['email']); | $this->assertEquals($user->email, $result['email']); | ||||
$this->assertEquals($user->status, $result['status']); | $this->assertEquals($user->status, $result['status']); | ||||
$this->assertTrue(is_array($result['statusInfo'])); | $this->assertTrue(is_array($result['statusInfo'])); | ||||
Show All 21 Lines | public function testUserResponse(): void | ||||
$this->assertEquals($ned->email, $result['email']); | $this->assertEquals($ned->email, $result['email']); | ||||
$this->assertTrue(is_array($result['accounts'])); | $this->assertTrue(is_array($result['accounts'])); | ||||
$this->assertTrue(is_array($result['wallets'])); | $this->assertTrue(is_array($result['wallets'])); | ||||
$this->assertCount(1, $result['accounts']); | $this->assertCount(1, $result['accounts']); | ||||
$this->assertCount(1, $result['wallets']); | $this->assertCount(1, $result['wallets']); | ||||
$this->assertSame($wallet->id, $result['wallet']['id']); | $this->assertSame($wallet->id, $result['wallet']['id']); | ||||
$this->assertSame($wallet->id, $result['accounts'][0]['id']); | $this->assertSame($wallet->id, $result['accounts'][0]['id']); | ||||
$this->assertSame($ned_wallet->id, $result['wallets'][0]['id']); | $this->assertSame($ned_wallet->id, $result['wallets'][0]['id']); | ||||
$this->assertSame($provider, $result['wallet']['provider']); | |||||
$this->assertSame($provider, $result['wallets'][0]['provider']); | |||||
// Test discount in a response | // Test discount in a response | ||||
$discount = Discount::where('code', 'TEST')->first(); | $discount = Discount::where('code', 'TEST')->first(); | ||||
$wallet->discount()->associate($discount); | $wallet->discount()->associate($discount); | ||||
$wallet->save(); | $wallet->save(); | ||||
$mod_provider = $provider == 'mollie' ? 'stripe' : 'mollie'; | |||||
$wallet->setSetting($mod_provider . '_id', 123); | |||||
$user->refresh(); | $user->refresh(); | ||||
$result = $this->invokeMethod(new UsersController(), 'userResponse', [$user]); | $result = $this->invokeMethod(new UsersController(), 'userResponse', [$user]); | ||||
$this->assertEquals($user->id, $result['id']); | $this->assertEquals($user->id, $result['id']); | ||||
$this->assertSame($discount->id, $result['wallet']['discount_id']); | $this->assertSame($discount->id, $result['wallet']['discount_id']); | ||||
$this->assertSame($discount->discount, $result['wallet']['discount']); | $this->assertSame($discount->discount, $result['wallet']['discount']); | ||||
$this->assertSame($discount->description, $result['wallet']['discount_description']); | $this->assertSame($discount->description, $result['wallet']['discount_description']); | ||||
$this->assertSame($mod_provider, $result['wallet']['provider']); | |||||
$this->assertSame($discount->id, $result['wallets'][0]['discount_id']); | $this->assertSame($discount->id, $result['wallets'][0]['discount_id']); | ||||
$this->assertSame($discount->discount, $result['wallets'][0]['discount']); | $this->assertSame($discount->discount, $result['wallets'][0]['discount']); | ||||
$this->assertSame($discount->description, $result['wallets'][0]['discount_description']); | $this->assertSame($discount->description, $result['wallets'][0]['discount_description']); | ||||
$this->assertSame($mod_provider, $result['wallets'][0]['provider']); | |||||
} | } | ||||
/** | /** | ||||
* List of alias validation cases for testValidateEmail() | * List of alias validation cases for testValidateEmail() | ||||
* | * | ||||
* @return array Arguments for testValidateEmail() | * @return array Arguments for testValidateEmail() | ||||
*/ | */ | ||||
public function dataValidateEmail(): array | public function dataValidateEmail(): array | ||||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |