mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Ensure group settings can be archived + tests!
This commit is contained in:
parent
694ad96111
commit
b780be3995
@ -332,7 +332,7 @@ class CreateTestData extends Command
|
||||
$this->info('Creating '.$this->count. ' clients');
|
||||
|
||||
|
||||
for ($x=0; $x<$this->count*1000; $x++) {
|
||||
for ($x=0; $x<$this->count*500; $x++) {
|
||||
$z = $x+1;
|
||||
$this->info("Creating client # ".$z);
|
||||
|
||||
|
@ -186,6 +186,10 @@ class BaseController extends Controller
|
||||
|
||||
$transformer = new $this->entity_transformer($this->serializer);
|
||||
$updated_at = request()->has('updated_at') ? request()->input('updated_at') : 0;
|
||||
|
||||
if(auth()->user()->getCompany()->is_large && !request()->has('updated_at'))
|
||||
return response()->json(['message' => 'Cannot load a large account without a updated_at parameter','errors' =>[]],401);
|
||||
|
||||
$updated_at = date('Y-m-d H:i:s', $updated_at);
|
||||
|
||||
$query->with(
|
||||
@ -202,8 +206,8 @@ class BaseController extends Controller
|
||||
'company.groups' => function ($query) use($updated_at){
|
||||
$query->where('updated_at', '>=', $updated_at);
|
||||
},
|
||||
'company.company_gateways' => function ($query) use($updated_at){
|
||||
$query->where('updated_at', '>=', $updated_at)->with('gateway');
|
||||
'company.company_gateways' => function ($query){
|
||||
$query->whereNotNull('updated_at');
|
||||
},
|
||||
'company.products' => function ($query) use($updated_at){
|
||||
$query->where('updated_at', '>=', $updated_at);
|
||||
|
@ -21,6 +21,7 @@ use App\Http\Requests\GroupSetting\UpdateGroupSettingRequest;
|
||||
use App\Models\GroupSetting;
|
||||
use App\Repositories\GroupSettingRepository;
|
||||
use App\Transformers\GroupSettingTransformer;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\Uploadable;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Http\Request;
|
||||
@ -29,7 +30,8 @@ class GroupSettingController extends BaseController
|
||||
{
|
||||
use DispatchesJobs;
|
||||
use Uploadable;
|
||||
|
||||
use MakesHash;
|
||||
|
||||
protected $entity_type = GroupSetting::class;
|
||||
|
||||
protected $entity_transformer = GroupSettingTransformer::class;
|
||||
|
95
tests/Feature/GroupSettingTest.php
Normal file
95
tests/Feature/GroupSettingTest.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class GroupSettingTest extends TestCase
|
||||
{
|
||||
use MakesHash;
|
||||
use DatabaseTransactions;
|
||||
use MockAccountData;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Session::start();
|
||||
|
||||
$this->faker = \Faker\Factory::create();
|
||||
|
||||
Model::reguard();
|
||||
|
||||
$this->makeTestData();
|
||||
}
|
||||
|
||||
public function testAddGroupSettings()
|
||||
{
|
||||
$settings = new \stdClass;
|
||||
$settings->currency_id = 1;
|
||||
|
||||
$data = [
|
||||
'name' => 'test',
|
||||
'settings' => $settings
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/group_settings', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertEquals('test', $arr['data']['name']);
|
||||
$this->assertEquals(0, $arr['data']['archived_at']);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testArchiveGroupSettings()
|
||||
{
|
||||
$settings = new \stdClass;
|
||||
$settings->currency_id = 1;
|
||||
|
||||
$data = [
|
||||
'name' => 'test',
|
||||
'settings' => $settings
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/group_settings', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$data = [
|
||||
'action' => 'archive',
|
||||
'ids' => [$arr['data']['id']]
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/group_settings/bulk', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertNotNull($arr['data']['archived_at']);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user