From d140f39c717b4859fca5973e3a726660dd794fd1 Mon Sep 17 00:00:00 2001 From: Farhan Kathawala <37834439+farhaninfyom@users.noreply.github.com> Date: Thu, 26 Sep 2019 13:07:46 +0530 Subject: [PATCH] test: test cases for modal attributes (#398) --- app/Models/TimeEntry.php | 1 + tests/Models/TaskAttachmentTest.php | 33 +++++++++++++++++++++++++++++ tests/Models/TaskTest.php | 22 +++++++++++++++++++ tests/Models/TimeEntryTest.php | 22 +++++++++++++++++++ tests/Models/UserTest.php | 32 ++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 tests/Models/TaskAttachmentTest.php create mode 100644 tests/Models/UserTest.php diff --git a/app/Models/TimeEntry.php b/app/Models/TimeEntry.php index 61d2a1c9a..7fbf40e4b 100644 --- a/app/Models/TimeEntry.php +++ b/app/Models/TimeEntry.php @@ -52,6 +52,7 @@ * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TimeEntry ofCurrentUser() * * @property int $entry_type + * @property-read string $entry_type_string * * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TimeEntry whereEntryType($value) */ diff --git a/tests/Models/TaskAttachmentTest.php b/tests/Models/TaskAttachmentTest.php new file mode 100644 index 000000000..ea8732c49 --- /dev/null +++ b/tests/Models/TaskAttachmentTest.php @@ -0,0 +1,33 @@ +create(); + + $taskAttachment = TaskAttachment::first(); + + $this->assertNotEmpty($taskAttachment->file_path); + $this->assertStringContainsString('attachments', $taskAttachment->file_path); + } + + /** @test */ + public function test_return_attachment_url() + { + $taskAttachment = factory(TaskAttachment::class)->create(); + + $taskAttachment = TaskAttachment::first(); + + $this->assertNotEmpty($taskAttachment->file_url); + } +} diff --git a/tests/Models/TaskTest.php b/tests/Models/TaskTest.php index 8db49582f..96a35cd3d 100644 --- a/tests/Models/TaskTest.php +++ b/tests/Models/TaskTest.php @@ -60,4 +60,26 @@ public function get_task_of_specific_project() $this->assertEquals($task2->id, $firstTask->id); $this->assertEquals($project2->id, $firstTask->project_id); } + + /** @test */ + public function test_return_due_date() + { + $task = factory(Task::class)->create(); + + $task = Task::first(); + + $this->assertNotEmpty($task->due_date); + } + + /** @test */ + public function test_return_task_prefix_number() + { + $task = factory(Task::class)->create(); + + $task = Task::first(); + + $this->assertNotEmpty($task->prefix_task_number); + $taskPrefixNumber = '#'.$task->project->prefix.'-'.$task->task_number; + $this->assertEquals($taskPrefixNumber, $task->prefix_task_number); + } } diff --git a/tests/Models/TimeEntryTest.php b/tests/Models/TimeEntryTest.php index b45a075c5..6cbb3c34b 100644 --- a/tests/Models/TimeEntryTest.php +++ b/tests/Models/TimeEntryTest.php @@ -57,4 +57,26 @@ public function get_time_entry_of_logged_in_user() $this->assertEquals($timeEntry2->id, $firstTimeEntry->id); $this->assertEquals($user2->id, $firstTimeEntry->user_id); } + + /** @test */ + public function test_return_time_entry_type_in_string() + { + $timeEntry = factory(TimeEntry::class)->create(); + + $timeEntry = TimeEntry::first(); + + $this->assertNotEmpty($timeEntry->entry_type_string); + $this->assertEquals('Stopwatch', $timeEntry->entry_type_string); + } + + /** @test */ + public function test_return_time_entry_type_via_form() + { + $timeEntry = factory(TimeEntry::class)->create(['entry_type' => TimeEntry::VIA_FORM]); + + $timeEntry = TimeEntry::first(); + + $this->assertNotEmpty($timeEntry->entry_type_string); + $this->assertEquals('Via Form', $timeEntry->entry_type_string); + } } diff --git a/tests/Models/UserTest.php b/tests/Models/UserTest.php new file mode 100644 index 000000000..558586355 --- /dev/null +++ b/tests/Models/UserTest.php @@ -0,0 +1,32 @@ +create(); + + $user = User::first(); + + $this->assertNotEmpty($user->img_avatar); + } + + /** @test */ + public function test_return_user_image_path() + { + $user = factory(User::class)->create(); + + $user = User::first(); + + $this->assertNotEmpty($user->image_path); + } +}