mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Add project as available include
This commit is contained in:
parent
d0531c19d7
commit
41c26bd032
@ -12,6 +12,7 @@
|
||||
namespace App\Transformers;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Models\Project;
|
||||
use App\Models\Task;
|
||||
use App\Models\TaskStatus;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -33,7 +34,8 @@ class TaskTransformer extends EntityTransformer
|
||||
*/
|
||||
protected $availableIncludes = [
|
||||
'client',
|
||||
'status'
|
||||
'status',
|
||||
'project',
|
||||
];
|
||||
|
||||
public function includeDocuments(Task $task)
|
||||
@ -65,6 +67,16 @@ class TaskTransformer extends EntityTransformer
|
||||
return $this->includeItem($task->status, $transformer, TaskStatus::class);
|
||||
}
|
||||
|
||||
public function includeProject(Task $task): ?Item
|
||||
{
|
||||
$transformer = new ProjectTransformer($this->serializer);
|
||||
|
||||
if (!$task->project) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->includeItem($task->project, $transformer, Project::class);
|
||||
}
|
||||
|
||||
public function transform(Task $task)
|
||||
{
|
||||
|
@ -11,14 +11,15 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Task;
|
||||
use App\Models\Project;
|
||||
use Tests\MockAccountData;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* @test
|
||||
@ -358,6 +359,34 @@ class TaskApiTest extends TestCase
|
||||
$this->assertTrue($this->checkTimeLog($log));
|
||||
}
|
||||
|
||||
public function testTaskListWithProjects()
|
||||
{
|
||||
|
||||
$project = Project::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'company_id' => $this->company->id,
|
||||
'client_id' => $this->client->id,
|
||||
'name' => 'proggy',
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'project_id' => $this->encodePrimaryKey($project->id),
|
||||
'timelog' => [[1,2,'a'],[3,4,'d']],
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/tasks?include=project', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertEquals('proggy', $arr['data']['project']['name']);
|
||||
|
||||
}
|
||||
|
||||
public function testTaskListClientStatus()
|
||||
{
|
||||
$response = $this->withHeaders([
|
||||
|
Loading…
x
Reference in New Issue
Block a user