|
@@ -5,7 +5,7 @@ namespace Tests\Feature\Services;
|
|
|
use App\Models\Group;
|
|
|
use App\Models\TwoFAccount;
|
|
|
use Tests\FeatureTestCase;
|
|
|
-use App\Services\GroupService;
|
|
|
+use App\Facades\Groups;
|
|
|
use App\Services\SettingService;
|
|
|
|
|
|
|
|
@@ -14,12 +14,6 @@ use App\Services\SettingService;
|
|
|
*/
|
|
|
class GroupServiceTest extends FeatureTestCase
|
|
|
{
|
|
|
- /**
|
|
|
- * App\Services\GroupService $groupService
|
|
|
- */
|
|
|
- protected $groupService;
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* App\Services\SettingService $settingService
|
|
|
*/
|
|
@@ -58,7 +52,6 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
{
|
|
|
parent::setUp();
|
|
|
|
|
|
- $this->groupService = $this->app->make(GroupService::class);
|
|
|
$this->settingService = $this->app->make(SettingService::class);
|
|
|
|
|
|
$this->groupOne = new Group;
|
|
@@ -102,7 +95,7 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
*/
|
|
|
public function test_getAll_returns_a_collection()
|
|
|
{
|
|
|
- $this->assertInstanceOf(\Illuminate\Database\Eloquent\Collection::class, $this->groupService->getAll());
|
|
|
+ $this->assertInstanceOf(\Illuminate\Database\Eloquent\Collection::class, Groups::getAll());
|
|
|
}
|
|
|
|
|
|
|
|
@@ -111,7 +104,7 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
*/
|
|
|
public function test_getAll_adds_pseudo_group_on_top_of_user_groups()
|
|
|
{
|
|
|
- $groups = $this->groupService->getAll();
|
|
|
+ $groups = Groups::getAll();
|
|
|
|
|
|
$this->assertEquals(0, $groups->first()->id);
|
|
|
$this->assertEquals(__('commons.all'), $groups->first()->name);
|
|
@@ -123,7 +116,7 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
*/
|
|
|
public function test_getAll_returns_pseudo_group_with_all_twofaccounts_count()
|
|
|
{
|
|
|
- $groups = $this->groupService->getAll();
|
|
|
+ $groups = Groups::getAll();
|
|
|
|
|
|
$this->assertEquals(self::TWOFACCOUNT_COUNT, $groups->first()->twofaccounts_count);
|
|
|
}
|
|
@@ -134,7 +127,7 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
*/
|
|
|
public function test_create_persists_and_returns_created_group()
|
|
|
{
|
|
|
- $newGroup = $this->groupService->create(['name' => self::NEW_GROUP_NAME]);
|
|
|
+ $newGroup = Groups::create(['name' => self::NEW_GROUP_NAME]);
|
|
|
|
|
|
$this->assertDatabaseHas('groups', ['name' => self::NEW_GROUP_NAME]);
|
|
|
$this->assertInstanceOf(\App\Models\Group::class, $newGroup);
|
|
@@ -147,7 +140,7 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
*/
|
|
|
public function test_update_persists_and_returns_updated_group()
|
|
|
{
|
|
|
- $this->groupOne = $this->groupService->update($this->groupOne, ['name' => self::NEW_GROUP_NAME]);
|
|
|
+ $this->groupOne = Groups::update($this->groupOne, ['name' => self::NEW_GROUP_NAME]);
|
|
|
|
|
|
$this->assertDatabaseHas('groups', ['name' => self::NEW_GROUP_NAME]);
|
|
|
$this->assertInstanceOf(\App\Models\Group::class, $this->groupOne);
|
|
@@ -160,7 +153,7 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
*/
|
|
|
public function test_delete_a_groupId_clear_db_and_returns_deleted_count()
|
|
|
{
|
|
|
- $deleted = $this->groupService->delete($this->groupOne->id);
|
|
|
+ $deleted = Groups::delete($this->groupOne->id);
|
|
|
|
|
|
$this->assertDatabaseMissing('groups', ['id' => $this->groupOne->id]);
|
|
|
$this->assertEquals(1, $deleted);
|
|
@@ -172,7 +165,7 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
*/
|
|
|
public function test_delete_an_array_of_ids_clear_db_and_returns_deleted_count()
|
|
|
{
|
|
|
- $deleted = $this->groupService->delete([$this->groupOne->id, $this->groupTwo->id]);
|
|
|
+ $deleted = Groups::delete([$this->groupOne->id, $this->groupTwo->id]);
|
|
|
|
|
|
$this->assertDatabaseMissing('groups', ['id' => $this->groupOne->id]);
|
|
|
$this->assertDatabaseMissing('groups', ['id' => $this->groupTwo->id]);
|
|
@@ -187,7 +180,7 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
{
|
|
|
$this->settingService->set('defaultGroup', $this->groupOne->id);
|
|
|
|
|
|
- $deleted = $this->groupService->delete($this->groupOne->id);
|
|
|
+ $deleted = Groups::delete($this->groupOne->id);
|
|
|
|
|
|
$this->assertDatabaseHas('options', [
|
|
|
'key' => 'defaultGroup',
|
|
@@ -204,7 +197,7 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
$this->settingService->set('rememberActiveGroup', true);
|
|
|
$this->settingService->set('activeGroup', $this->groupOne->id);
|
|
|
|
|
|
- $deleted = $this->groupService->delete($this->groupOne->id);
|
|
|
+ $deleted = Groups::delete($this->groupOne->id);
|
|
|
|
|
|
$this->assertDatabaseHas('options', [
|
|
|
'key' => 'activeGroup',
|
|
@@ -219,7 +212,7 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
public function test_assign_a_twofaccountid_to_a_specified_group_persists_the_relation()
|
|
|
{
|
|
|
|
|
|
- $this->groupService->assign($this->twofaccountOne->id, $this->groupOne);
|
|
|
+ Groups::assign($this->twofaccountOne->id, $this->groupOne);
|
|
|
|
|
|
$this->assertDatabaseHas('twofaccounts', [
|
|
|
'id' => $this->twofaccountOne->id,
|
|
@@ -233,7 +226,7 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
*/
|
|
|
public function test_assign_multiple_twofaccountid_to_a_specified_group_persists_the_relation()
|
|
|
{
|
|
|
- $this->groupService->assign([$this->twofaccountOne->id, $this->twofaccountTwo->id], $this->groupOne);
|
|
|
+ Groups::assign([$this->twofaccountOne->id, $this->twofaccountTwo->id], $this->groupOne);
|
|
|
|
|
|
$this->assertDatabaseHas('twofaccounts', [
|
|
|
'id' => $this->twofaccountOne->id,
|
|
@@ -253,7 +246,7 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
{
|
|
|
$this->settingService->set('defaultGroup', $this->groupTwo->id);
|
|
|
|
|
|
- $this->groupService->assign($this->twofaccountOne->id);
|
|
|
+ Groups::assign($this->twofaccountOne->id);
|
|
|
|
|
|
$this->assertDatabaseHas('twofaccounts', [
|
|
|
'id' => $this->twofaccountOne->id,
|
|
@@ -270,7 +263,7 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
$this->settingService->set('defaultGroup', -1);
|
|
|
$this->settingService->set('activeGroup', $this->groupTwo->id);
|
|
|
|
|
|
- $this->groupService->assign($this->twofaccountOne->id);
|
|
|
+ Groups::assign($this->twofaccountOne->id);
|
|
|
|
|
|
$this->assertDatabaseHas('twofaccounts', [
|
|
|
'id' => $this->twofaccountOne->id,
|
|
@@ -287,7 +280,7 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
$this->settingService->set('defaultGroup', -1);
|
|
|
$this->settingService->set('activeGroup', 100000);
|
|
|
|
|
|
- $this->groupService->assign($this->twofaccountOne->id);
|
|
|
+ Groups::assign($this->twofaccountOne->id);
|
|
|
|
|
|
$this->assertDatabaseHas('twofaccounts', [
|
|
|
'id' => $this->twofaccountOne->id,
|
|
@@ -301,8 +294,8 @@ class GroupServiceTest extends FeatureTestCase
|
|
|
*/
|
|
|
public function test_getAccounts_returns_accounts()
|
|
|
{
|
|
|
- $this->groupService->assign([$this->twofaccountOne->id, $this->twofaccountTwo->id], $this->groupOne);
|
|
|
- $accounts = $this->groupService->getAccounts($this->groupOne);
|
|
|
+ Groups::assign([$this->twofaccountOne->id, $this->twofaccountTwo->id], $this->groupOne);
|
|
|
+ $accounts = Groups::getAccounts($this->groupOne);
|
|
|
|
|
|
$this->assertEquals(2, $accounts->count());
|
|
|
}
|