Browse Source

Add job comments relation

pull/15/head
Nafies Luthfi 7 years ago
parent
commit
5f21b4d8d0
  1. 10
      app/Entities/Projects/Job.php
  2. 1
      app/Providers/AppServiceProvider.php
  3. 14
      tests/Unit/Models/JobTest.php

10
app/Entities/Projects/Job.php

@ -71,6 +71,16 @@ class Job extends Model
}
/**
* Job has many comments relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function comments()
{
return $this->morphMany(Comment::class, 'commentable');
}
/**
* Get the job type.
*
* @return string

1
app/Providers/AppServiceProvider.php

@ -22,6 +22,7 @@ class AppServiceProvider extends ServiceProvider
Relation::morphMap([
'projects' => 'App\Entities\Projects\Project',
'jobs' => 'App\Entities\Projects\Job',
]);
}

14
tests/Unit/Models/JobTest.php

@ -5,6 +5,7 @@ namespace Tests\Unit\Models;
use Tests\TestCase;
use App\Entities\Projects\Job;
use App\Entities\Projects\Task;
use App\Entities\Projects\Comment;
use App\Entities\Projects\Project;
use Illuminate\Support\Collection;
@ -80,4 +81,17 @@ class JobTest extends TestCase
// Job receiveable earning = job tasks average progress (%) * job price
$this->assertEquals(750, $job->receiveable_earning);
}
/** @test */
public function a_job_has_many_comments_relation()
{
$job = factory(Job::class)->create();
$comment = factory(Comment::class)->create([
'commentable_type' => 'jobs',
'commentable_id' => $job->id,
]);
$this->assertInstanceOf(Collection::class, $job->comments);
$this->assertInstanceOf(Comment::class, $job->comments->first());
}
}
Loading…
Cancel
Save