From af7da72fac10c30b8d70b036f71029113291e1d4 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sat, 20 Oct 2018 00:36:17 +0200 Subject: [PATCH 01/16] Add api tests --- tests/Api/ApiGiftsTest.php | 68 ++++++++- tests/Api/ApiTagsTest.php | 282 +++++++++++++++++++++++++++++++++++++ tests/Api/ApiTasksTest.php | 281 ++++++++++++++++++++++++++++++++++++ 3 files changed, 624 insertions(+), 7 deletions(-) create mode 100644 tests/Api/ApiTagsTest.php create mode 100644 tests/Api/ApiTasksTest.php diff --git a/tests/Api/ApiGiftsTest.php b/tests/Api/ApiGiftsTest.php index e7b307209c5..3a5ae1834dc 100644 --- a/tests/Api/ApiGiftsTest.php +++ b/tests/Api/ApiGiftsTest.php @@ -4,6 +4,7 @@ use Tests\ApiTestCase; use App\Models\Contact\Gift; +use App\Models\Account\Account; use App\Models\Contact\Contact; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -32,7 +33,7 @@ class ApiGiftsTest extends ApiTestCase 'updated_at', ]; - public function test_gift_get_all_gifts() + public function test_gifts_get_all_gifts() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -66,7 +67,7 @@ public function test_gift_get_all_gifts() ]); } - public function test_gift_get_contact_all_gifts() + public function test_gifts_get_contact_all_gifts() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -100,7 +101,7 @@ public function test_gift_get_contact_all_gifts() ]); } - public function test_gift_get_one_gift() + public function test_gifts_get_one_gift() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -131,7 +132,21 @@ public function test_gift_get_one_gift() ]); } - public function test_gift_create_gift() + public function test_gifts_get_one_gift_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/gifts/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31 + ] + ]); + } + + public function test_gifts_create_gift() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -139,7 +154,6 @@ public function test_gift_create_gift() ]); $response = $this->json('POST', '/api/gifts', [ - 'account_id' => $user->account->id, 'contact_id' => $contact->id, 'name' => 'the gift', ]); @@ -163,7 +177,47 @@ public function test_gift_create_gift() ]); } - public function test_gift_update_gift() + public function test_gifts_create_gift_error() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('POST', '/api/gifts', [ + 'contact_id' => $contact->id, + ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32 + ] + ]); + } + + public function test_gifts_create_gift_error_bad_account() + { + $user = $this->signin(); + + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create([ + 'account_id' => $account->id, + ]); + + $response = $this->json('POST', '/api/gifts', [ + 'contact_id' => $contact->id, + ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32 + ] + ]); + } + + public function test_gifts_update_gift() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -201,7 +255,7 @@ public function test_gift_update_gift() ]); } - public function test_gift_delete_gift() + public function test_gifts_delete_gift() { $user = $this->signin(); $contact = factory(Contact::class)->create([ diff --git a/tests/Api/ApiTagsTest.php b/tests/Api/ApiTagsTest.php new file mode 100644 index 00000000000..3fb81e117b4 --- /dev/null +++ b/tests/Api/ApiTagsTest.php @@ -0,0 +1,282 @@ + [ + 'id', + ], + 'created_at', + 'updated_at', + ]; + + public function test_tags_get_all_tags() + { + $user = $this->signin(); + $tag1 = factory(Tag::class)->create([ + 'account_id' => $user->account->id, + ]); + $tag2 = factory(Tag::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('GET', '/api/tags'); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => ['*' => $this->jsonTag], + ]); + $response->assertJsonFragment([ + 'object' => 'tag', + 'id' => $tag1->id, + ]); + $response->assertJsonFragment([ + 'object' => 'tag', + 'id' => $tag2->id, + ]); + } + + public function test_tags_get_one_tag() + { + $user = $this->signin(); + $tag1 = factory(Tag::class)->create([ + 'account_id' => $user->account->id, + ]); + $tag2 = factory(Tag::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('GET', '/api/tags/'.$tag1->id); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonTag, + ]); + $response->assertJsonFragment([ + 'object' => 'tag', + 'id' => $tag1->id, + ]); + $response->assertJsonMissingExact([ + 'object' => 'tag', + 'id' => $tag2->id, + ]); + } + + public function test_tags_get_one_tag_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/tags/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31 + ] + ]); + } + + public function test_tags_create_tag() + { + $user = $this->signin(); + + $response = $this->json('POST', '/api/tags', [ + 'name' => 'the tag', + ]); + + $response->assertStatus(201); + $response->assertJsonStructure([ + 'data' => $this->jsonTag, + ]); + $tag_id = $response->json('data.id'); + $response->assertJsonFragment([ + 'object' => 'tag', + 'id' => $tag_id, + 'name' => 'the tag', + ]); + + $this->assertGreaterThan(0, $tag_id); + $this->assertDatabaseHas('tags', [ + 'account_id' => $user->account->id, + 'name' => 'the tag', + 'id' => $tag_id, + ]); + } + + public function test_tags_create_tag_error() + { + $user = $this->signin(); + + $response = $this->json('POST', '/api/tags', []); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32 + ] + ]); + } + + public function test_tags_update_tag() + { + $user = $this->signin(); + $tag = factory(Tag::class)->create([ + 'account_id' => $user->account->id, + 'name' => 'old name' + ]); + + $response = $this->json('PUT', '/api/tags/'.$tag->id, [ + 'name' => 'the tag', + ]); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonTag, + ]); + $tag_id = $response->json('data.id'); + $this->assertEquals($tag->id, $tag_id); + $response->assertJsonFragment([ + 'object' => 'tag', + 'id' => $tag_id, + 'name' => 'the tag', + ]); + + $this->assertGreaterThan(0, $tag_id); + $this->assertDatabaseHas('tags', [ + 'account_id' => $user->account->id, + 'name' => 'the tag', + 'id' => $tag_id, + ]); + } + + public function test_tags_delete_tag() + { + $user = $this->signin(); + $tag = factory(Tag::class)->create([ + 'account_id' => $user->account->id, + ]); + $this->assertDatabaseHas('tags', [ + 'account_id' => $user->account->id, + 'id' => $tag->id, + ]); + + $response = $this->json('DELETE', '/api/tags/'.$tag->id); + + $response->assertStatus(200); + $this->assertDatabaseMissing('tags', [ + 'account_id' => $user->account->id, + 'id' => $tag->id, + ]); + } + + public function test_tags_associate_contact() + { + $user = $this->signin(); + $tag = factory(Tag::class)->create([ + 'account_id' => $user->account->id, + ]); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('POST', '/api/contacts/'.$contact->id.'/setTags', [ + 'tags' => ['tag1', 'tag2'] + ]); + + $response->assertStatus(200); + $tag_id1 = $response->json('data.tags.0.id'); + $tag_id2 = $response->json('data.tags.1.id'); + + $response->assertJsonFragment([ + 'object' => 'tag', + 'name' => 'tag1', + 'id' => $tag_id1 + ]); + $response->assertJsonFragment([ + 'object' => 'tag', + 'name' => 'tag2', + 'id' => $tag_id2 + ]); + + $this->assertDatabaseHas('contact_tag', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'tag_id' => $tag_id1, + ]); + $this->assertDatabaseHas('contact_tag', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'tag_id' => $tag_id2, + ]); + } + + public function test_tags_unset_contact_tag() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $tag = $contact->setTag('a tag'); + + $this->assertDatabaseHas('contact_tag', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'tag_id' => $tag->id, + ]); + + $response = $this->json('POST', '/api/contacts/'.$contact->id.'/unsetTag', [ + 'tags' => [$tag->id] + ]); + + $response->assertStatus(200); + + $this->assertDatabaseMissing('contact_tag', [ + 'contact_id' => $contact->id, + 'tag_id' => $tag->id, + 'account_id' => $user->account->id, + ]); + } + + public function test_tags_unset_contact_tags() + { + $user = $this->signin(); + $tag1 = factory(Tag::class)->create([ + 'account_id' => $user->account->id, + ]); + $tag2 = factory(Tag::class)->create([ + 'account_id' => $user->account->id, + ]); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $contact->setTag($tag1); + $contact->setTag($tag2); + + $response = $this->json('POST', '/api/contacts/'.$contact->id.'/unsetTags'); + + $this->assertDatabaseMissing('contact_tag', [ + 'contact_id' => $contact->id, + 'tag_id' => $tag1->id, + 'account_id' => $user->account->id, + ]); + $this->assertDatabaseMissing('contact_tag', [ + 'contact_id' => $contact->id, + 'tag_id' => $tag2->id, + 'account_id' => $user->account->id, + ]); + } +} diff --git a/tests/Api/ApiTasksTest.php b/tests/Api/ApiTasksTest.php new file mode 100644 index 00000000000..3c6813dd9de --- /dev/null +++ b/tests/Api/ApiTasksTest.php @@ -0,0 +1,281 @@ + [ + 'id', + ], + 'contact' => [ + 'id', + ], + 'created_at', + 'updated_at', + ]; + + public function test_tasks_get_all_tasks() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $task1 = factory(Task::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $contact2 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $task2 = factory(Task::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact2->id, + ]); + + $response = $this->json('GET', '/api/tasks'); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => ['*' => $this->jsonTask], + ]); + $response->assertJsonFragment([ + 'object' => 'task', + 'id' => $task1->id, + ]); + $response->assertJsonFragment([ + 'object' => 'task', + 'id' => $task2->id, + ]); + } + + public function test_tasks_get_contact_all_tasks() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $task1 = factory(Task::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $contact2 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $task2 = factory(Task::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact2->id, + ]); + + $response = $this->json('GET', '/api/contacts/'.$contact1->id.'/tasks'); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => ['*' => $this->jsonTask], + ]); + $response->assertJsonFragment([ + 'object' => 'task', + 'id' => $task1->id, + ]); + $response->assertJsonMissingExact([ + 'object' => 'task', + 'id' => $task2->id, + ]); + } + + public function test_tasks_get_one_task() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $task1 = factory(Task::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $task2 = factory(Task::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + + $response = $this->json('GET', '/api/tasks/'.$task1->id); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonTask, + ]); + $response->assertJsonFragment([ + 'object' => 'task', + 'id' => $task1->id, + ]); + $response->assertJsonMissingExact([ + 'object' => 'task', + 'id' => $task2->id, + ]); + } + + public function test_tasks_get_one_task_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/tasks/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31 + ] + ]); + } + + public function test_tasks_create_task() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('POST', '/api/tasks', [ + 'contact_id' => $contact->id, + 'title' => 'the task', + 'completed' => false, + ]); + + $response->assertStatus(201); + $response->assertJsonStructure([ + 'data' => $this->jsonTask, + ]); + $task_id = $response->json('data.id'); + $response->assertJsonFragment([ + 'object' => 'task', + 'id' => $task_id, + ]); + + $this->assertGreaterThan(0, $task_id); + $this->assertDatabaseHas('tasks', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'title' => 'the task', + 'completed' => false, + 'id' => $task_id, + ]); + } + + public function test_tasks_create_task_error() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('POST', '/api/tasks', [ + 'contact_id' => $contact->id, + ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32 + ] + ]); + } + + public function test_tasks_create_task_error_bad_account() + { + $user = $this->signin(); + + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create([ + 'account_id' => $account->id, + ]); + + $response = $this->json('POST', '/api/tasks', [ + 'contact_id' => $contact->id, + ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32 + ] + ]); + } + + public function test_tasks_update_task() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $task = factory(Task::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + + $response = $this->json('PUT', '/api/tasks/'.$task->id, [ + 'contact_id' => $contact->id, + 'title' => 'the task', + 'completed' => false, + ]); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonTask, + ]); + $task_id = $response->json('data.id'); + $this->assertEquals($task->id, $task_id); + $response->assertJsonFragment([ + 'object' => 'task', + 'id' => $task_id, + ]); + + $this->assertGreaterThan(0, $task_id); + $this->assertDatabaseHas('tasks', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'title' => 'the task', + 'completed' => false, + 'id' => $task_id, + ]); + } + + public function test_tasks_delete_task() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $task = factory(Task::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + $this->assertDatabaseHas('tasks', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $task->id, + ]); + + $response = $this->json('DELETE', '/api/tasks/'.$task->id); + + $response->assertStatus(200); + $this->assertDatabaseMissing('tasks', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $task->id, + ]); + } +} From cbc7ecb7a42fee49c1df3859b73977b59688d9d6 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Fri, 19 Oct 2018 22:36:31 +0000 Subject: [PATCH 02/16] Apply fixes from StyleCI --- tests/Api/ApiGiftsTest.php | 12 ++++++------ tests/Api/ApiTagsTest.php | 18 +++++++++--------- tests/Api/ApiTasksTest.php | 12 ++++++------ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/Api/ApiGiftsTest.php b/tests/Api/ApiGiftsTest.php index 3a5ae1834dc..f68f9407253 100644 --- a/tests/Api/ApiGiftsTest.php +++ b/tests/Api/ApiGiftsTest.php @@ -141,8 +141,8 @@ public function test_gifts_get_one_gift_error() $response->assertStatus(404); $response->assertJson([ 'error' => [ - 'error_code' => 31 - ] + 'error_code' => 31, + ], ]); } @@ -191,8 +191,8 @@ public function test_gifts_create_gift_error() $response->assertStatus(200); $response->assertJson([ 'error' => [ - 'error_code' => 32 - ] + 'error_code' => 32, + ], ]); } @@ -212,8 +212,8 @@ public function test_gifts_create_gift_error_bad_account() $response->assertStatus(200); $response->assertJson([ 'error' => [ - 'error_code' => 32 - ] + 'error_code' => 32, + ], ]); } diff --git a/tests/Api/ApiTagsTest.php b/tests/Api/ApiTagsTest.php index 3fb81e117b4..438d65151d2 100644 --- a/tests/Api/ApiTagsTest.php +++ b/tests/Api/ApiTagsTest.php @@ -85,8 +85,8 @@ public function test_tags_get_one_tag_error() $response->assertStatus(404); $response->assertJson([ 'error' => [ - 'error_code' => 31 - ] + 'error_code' => 31, + ], ]); } @@ -126,8 +126,8 @@ public function test_tags_create_tag_error() $response->assertStatus(200); $response->assertJson([ 'error' => [ - 'error_code' => 32 - ] + 'error_code' => 32, + ], ]); } @@ -136,7 +136,7 @@ public function test_tags_update_tag() $user = $this->signin(); $tag = factory(Tag::class)->create([ 'account_id' => $user->account->id, - 'name' => 'old name' + 'name' => 'old name', ]); $response = $this->json('PUT', '/api/tags/'.$tag->id, [ @@ -194,7 +194,7 @@ public function test_tags_associate_contact() ]); $response = $this->json('POST', '/api/contacts/'.$contact->id.'/setTags', [ - 'tags' => ['tag1', 'tag2'] + 'tags' => ['tag1', 'tag2'], ]); $response->assertStatus(200); @@ -204,12 +204,12 @@ public function test_tags_associate_contact() $response->assertJsonFragment([ 'object' => 'tag', 'name' => 'tag1', - 'id' => $tag_id1 + 'id' => $tag_id1, ]); $response->assertJsonFragment([ 'object' => 'tag', 'name' => 'tag2', - 'id' => $tag_id2 + 'id' => $tag_id2, ]); $this->assertDatabaseHas('contact_tag', [ @@ -239,7 +239,7 @@ public function test_tags_unset_contact_tag() ]); $response = $this->json('POST', '/api/contacts/'.$contact->id.'/unsetTag', [ - 'tags' => [$tag->id] + 'tags' => [$tag->id], ]); $response->assertStatus(200); diff --git a/tests/Api/ApiTasksTest.php b/tests/Api/ApiTasksTest.php index 3c6813dd9de..9eb8155df99 100644 --- a/tests/Api/ApiTasksTest.php +++ b/tests/Api/ApiTasksTest.php @@ -137,8 +137,8 @@ public function test_tasks_get_one_task_error() $response->assertStatus(404); $response->assertJson([ 'error' => [ - 'error_code' => 31 - ] + 'error_code' => 31, + ], ]); } @@ -189,8 +189,8 @@ public function test_tasks_create_task_error() $response->assertStatus(200); $response->assertJson([ 'error' => [ - 'error_code' => 32 - ] + 'error_code' => 32, + ], ]); } @@ -210,8 +210,8 @@ public function test_tasks_create_task_error_bad_account() $response->assertStatus(200); $response->assertJson([ 'error' => [ - 'error_code' => 32 - ] + 'error_code' => 32, + ], ]); } From 927ba4a3097681a6bdc5b70ad888175d7295f6e8 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sat, 20 Oct 2018 15:28:32 +0200 Subject: [PATCH 03/16] More tests --- tests/Api/ApiCallsTest.php | 279 ++++++++++++++++++++++++++++++++ tests/Api/ApiDebtsTest.php | 299 +++++++++++++++++++++++++++++++++++ tests/Api/ApiGiftsTest.php | 4 +- tests/Api/ApiJournalTest.php | 190 ++++++++++++++++++++++ tests/Api/ApiNotesTest.php | 284 +++++++++++++++++++++++++++++++++ tests/Api/ApiTagsTest.php | 8 +- tests/Api/ApiTasksTest.php | 4 +- 7 files changed, 1060 insertions(+), 8 deletions(-) create mode 100644 tests/Api/ApiCallsTest.php create mode 100644 tests/Api/ApiDebtsTest.php create mode 100644 tests/Api/ApiJournalTest.php create mode 100644 tests/Api/ApiNotesTest.php diff --git a/tests/Api/ApiCallsTest.php b/tests/Api/ApiCallsTest.php new file mode 100644 index 00000000000..8c7b0804998 --- /dev/null +++ b/tests/Api/ApiCallsTest.php @@ -0,0 +1,279 @@ + [ + 'id', + ], + 'contact' => [ + 'id', + ], + 'created_at', + 'updated_at', + ]; + + public function test_calls_get_all_calls() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $call1 = factory(Call::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $contact2 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $call2 = factory(Call::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact2->id, + ]); + + $response = $this->json('GET', '/api/calls'); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => ['*' => $this->jsonCall], + ]); + $response->assertJsonFragment([ + 'object' => 'call', + 'id' => $call1->id, + ]); + $response->assertJsonFragment([ + 'object' => 'call', + 'id' => $call2->id, + ]); + } + + public function test_calls_get_contact_all_calls() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $call1 = factory(Call::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $contact2 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $call2 = factory(Call::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact2->id, + ]); + + $response = $this->json('GET', '/api/contacts/'.$contact1->id.'/calls'); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => ['*' => $this->jsonCall], + ]); + $response->assertJsonFragment([ + 'object' => 'call', + 'id' => $call1->id, + ]); + $response->assertJsonMissingExact([ + 'object' => 'call', + 'id' => $call2->id, + ]); + } + + public function test_calls_get_one_call() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $call1 = factory(Call::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $call2 = factory(Call::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + + $response = $this->json('GET', '/api/calls/'.$call1->id); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonCall, + ]); + $response->assertJsonFragment([ + 'object' => 'call', + 'id' => $call1->id, + ]); + $response->assertJsonMissingExact([ + 'object' => 'call', + 'id' => $call2->id, + ]); + } + + public function test_calls_get_one_call_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/calls/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_calls_create_call() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('POST', '/api/calls', [ + 'contact_id' => $contact->id, + 'content' => 'the call', + 'called_at' => '2018-05-01', + ]); + + $response->assertStatus(201); + $response->assertJsonStructure([ + 'data' => $this->jsonCall, + ]); + $call_id = $response->json('data.id'); + $response->assertJsonFragment([ + 'object' => 'call', + 'id' => $call_id, + ]); + + $this->assertGreaterThan(0, $call_id); + $this->assertDatabaseHas('calls', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $call_id, + 'content' => 'the call', + 'called_at' => '2018-05-01', + ]); + } + + public function test_calls_create_call_error() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('POST', '/api/calls', [ + 'contact_id' => $contact->id, + ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32, + ], + ]); + } + + public function test_calls_create_call_error_bad_account() + { + $user = $this->signin(); + + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create([ + 'account_id' => $account->id, + ]); + + $response = $this->json('POST', '/api/calls', [ + 'contact_id' => $contact->id, + ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32, + ], + ]); + } + + public function test_calls_update_call() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $call = factory(Call::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + + $response = $this->json('PUT', '/api/calls/'.$call->id, [ + 'contact_id' => $contact->id, + 'content' => 'the call', + 'called_at' => '2018-05-01', + ]); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonCall, + ]); + $call_id = $response->json('data.id'); + $this->assertEquals($call->id, $call_id); + $response->assertJsonFragment([ + 'object' => 'call', + 'id' => $call_id, + ]); + + $this->assertGreaterThan(0, $call_id); + $this->assertDatabaseHas('calls', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $call_id, + 'content' => 'the call', + 'called_at' => '2018-05-01', + ]); + } + + public function test_calls_delete_call() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $call = factory(Call::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + $this->assertDatabaseHas('calls', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $call->id, + ]); + + $response = $this->json('DELETE', '/api/calls/'.$call->id); + + $response->assertStatus(200); + $this->assertDatabaseMissing('calls', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $call->id, + ]); + } +} diff --git a/tests/Api/ApiDebtsTest.php b/tests/Api/ApiDebtsTest.php new file mode 100644 index 00000000000..c844b78e909 --- /dev/null +++ b/tests/Api/ApiDebtsTest.php @@ -0,0 +1,299 @@ + [ + 'id', + ], + 'contact' => [ + 'id', + ], + 'created_at', + 'updated_at', + ]; + + public function test_debts_get_all_debts() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $debt1 = factory(Debt::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $contact2 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $debt2 = factory(Debt::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact2->id, + ]); + + $response = $this->json('GET', '/api/debts'); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => ['*' => $this->jsonDebt], + ]); + $response->assertJsonFragment([ + 'object' => 'debt', + 'id' => $debt1->id, + ]); + $response->assertJsonFragment([ + 'object' => 'debt', + 'id' => $debt2->id, + ]); + } + + public function test_debts_get_contact_all_debts() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $debt1 = factory(Debt::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $contact2 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $debt2 = factory(Debt::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact2->id, + ]); + + $response = $this->json('GET', '/api/contacts/'.$contact1->id.'/debts'); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => ['*' => $this->jsonDebt], + ]); + $response->assertJsonFragment([ + 'object' => 'debt', + 'id' => $debt1->id, + ]); + $response->assertJsonMissingExact([ + 'object' => 'debt', + 'id' => $debt2->id, + ]); + } + + public function test_debts_get_one_debt() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $debt1 = factory(Debt::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $debt2 = factory(Debt::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + + $response = $this->json('GET', '/api/debts/'.$debt1->id); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonDebt, + ]); + $response->assertJsonFragment([ + 'object' => 'debt', + 'id' => $debt1->id, + ]); + $response->assertJsonMissingExact([ + 'object' => 'debt', + 'id' => $debt2->id, + ]); + } + + public function test_debts_get_one_debt_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/debts/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_debts_create_debt() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('POST', '/api/debts', [ + 'contact_id' => $contact->id, + 'in_debt' => true, + 'status' => 'inprogress', + 'amount' => 42, + 'reason' => 'that\'s why' + ]); + + $response->assertStatus(201); + $response->assertJsonStructure([ + 'data' => $this->jsonDebt, + ]); + $debt_id = $response->json('data.id'); + $response->assertJsonFragment([ + 'object' => 'debt', + 'id' => $debt_id, + 'in_debt' => true, + 'status' => 'inprogress', + 'amount' => 42, + 'amount_with_currency' => '$42', + 'reason' => 'that\'s why' + ]); + + $this->assertGreaterThan(0, $debt_id); + $this->assertDatabaseHas('debts', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $debt_id, + 'in_debt' => true, + 'status' => 'inprogress', + 'amount' => 42, + 'reason' => 'that\'s why' + ]); + } + + public function test_debts_create_debt_error() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('POST', '/api/debts', [ + 'contact_id' => $contact->id, + ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32, + ], + ]); + } + + public function test_debts_create_debt_error_bad_account() + { + $user = $this->signin(); + + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create([ + 'account_id' => $account->id, + ]); + + $response = $this->json('POST', '/api/debts', [ + 'contact_id' => $contact->id, + ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32, + ], + ]); + } + + public function test_debts_update_debt() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $debt = factory(Debt::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + + $response = $this->json('PUT', '/api/debts/'.$debt->id, [ + 'contact_id' => $contact->id, + 'in_debt' => true, + 'status' => 'complete', + 'amount' => 142, + 'reason' => 'voilà' + ]); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonDebt, + ]); + $debt_id = $response->json('data.id'); + $this->assertEquals($debt->id, $debt_id); + $response->assertJsonFragment([ + 'object' => 'debt', + 'id' => $debt_id, + 'in_debt' => true, + 'status' => 'complete', + 'amount' => 142, + 'reason' => 'voilà' + ]); + + $this->assertGreaterThan(0, $debt_id); + $this->assertDatabaseHas('debts', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $debt_id, + 'in_debt' => true, + 'status' => 'complete', + 'amount' => 142, + 'reason' => 'voilà' + ]); + } + + public function test_debts_delete_debt() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $debt = factory(Debt::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + $this->assertDatabaseHas('debts', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $debt->id, + ]); + + $response = $this->json('DELETE', '/api/debts/'.$debt->id); + + $response->assertStatus(200); + $this->assertDatabaseMissing('debts', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $debt->id, + ]); + } +} diff --git a/tests/Api/ApiGiftsTest.php b/tests/Api/ApiGiftsTest.php index f68f9407253..52c39c182e4 100644 --- a/tests/Api/ApiGiftsTest.php +++ b/tests/Api/ApiGiftsTest.php @@ -172,8 +172,8 @@ public function test_gifts_create_gift() $this->assertDatabaseHas('gifts', [ 'account_id' => $user->account->id, 'contact_id' => $contact->id, - 'name' => 'the gift', 'id' => $gift_id, + 'name' => 'the gift', ]); } @@ -249,9 +249,9 @@ public function test_gifts_update_gift() $this->assertDatabaseHas('gifts', [ 'account_id' => $user->account->id, 'contact_id' => $contact->id, + 'id' => $gift_id, 'name' => 'the gift', 'comment' => 'one comment', - 'id' => $gift_id, ]); } diff --git a/tests/Api/ApiJournalTest.php b/tests/Api/ApiJournalTest.php new file mode 100644 index 00000000000..73798cadc6c --- /dev/null +++ b/tests/Api/ApiJournalTest.php @@ -0,0 +1,190 @@ + [ + 'id', + ], + 'created_at', + 'updated_at', + ]; + + public function test_journal_get_all_journal() + { + $user = $this->signin(); + $journal_entry1 = factory(JournalEntry::class)->create([ + 'account_id' => $user->account->id, + ]); + $journal_entry2 = factory(JournalEntry::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('GET', '/api/journal'); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => ['*' => $this->jsonJournal], + ]); + $response->assertJsonFragment([ + 'object' => 'journal', + 'id' => $journal_entry1->id, + ]); + $response->assertJsonFragment([ + 'object' => 'journal', + 'id' => $journal_entry2->id, + ]); + } + + public function test_journal_get_one_journal() + { + $user = $this->signin(); + $journal_entry1 = factory(JournalEntry::class)->create([ + 'account_id' => $user->account->id, + ]); + $journal_entry2 = factory(JournalEntry::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('GET', '/api/journal/'.$journal_entry1->id); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonJournal, + ]); + $response->assertJsonFragment([ + 'object' => 'journal', + 'id' => $journal_entry1->id, + ]); + $response->assertJsonMissingExact([ + 'object' => 'journal', + 'id' => $journal_entry2->id, + ]); + } + + public function test_journal_get_one_journal_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/journal/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_journal_create_journal() + { + $user = $this->signin(); + + $response = $this->json('POST', '/api/journal', [ + 'title' => 'my title', + 'post' => 'content post' + ]); + + $response->assertStatus(201); + $response->assertJsonStructure([ + 'data' => $this->jsonJournal, + ]); + $journal_entry_id = $response->json('data.id'); + $response->assertJsonFragment([ + 'object' => 'journal', + 'id' => $journal_entry_id, + 'title' => 'my title', + 'post' => 'content post' + ]); + + $this->assertGreaterThan(0, $journal_entry_id); + $this->assertDatabaseHas('journal', [ + 'account_id' => $user->account->id, + 'id' => $journal_entry_id, + 'title' => 'my title', + 'post' => 'content post' + ]); + } + + public function test_journal_create_journal_error() + { + $user = $this->signin(); + + $response = $this->json('POST', '/api/journal', []); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32, + ], + ]); + } + + public function test_journal_update_journal() + { + $user = $this->signin(); + $journal_entry = factory(JournalEntry::class)->create([ + 'account_id' => $user->account->id, + 'title' => 'xxx', + ]); + + $response = $this->json('PUT', '/api/journal/'.$journal_entry->id, [ + 'title' => 'my title', + 'post' => 'content post' + ]); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonJournal, + ]); + $journal_entry_id = $response->json('data.id'); + $this->assertEquals($journal_entry->id, $journal_entry_id); + $response->assertJsonFragment([ + 'object' => 'journal', + 'id' => $journal_entry_id, + 'title' => 'my title', + 'post' => 'content post' + ]); + + $this->assertGreaterThan(0, $journal_entry_id); + $this->assertDatabaseHas('journal_entry', [ + 'account_id' => $user->account->id, + 'id' => $journal_entry_id, + 'title' => 'my title', + 'post' => 'content post' + ]); + } + + public function test_journal_delete_journal() + { + $user = $this->signin(); + $journal_entry = factory(JournalEntry::class)->create([ + 'account_id' => $user->account->id, + ]); + $this->assertDatabaseHas('journal', [ + 'account_id' => $user->account->id, + 'id' => $journal_entry->id, + ]); + + $response = $this->json('DELETE', '/api/journal/'.$journal_entry->id); + + $response->assertStatus(200); + $this->assertDatabaseMissing('journal', [ + 'account_id' => $user->account->id, + 'id' => $journal_entry->id, + ]); + } +} diff --git a/tests/Api/ApiNotesTest.php b/tests/Api/ApiNotesTest.php new file mode 100644 index 00000000000..e26ef9180ad --- /dev/null +++ b/tests/Api/ApiNotesTest.php @@ -0,0 +1,284 @@ + [ + 'id', + ], + 'contact' => [ + 'id', + ], + 'created_at', + 'updated_at', + ]; + + public function test_notes_get_all_notes() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $note1 = factory(Note::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $contact2 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $note2 = factory(Note::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact2->id, + ]); + + $response = $this->json('GET', '/api/notes'); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => ['*' => $this->jsonNote], + ]); + $response->assertJsonFragment([ + 'object' => 'note', + 'id' => $note1->id, + ]); + $response->assertJsonFragment([ + 'object' => 'note', + 'id' => $note2->id, + ]); + } + + public function test_notes_get_contact_all_notes() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $note1 = factory(Note::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $contact2 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $note2 = factory(Note::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact2->id, + ]); + + $response = $this->json('GET', '/api/contacts/'.$contact1->id.'/notes'); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => ['*' => $this->jsonNote], + ]); + $response->assertJsonFragment([ + 'object' => 'note', + 'id' => $note1->id, + ]); + $response->assertJsonMissingExact([ + 'object' => 'note', + 'id' => $note2->id, + ]); + } + + public function test_notes_get_one_note() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $note1 = factory(Note::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $note2 = factory(Note::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + + $response = $this->json('GET', '/api/notes/'.$note1->id); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonNote, + ]); + $response->assertJsonFragment([ + 'object' => 'note', + 'id' => $note1->id, + ]); + $response->assertJsonMissingExact([ + 'object' => 'note', + 'id' => $note2->id, + ]); + } + + public function test_notes_get_one_note_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/notes/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_notes_create_note() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('POST', '/api/notes', [ + 'contact_id' => $contact->id, + 'body' => 'the body of the note', + 'is_favorited' => false, + ]); + + $response->assertStatus(201); + $response->assertJsonStructure([ + 'data' => $this->jsonNote, + ]); + $note_id = $response->json('data.id'); + $response->assertJsonFragment([ + 'object' => 'note', + 'id' => $note_id, + 'body' => 'the body of the note', + 'is_favorited' => false, + ]); + + $this->assertGreaterThan(0, $note_id); + $this->assertDatabaseHas('notes', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $note_id, + 'body' => 'the body of the note', + 'is_favorited' => false, + ]); + } + + public function test_notes_create_note_error() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('POST', '/api/notes', [ + 'contact_id' => $contact->id, + ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32, + ], + ]); + } + + public function test_notes_create_note_error_bad_account() + { + $user = $this->signin(); + + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create([ + 'account_id' => $account->id, + ]); + + $response = $this->json('POST', '/api/notes', [ + 'contact_id' => $contact->id, + ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32, + ], + ]); + } + + public function test_notes_update_note() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $note = factory(Note::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + + $response = $this->json('PUT', '/api/notes/'.$note->id, [ + 'contact_id' => $contact->id, + 'body' => 'the body of the note', + 'is_favorited' => false, + ]); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonNote, + ]); + $note_id = $response->json('data.id'); + $this->assertEquals($note->id, $note_id); + $response->assertJsonFragment([ + 'object' => 'note', + 'id' => $note_id, + 'body' => 'the body of the note', + 'is_favorited' => false, + ]); + + $this->assertGreaterThan(0, $note_id); + $this->assertDatabaseHas('notes', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $note_id, + 'body' => 'the body of the note', + 'is_favorited' => false, + ]); + } + + public function test_notes_delete_note() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $note = factory(Note::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + $this->assertDatabaseHas('notes', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $note->id, + ]); + + $response = $this->json('DELETE', '/api/notes/'.$note->id); + + $response->assertStatus(200); + $this->assertDatabaseMissing('notes', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $note->id, + ]); + } +} diff --git a/tests/Api/ApiTagsTest.php b/tests/Api/ApiTagsTest.php index 438d65151d2..90f2ad5786a 100644 --- a/tests/Api/ApiTagsTest.php +++ b/tests/Api/ApiTagsTest.php @@ -112,8 +112,8 @@ public function test_tags_create_tag() $this->assertGreaterThan(0, $tag_id); $this->assertDatabaseHas('tags', [ 'account_id' => $user->account->id, - 'name' => 'the tag', 'id' => $tag_id, + 'name' => 'the tag', ]); } @@ -158,8 +158,8 @@ public function test_tags_update_tag() $this->assertGreaterThan(0, $tag_id); $this->assertDatabaseHas('tags', [ 'account_id' => $user->account->id, - 'name' => 'the tag', 'id' => $tag_id, + 'name' => 'the tag', ]); } @@ -203,13 +203,13 @@ public function test_tags_associate_contact() $response->assertJsonFragment([ 'object' => 'tag', - 'name' => 'tag1', 'id' => $tag_id1, + 'name' => 'tag1', ]); $response->assertJsonFragment([ 'object' => 'tag', - 'name' => 'tag2', 'id' => $tag_id2, + 'name' => 'tag2', ]); $this->assertDatabaseHas('contact_tag', [ diff --git a/tests/Api/ApiTasksTest.php b/tests/Api/ApiTasksTest.php index 9eb8155df99..528919f9e3b 100644 --- a/tests/Api/ApiTasksTest.php +++ b/tests/Api/ApiTasksTest.php @@ -169,9 +169,9 @@ public function test_tasks_create_task() $this->assertDatabaseHas('tasks', [ 'account_id' => $user->account->id, 'contact_id' => $contact->id, + 'id' => $task_id, 'title' => 'the task', 'completed' => false, - 'id' => $task_id, ]); } @@ -247,9 +247,9 @@ public function test_tasks_update_task() $this->assertDatabaseHas('tasks', [ 'account_id' => $user->account->id, 'contact_id' => $contact->id, + 'id' => $task_id, 'title' => 'the task', 'completed' => false, - 'id' => $task_id, ]); } From c1276905ee1d6142d32c26c4f085aafd06286f0d Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 21 Oct 2018 02:12:36 +0200 Subject: [PATCH 04/16] wip --- tests/Api/ApiDebtsTest.php | 30 +++++++++------ tests/Api/ApiJournalTest.php | 73 ++++++++++++++++++------------------ tests/Api/ApiNotesTest.php | 2 +- 3 files changed, 57 insertions(+), 48 deletions(-) diff --git a/tests/Api/ApiDebtsTest.php b/tests/Api/ApiDebtsTest.php index c844b78e909..b0d6e8fe1c2 100644 --- a/tests/Api/ApiDebtsTest.php +++ b/tests/Api/ApiDebtsTest.php @@ -6,6 +6,7 @@ use App\Models\Contact\Debt; use App\Models\Account\Account; use App\Models\Contact\Contact; +use App\Models\Settings\Currency; use Illuminate\Foundation\Testing\DatabaseTransactions; class ApiDebtsTest extends ApiTestCase @@ -17,7 +18,7 @@ class ApiDebtsTest extends ApiTestCase 'object', 'in_debt', 'status', - 'ammount', + 'amount', 'amount_with_currency', 'reason', 'account' => [ @@ -149,10 +150,17 @@ public function test_debts_create_debt() $contact = factory(Contact::class)->create([ 'account_id' => $user->account->id, ]); + $currency = factory(Currency::class)->create([ + 'iso' => 'USD', + 'symbol' => '$', + ]); + //$user->associateCurrency($currency); + $user->currency_id = $currency->id; + $user->save(); $response = $this->json('POST', '/api/debts', [ 'contact_id' => $contact->id, - 'in_debt' => true, + 'in_debt' => 'yes', 'status' => 'inprogress', 'amount' => 42, 'reason' => 'that\'s why' @@ -166,10 +174,10 @@ public function test_debts_create_debt() $response->assertJsonFragment([ 'object' => 'debt', 'id' => $debt_id, - 'in_debt' => true, + 'in_debt' => 'yes', 'status' => 'inprogress', 'amount' => 42, - 'amount_with_currency' => '$42', + 'amount_with_currency' => '$42.00', 'reason' => 'that\'s why' ]); @@ -178,7 +186,7 @@ public function test_debts_create_debt() 'account_id' => $user->account->id, 'contact_id' => $contact->id, 'id' => $debt_id, - 'in_debt' => true, + 'in_debt' => 'yes', 'status' => 'inprogress', 'amount' => 42, 'reason' => 'that\'s why' @@ -238,8 +246,8 @@ public function test_debts_update_debt() $response = $this->json('PUT', '/api/debts/'.$debt->id, [ 'contact_id' => $contact->id, - 'in_debt' => true, - 'status' => 'complete', + 'in_debt' => 'yes', + 'status' => 'completed', 'amount' => 142, 'reason' => 'voilà' ]); @@ -253,8 +261,8 @@ public function test_debts_update_debt() $response->assertJsonFragment([ 'object' => 'debt', 'id' => $debt_id, - 'in_debt' => true, - 'status' => 'complete', + 'in_debt' => 'yes', + 'status' => 'completed', 'amount' => 142, 'reason' => 'voilà' ]); @@ -264,8 +272,8 @@ public function test_debts_update_debt() 'account_id' => $user->account->id, 'contact_id' => $contact->id, 'id' => $debt_id, - 'in_debt' => true, - 'status' => 'complete', + 'in_debt' => 'yes', + 'status' => 'completed', 'amount' => 142, 'reason' => 'voilà' ]); diff --git a/tests/Api/ApiJournalTest.php b/tests/Api/ApiJournalTest.php index 73798cadc6c..f443e5fd7e3 100644 --- a/tests/Api/ApiJournalTest.php +++ b/tests/Api/ApiJournalTest.php @@ -4,6 +4,7 @@ use Tests\ApiTestCase; use App\Models\Account\Account; +use App\Models\Journal\Entry; use App\Models\Journal\JournalEntry; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -26,10 +27,10 @@ class ApiJournalTest extends ApiTestCase public function test_journal_get_all_journal() { $user = $this->signin(); - $journal_entry1 = factory(JournalEntry::class)->create([ + $entry1 = factory(Entry::class)->create([ 'account_id' => $user->account->id, ]); - $journal_entry2 = factory(JournalEntry::class)->create([ + $entry2 = factory(Entry::class)->create([ 'account_id' => $user->account->id, ]); @@ -40,38 +41,38 @@ public function test_journal_get_all_journal() 'data' => ['*' => $this->jsonJournal], ]); $response->assertJsonFragment([ - 'object' => 'journal', - 'id' => $journal_entry1->id, + 'object' => 'entry', + 'id' => $entry1->id, ]); $response->assertJsonFragment([ - 'object' => 'journal', - 'id' => $journal_entry2->id, + 'object' => 'entry', + 'id' => $entry2->id, ]); } public function test_journal_get_one_journal() { $user = $this->signin(); - $journal_entry1 = factory(JournalEntry::class)->create([ + $entry1 = factory(Entry::class)->create([ 'account_id' => $user->account->id, ]); - $journal_entry2 = factory(JournalEntry::class)->create([ + $entry2 = factory(Entry::class)->create([ 'account_id' => $user->account->id, ]); - $response = $this->json('GET', '/api/journal/'.$journal_entry1->id); + $response = $this->json('GET', '/api/journal/'.$entry1->id); $response->assertStatus(200); $response->assertJsonStructure([ 'data' => $this->jsonJournal, ]); $response->assertJsonFragment([ - 'object' => 'journal', - 'id' => $journal_entry1->id, + 'object' => 'entry', + 'id' => $entry1->id, ]); $response->assertJsonMissingExact([ - 'object' => 'journal', - 'id' => $journal_entry2->id, + 'object' => 'entry', + 'id' => $entry2->id, ]); } @@ -102,18 +103,18 @@ public function test_journal_create_journal() $response->assertJsonStructure([ 'data' => $this->jsonJournal, ]); - $journal_entry_id = $response->json('data.id'); + $entry_id = $response->json('data.id'); $response->assertJsonFragment([ - 'object' => 'journal', - 'id' => $journal_entry_id, + 'object' => 'entry', + 'id' => $entry_id, 'title' => 'my title', - 'post' => 'content post' + 'post' => '

content post

' ]); - $this->assertGreaterThan(0, $journal_entry_id); - $this->assertDatabaseHas('journal', [ + $this->assertGreaterThan(0, $entry_id); + $this->assertDatabaseHas('entries', [ 'account_id' => $user->account->id, - 'id' => $journal_entry_id, + 'id' => $entry_id, 'title' => 'my title', 'post' => 'content post' ]); @@ -136,12 +137,12 @@ public function test_journal_create_journal_error() public function test_journal_update_journal() { $user = $this->signin(); - $journal_entry = factory(JournalEntry::class)->create([ + $entry = factory(Entry::class)->create([ 'account_id' => $user->account->id, 'title' => 'xxx', ]); - $response = $this->json('PUT', '/api/journal/'.$journal_entry->id, [ + $response = $this->json('PUT', '/api/journal/'.$entry->id, [ 'title' => 'my title', 'post' => 'content post' ]); @@ -150,19 +151,19 @@ public function test_journal_update_journal() $response->assertJsonStructure([ 'data' => $this->jsonJournal, ]); - $journal_entry_id = $response->json('data.id'); - $this->assertEquals($journal_entry->id, $journal_entry_id); + $entry_id = $response->json('data.id'); + $this->assertEquals($entry->id, $entry_id); $response->assertJsonFragment([ - 'object' => 'journal', - 'id' => $journal_entry_id, + 'object' => 'entry', + 'id' => $entry_id, 'title' => 'my title', - 'post' => 'content post' + 'post' => '

content post

' ]); - $this->assertGreaterThan(0, $journal_entry_id); - $this->assertDatabaseHas('journal_entry', [ + $this->assertGreaterThan(0, $entry_id); + $this->assertDatabaseHas('entries', [ 'account_id' => $user->account->id, - 'id' => $journal_entry_id, + 'id' => $entry_id, 'title' => 'my title', 'post' => 'content post' ]); @@ -171,20 +172,20 @@ public function test_journal_update_journal() public function test_journal_delete_journal() { $user = $this->signin(); - $journal_entry = factory(JournalEntry::class)->create([ + $entry = factory(Entry::class)->create([ 'account_id' => $user->account->id, ]); - $this->assertDatabaseHas('journal', [ + $this->assertDatabaseHas('entries', [ 'account_id' => $user->account->id, - 'id' => $journal_entry->id, + 'id' => $entry->id, ]); - $response = $this->json('DELETE', '/api/journal/'.$journal_entry->id); + $response = $this->json('DELETE', '/api/journal/'.$entry->id); $response->assertStatus(200); - $this->assertDatabaseMissing('journal', [ + $this->assertDatabaseMissing('entries', [ 'account_id' => $user->account->id, - 'id' => $journal_entry->id, + 'id' => $entry->id, ]); } } diff --git a/tests/Api/ApiNotesTest.php b/tests/Api/ApiNotesTest.php index e26ef9180ad..e86a6ba3216 100644 --- a/tests/Api/ApiNotesTest.php +++ b/tests/Api/ApiNotesTest.php @@ -151,7 +151,7 @@ public function test_notes_create_note() $response = $this->json('POST', '/api/notes', [ 'contact_id' => $contact->id, 'body' => 'the body of the note', - 'is_favorited' => false, + 'is_favorited' => 0, ]); $response->assertStatus(201); From 9bc533f7a185d4751522d438d606927e47d6666c Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 21 Oct 2018 00:13:11 +0000 Subject: [PATCH 05/16] Apply fixes from StyleCI --- tests/Api/ApiDebtsTest.php | 12 ++++++------ tests/Api/ApiJournalTest.php | 15 +++++++-------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/Api/ApiDebtsTest.php b/tests/Api/ApiDebtsTest.php index b0d6e8fe1c2..02fd0f0348d 100644 --- a/tests/Api/ApiDebtsTest.php +++ b/tests/Api/ApiDebtsTest.php @@ -163,7 +163,7 @@ public function test_debts_create_debt() 'in_debt' => 'yes', 'status' => 'inprogress', 'amount' => 42, - 'reason' => 'that\'s why' + 'reason' => 'that\'s why', ]); $response->assertStatus(201); @@ -178,7 +178,7 @@ public function test_debts_create_debt() 'status' => 'inprogress', 'amount' => 42, 'amount_with_currency' => '$42.00', - 'reason' => 'that\'s why' + 'reason' => 'that\'s why', ]); $this->assertGreaterThan(0, $debt_id); @@ -189,7 +189,7 @@ public function test_debts_create_debt() 'in_debt' => 'yes', 'status' => 'inprogress', 'amount' => 42, - 'reason' => 'that\'s why' + 'reason' => 'that\'s why', ]); } @@ -249,7 +249,7 @@ public function test_debts_update_debt() 'in_debt' => 'yes', 'status' => 'completed', 'amount' => 142, - 'reason' => 'voilà' + 'reason' => 'voilà', ]); $response->assertStatus(200); @@ -264,7 +264,7 @@ public function test_debts_update_debt() 'in_debt' => 'yes', 'status' => 'completed', 'amount' => 142, - 'reason' => 'voilà' + 'reason' => 'voilà', ]); $this->assertGreaterThan(0, $debt_id); @@ -275,7 +275,7 @@ public function test_debts_update_debt() 'in_debt' => 'yes', 'status' => 'completed', 'amount' => 142, - 'reason' => 'voilà' + 'reason' => 'voilà', ]); } diff --git a/tests/Api/ApiJournalTest.php b/tests/Api/ApiJournalTest.php index f443e5fd7e3..c3b64225910 100644 --- a/tests/Api/ApiJournalTest.php +++ b/tests/Api/ApiJournalTest.php @@ -3,9 +3,8 @@ namespace Tests\Api; use Tests\ApiTestCase; -use App\Models\Account\Account; use App\Models\Journal\Entry; -use App\Models\Journal\JournalEntry; +use App\Models\Account\Account; use Illuminate\Foundation\Testing\DatabaseTransactions; class ApiJournalTest extends ApiTestCase @@ -96,7 +95,7 @@ public function test_journal_create_journal() $response = $this->json('POST', '/api/journal', [ 'title' => 'my title', - 'post' => 'content post' + 'post' => 'content post', ]); $response->assertStatus(201); @@ -108,7 +107,7 @@ public function test_journal_create_journal() 'object' => 'entry', 'id' => $entry_id, 'title' => 'my title', - 'post' => '

content post

' + 'post' => '

content post

', ]); $this->assertGreaterThan(0, $entry_id); @@ -116,7 +115,7 @@ public function test_journal_create_journal() 'account_id' => $user->account->id, 'id' => $entry_id, 'title' => 'my title', - 'post' => 'content post' + 'post' => 'content post', ]); } @@ -144,7 +143,7 @@ public function test_journal_update_journal() $response = $this->json('PUT', '/api/journal/'.$entry->id, [ 'title' => 'my title', - 'post' => 'content post' + 'post' => 'content post', ]); $response->assertStatus(200); @@ -157,7 +156,7 @@ public function test_journal_update_journal() 'object' => 'entry', 'id' => $entry_id, 'title' => 'my title', - 'post' => '

content post

' + 'post' => '

content post

', ]); $this->assertGreaterThan(0, $entry_id); @@ -165,7 +164,7 @@ public function test_journal_update_journal() 'account_id' => $user->account->id, 'id' => $entry_id, 'title' => 'my title', - 'post' => 'content post' + 'post' => 'content post', ]); } From f7b400870a4727fb21a58aee2552750ec721b65c Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 21 Oct 2018 13:45:39 +0200 Subject: [PATCH 06/16] Add pet tests --- tests/Api/ApiPetsTest.php | 285 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 285 insertions(+) create mode 100644 tests/Api/ApiPetsTest.php diff --git a/tests/Api/ApiPetsTest.php b/tests/Api/ApiPetsTest.php new file mode 100644 index 00000000000..2dc40b544f6 --- /dev/null +++ b/tests/Api/ApiPetsTest.php @@ -0,0 +1,285 @@ + [ + 'id', + 'object', + 'name', + 'is_common', + ], + 'account' => [ + 'id', + ], + 'contact' => [ + 'id', + ], + 'created_at', + 'updated_at', + ]; + + /* + public function test_pets_get_all_pets() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $pet1 = factory(Pet::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $contact2 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $pet2 = factory(Pet::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact2->id, + ]); + + $response = $this->json('GET', '/api/pets'); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => ['*' => $this->jsonPet], + ]); + $response->assertJsonFragment([ + 'object' => 'pet', + 'id' => $pet1->id, + ]); + $response->assertJsonFragment([ + 'object' => 'pet', + 'id' => $pet2->id, + ]); + } + */ + + public function test_pets_get_contact_all_pets() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $pet1 = factory(Pet::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $contact2 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $pet2 = factory(Pet::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact2->id, + ]); + + $response = $this->json('GET', '/api/contacts/'.$contact1->id.'/pets'); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => ['*' => $this->jsonPet], + ]); + $response->assertJsonFragment([ + 'object' => 'pet', + 'id' => $pet1->id, + ]); + $response->assertJsonMissingExact([ + 'object' => 'pet', + 'id' => $pet2->id, + ]); + } + + public function test_pets_get_one_pet() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $pet1 = factory(Pet::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $pet2 = factory(Pet::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + + $response = $this->json('GET', '/api/pets/'.$pet1->id); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonPet, + ]); + $response->assertJsonFragment([ + 'object' => 'pet', + 'id' => $pet1->id, + ]); + $response->assertJsonMissingExact([ + 'object' => 'pet', + 'id' => $pet2->id, + ]); + } + + public function test_pets_get_one_pet_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/pets/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_pets_create_pet() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $pet_category = factory(PetCategory::class)->create(); + + $response = $this->json('POST', '/api/pets', [ + 'contact_id' => $contact->id, + 'pet_category_id' => $pet_category->id, + ]); + + $response->assertStatus(201); + $response->assertJsonStructure([ + 'data' => $this->jsonPet, + ]); + $pet_id = $response->json('data.id'); + $response->assertJsonFragment([ + 'object' => 'pet', + 'id' => $pet_id, + ]); + + $this->assertGreaterThan(0, $pet_id); + $this->assertDatabaseHas('pets', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'pet_category_id' => $pet_category->id, + 'id' => $pet_id, + ]); + } + + public function test_pets_create_pet_error() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('POST', '/api/pets', [ + 'contact_id' => $contact->id, + ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32, + ], + ]); + } + + public function test_pets_create_pet_error_bad_account() + { + $user = $this->signin(); + + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create([ + 'account_id' => $account->id, + ]); + + $response = $this->json('POST', '/api/pets', [ + 'contact_id' => $contact->id, + ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32, + ], + ]); + } + + public function test_pets_update_pet() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $pet = factory(Pet::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + $pet_category = factory(PetCategory::class)->create(); + + $response = $this->json('PUT', '/api/pets/'.$pet->id, [ + 'contact_id' => $contact->id, + 'pet_category_id' => $pet_category->id, + ]); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonPet, + ]); + $pet_id = $response->json('data.id'); + $this->assertEquals($pet->id, $pet_id); + $response->assertJsonFragment([ + 'object' => 'pet', + 'id' => $pet_id, + ]); + + $this->assertGreaterThan(0, $pet_id); + $this->assertDatabaseHas('pets', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'pet_category_id' => $pet_category->id, + 'id' => $pet_id, + ]); + } + + public function test_pets_delete_pet() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $pet = factory(Pet::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + $this->assertDatabaseHas('pets', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $pet->id, + ]); + + $response = $this->json('DELETE', '/api/pets/'.$pet->id); + + $response->assertStatus(200); + $this->assertDatabaseMissing('pets', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $pet->id, + ]); + } +} From a5e54258df0ae2dbabea838cad1e9db86b63ee0f Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 21 Oct 2018 14:09:49 +0200 Subject: [PATCH 07/16] Add reminders tets --- tests/Api/ApiRemindersTest.php | 304 +++++++++++++++++++++++++++++++++ 1 file changed, 304 insertions(+) create mode 100644 tests/Api/ApiRemindersTest.php diff --git a/tests/Api/ApiRemindersTest.php b/tests/Api/ApiRemindersTest.php new file mode 100644 index 00000000000..cac35494800 --- /dev/null +++ b/tests/Api/ApiRemindersTest.php @@ -0,0 +1,304 @@ + [ + 'id', + ], + 'contact' => [ + 'id', + ], + 'created_at', + 'updated_at', + ]; + + public function test_reminders_get_all_reminders() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $reminder1 = factory(Reminder::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $contact2 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $reminder2 = factory(Reminder::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact2->id, + ]); + + $response = $this->json('GET', '/api/reminders'); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => ['*' => $this->jsonReminder], + ]); + $response->assertJsonFragment([ + 'object' => 'reminder', + 'id' => $reminder1->id, + ]); + $response->assertJsonFragment([ + 'object' => 'reminder', + 'id' => $reminder2->id, + ]); + } + + public function test_reminders_get_contact_all_reminders() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $reminder1 = factory(Reminder::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $contact2 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $reminder2 = factory(Reminder::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact2->id, + ]); + + $response = $this->json('GET', '/api/contacts/'.$contact1->id.'/reminders'); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => ['*' => $this->jsonReminder], + ]); + $response->assertJsonFragment([ + 'object' => 'reminder', + 'id' => $reminder1->id, + ]); + $response->assertJsonMissingExact([ + 'object' => 'reminder', + 'id' => $reminder2->id, + ]); + } + + public function test_reminders_get_one_reminder() + { + $user = $this->signin(); + $contact1 = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $reminder1 = factory(Reminder::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + $reminder2 = factory(Reminder::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact1->id, + ]); + + $response = $this->json('GET', '/api/reminders/'.$reminder1->id); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonReminder, + ]); + $response->assertJsonFragment([ + 'object' => 'reminder', + 'id' => $reminder1->id, + ]); + $response->assertJsonMissingExact([ + 'object' => 'reminder', + 'id' => $reminder2->id, + ]); + } + + public function test_reminders_get_one_reminder_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/reminders/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_reminders_create_reminder() + { + Carbon::setTestNow(Carbon::create(2018, 1, 1, 7, 0, 0)); + + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('POST', '/api/reminders', [ + 'contact_id' => $contact->id, + 'title' => 'the title', + 'next_expected_date' => '2018-05-01', + 'frequency_type' => 'one_time', + 'description' => 'the description' + ]); + + $response->assertStatus(201); + $response->assertJsonStructure([ + 'data' => $this->jsonReminder, + ]); + $reminder_id = $response->json('data.id'); + $response->assertJsonFragment([ + 'object' => 'reminder', + 'id' => $reminder_id, + 'title' => 'the title', + 'next_expected_date' => '2018-05-01T00:00:00Z', + 'frequency_type' => 'one_time', + 'description' => 'the description' + ]); + + $this->assertGreaterThan(0, $reminder_id); + $this->assertDatabaseHas('reminders', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $reminder_id, + 'title' => 'the title', + 'next_expected_date' => '2018-05-01 00:00:00', + 'frequency_type' => 'one_time', + 'description' => 'the description' + ]); + } + + public function test_reminders_create_reminder_error() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + + $response = $this->json('POST', '/api/reminders', [ + 'contact_id' => $contact->id, + ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32, + ], + ]); + } + + public function test_reminders_create_reminder_error_bad_account() + { + $user = $this->signin(); + + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create([ + 'account_id' => $account->id, + ]); + + $response = $this->json('POST', '/api/reminders', [ + 'contact_id' => $contact->id, + ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32, + ], + ]); + } + + public function test_reminders_update_reminder() + { + Carbon::setTestNow(Carbon::create(2018, 1, 1, 7, 0, 0)); + + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $reminder = factory(Reminder::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + + $response = $this->json('PUT', '/api/reminders/'.$reminder->id, [ + 'contact_id' => $contact->id, + 'title' => 'the title', + 'next_expected_date' => '2018-05-01', + 'frequency_type' => 'day', + 'description' => 'the description' + ]); + + $response->assertStatus(200); + $response->assertJsonStructure([ + 'data' => $this->jsonReminder, + ]); + $reminder_id = $response->json('data.id'); + $this->assertEquals($reminder->id, $reminder_id); + $response->assertJsonFragment([ + 'object' => 'reminder', + 'id' => $reminder_id, + 'title' => 'the title', + 'next_expected_date' => '2018-05-01T00:00:00Z', + 'frequency_type' => 'day', + 'description' => 'the description' + ]); + + $this->assertGreaterThan(0, $reminder_id); + $this->assertDatabaseHas('reminders', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $reminder_id, + 'title' => 'the title', + 'next_expected_date' => '2018-05-01 00:00:00', + 'frequency_type' => 'day', + 'description' => 'the description' + ]); + } + + public function test_reminders_delete_reminder() + { + $user = $this->signin(); + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account->id, + ]); + $reminder = factory(Reminder::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + $this->assertDatabaseHas('reminders', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $reminder->id, + ]); + + $response = $this->json('DELETE', '/api/reminders/'.$reminder->id); + + $response->assertStatus(200); + $this->assertDatabaseMissing('reminders', [ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + 'id' => $reminder->id, + ]); + } +} From 421b68921d3753631879f4c9e0e3e02052bf2df2 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 21 Oct 2018 12:10:17 +0000 Subject: [PATCH 08/16] Apply fixes from StyleCI --- tests/Api/ApiRemindersTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/Api/ApiRemindersTest.php b/tests/Api/ApiRemindersTest.php index cac35494800..9d8fb87f054 100644 --- a/tests/Api/ApiRemindersTest.php +++ b/tests/Api/ApiRemindersTest.php @@ -4,9 +4,9 @@ use Carbon\Carbon; use Tests\ApiTestCase; -use App\Models\Contact\Reminder; use App\Models\Account\Account; use App\Models\Contact\Contact; +use App\Models\Contact\Reminder; use Illuminate\Foundation\Testing\DatabaseTransactions; class ApiRemindersTest extends ApiTestCase @@ -159,7 +159,7 @@ public function test_reminders_create_reminder() 'title' => 'the title', 'next_expected_date' => '2018-05-01', 'frequency_type' => 'one_time', - 'description' => 'the description' + 'description' => 'the description', ]); $response->assertStatus(201); @@ -173,7 +173,7 @@ public function test_reminders_create_reminder() 'title' => 'the title', 'next_expected_date' => '2018-05-01T00:00:00Z', 'frequency_type' => 'one_time', - 'description' => 'the description' + 'description' => 'the description', ]); $this->assertGreaterThan(0, $reminder_id); @@ -184,7 +184,7 @@ public function test_reminders_create_reminder() 'title' => 'the title', 'next_expected_date' => '2018-05-01 00:00:00', 'frequency_type' => 'one_time', - 'description' => 'the description' + 'description' => 'the description', ]); } @@ -246,7 +246,7 @@ public function test_reminders_update_reminder() 'title' => 'the title', 'next_expected_date' => '2018-05-01', 'frequency_type' => 'day', - 'description' => 'the description' + 'description' => 'the description', ]); $response->assertStatus(200); @@ -261,7 +261,7 @@ public function test_reminders_update_reminder() 'title' => 'the title', 'next_expected_date' => '2018-05-01T00:00:00Z', 'frequency_type' => 'day', - 'description' => 'the description' + 'description' => 'the description', ]); $this->assertGreaterThan(0, $reminder_id); @@ -272,7 +272,7 @@ public function test_reminders_update_reminder() 'title' => 'the title', 'next_expected_date' => '2018-05-01 00:00:00', 'frequency_type' => 'day', - 'description' => 'the description' + 'description' => 'the description', ]); } From 246d31b7cc49d712a63990d7bc4806d293dae0cc Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 21 Oct 2018 15:21:01 +0200 Subject: [PATCH 09/16] update --- app/Http/Controllers/Api/ApiController.php | 1 + tests/Api/ApiCallsTest.php | 87 ++++++++++++++++++--- tests/Api/ApiDebtsTest.php | 89 ++++++++++++++++++--- tests/Api/ApiGiftsTest.php | 88 ++++++++++++++++++--- tests/Api/ApiNotesTest.php | 87 ++++++++++++++++++--- tests/Api/ApiPetsTest.php | 90 ++++++++++++++++++--- tests/Api/ApiRemindersTest.php | 91 +++++++++++++++++++--- tests/Api/ApiTasksTest.php | 87 ++++++++++++++++++--- 8 files changed, 557 insertions(+), 63 deletions(-) diff --git a/app/Http/Controllers/Api/ApiController.php b/app/Http/Controllers/Api/ApiController.php index 712b6cc44a6..fb03e848d2e 100644 --- a/app/Http/Controllers/Api/ApiController.php +++ b/app/Http/Controllers/Api/ApiController.php @@ -288,6 +288,7 @@ public function respondNotTheRightParameters($message = 'Too many parameters') */ public function respondWithError($message) { + // TODO status code return $this->respond([ 'error' => [ 'message' => $message, diff --git a/tests/Api/ApiCallsTest.php b/tests/Api/ApiCallsTest.php index 8c7b0804998..158a454f808 100644 --- a/tests/Api/ApiCallsTest.php +++ b/tests/Api/ApiCallsTest.php @@ -27,7 +27,7 @@ class ApiCallsTest extends ApiTestCase 'updated_at', ]; - public function test_calls_get_all_calls() + public function test_calls_get_all() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -61,7 +61,7 @@ public function test_calls_get_all_calls() ]); } - public function test_calls_get_contact_all_calls() + public function test_calls_get_contact_all() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -95,7 +95,21 @@ public function test_calls_get_contact_all_calls() ]); } - public function test_calls_get_one_call() + public function test_calls_get_contact_all_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/contacts/0/calls'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_calls_get_one() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -126,7 +140,7 @@ public function test_calls_get_one_call() ]); } - public function test_calls_get_one_call_error() + public function test_calls_get_one_error() { $user = $this->signin(); @@ -140,7 +154,7 @@ public function test_calls_get_one_call_error() ]); } - public function test_calls_create_call() + public function test_calls_create() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -173,7 +187,7 @@ public function test_calls_create_call() ]); } - public function test_calls_create_call_error() + public function test_calls_create_error() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -192,7 +206,7 @@ public function test_calls_create_call_error() ]); } - public function test_calls_create_call_error_bad_account() + public function test_calls_create_error_bad_account() { $user = $this->signin(); @@ -213,7 +227,7 @@ public function test_calls_create_call_error_bad_account() ]); } - public function test_calls_update_call() + public function test_calls_update() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -251,7 +265,48 @@ public function test_calls_update_call() ]); } - public function test_calls_delete_call() + public function test_calls_update_error() + { + $user = $this->signin(); + + $response = $this->json('PUT', '/api/calls/0', []); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_calls_update_error_bad_account() + { + $user = $this->signin(); + + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create([ + 'account_id' => $account->id, + ]); + $call = factory(Call::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + + $response = $this->json('PUT', '/api/calls/'.$call->id, [ + 'contact_id' => $contact->id, + 'content' => 'the call', + 'called_at' => '2018-05-01', + ]); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_calls_delete() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -276,4 +331,18 @@ public function test_calls_delete_call() 'id' => $call->id, ]); } + + public function test_calls_delete_error() + { + $user = $this->signin(); + + $response = $this->json('DELETE', '/api/calls/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } } diff --git a/tests/Api/ApiDebtsTest.php b/tests/Api/ApiDebtsTest.php index 02fd0f0348d..6c9b953f358 100644 --- a/tests/Api/ApiDebtsTest.php +++ b/tests/Api/ApiDebtsTest.php @@ -31,7 +31,7 @@ class ApiDebtsTest extends ApiTestCase 'updated_at', ]; - public function test_debts_get_all_debts() + public function test_debts_get_all() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -65,7 +65,7 @@ public function test_debts_get_all_debts() ]); } - public function test_debts_get_contact_all_debts() + public function test_debts_get_contact_all() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -99,7 +99,21 @@ public function test_debts_get_contact_all_debts() ]); } - public function test_debts_get_one_debt() + public function test_debts_get_contact_all_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/contacts/0/debts'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_debts_get_one() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -130,7 +144,7 @@ public function test_debts_get_one_debt() ]); } - public function test_debts_get_one_debt_error() + public function test_debts_get_one_error() { $user = $this->signin(); @@ -144,7 +158,7 @@ public function test_debts_get_one_debt_error() ]); } - public function test_debts_create_debt() + public function test_debts_create() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -193,7 +207,7 @@ public function test_debts_create_debt() ]); } - public function test_debts_create_debt_error() + public function test_debts_create_error() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -212,7 +226,7 @@ public function test_debts_create_debt_error() ]); } - public function test_debts_create_debt_error_bad_account() + public function test_debts_create_error_bad_account() { $user = $this->signin(); @@ -233,7 +247,7 @@ public function test_debts_create_debt_error_bad_account() ]); } - public function test_debts_update_debt() + public function test_debts_update() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -279,7 +293,50 @@ public function test_debts_update_debt() ]); } - public function test_debts_delete_debt() + public function test_debts_update_error() + { + $user = $this->signin(); + + $response = $this->json('PUT', '/api/debts/0', []); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_dets_update_error_bad_account() + { + $user = $this->signin(); + + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create([ + 'account_id' => $account->id, + ]); + $debt = factory(Debt::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + + $response = $this->json('PUT', '/api/debts/'.$debt->id, [ + 'contact_id' => $contact->id, + 'in_debt' => 'yes', + 'status' => 'completed', + 'amount' => 142, + 'reason' => 'voilà', + ]); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_debts_delete() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -304,4 +361,18 @@ public function test_debts_delete_debt() 'id' => $debt->id, ]); } + + public function test_debts_delete_error() + { + $user = $this->signin(); + + $response = $this->json('DELETE', '/api/debts/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } } diff --git a/tests/Api/ApiGiftsTest.php b/tests/Api/ApiGiftsTest.php index 52c39c182e4..2edb92bbe07 100644 --- a/tests/Api/ApiGiftsTest.php +++ b/tests/Api/ApiGiftsTest.php @@ -33,7 +33,7 @@ class ApiGiftsTest extends ApiTestCase 'updated_at', ]; - public function test_gifts_get_all_gifts() + public function test_gifts_get_all() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -67,7 +67,7 @@ public function test_gifts_get_all_gifts() ]); } - public function test_gifts_get_contact_all_gifts() + public function test_gifts_get_contact_all() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -101,7 +101,22 @@ public function test_gifts_get_contact_all_gifts() ]); } - public function test_gifts_get_one_gift() + + public function test_gifts_get_contact_all_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/contacts/0/gifts'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_gifts_get_one() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -132,7 +147,7 @@ public function test_gifts_get_one_gift() ]); } - public function test_gifts_get_one_gift_error() + public function test_gifts_get_one_error() { $user = $this->signin(); @@ -146,7 +161,7 @@ public function test_gifts_get_one_gift_error() ]); } - public function test_gifts_create_gift() + public function test_gifts_create() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -177,7 +192,7 @@ public function test_gifts_create_gift() ]); } - public function test_gifts_create_gift_error() + public function test_gifts_create_error() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -196,7 +211,7 @@ public function test_gifts_create_gift_error() ]); } - public function test_gifts_create_gift_error_bad_account() + public function test_gifts_create_error_bad_account() { $user = $this->signin(); @@ -217,7 +232,7 @@ public function test_gifts_create_gift_error_bad_account() ]); } - public function test_gifts_update_gift() + public function test_gifts_update() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -255,7 +270,48 @@ public function test_gifts_update_gift() ]); } - public function test_gifts_delete_gift() + public function test_gifts_update_error() + { + $user = $this->signin(); + + $response = $this->json('PUT', '/api/gifts/0', []); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_gifts_update_error_bad_account() + { + $user = $this->signin(); + + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create([ + 'account_id' => $account->id, + ]); + $gift = factory(Gift::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + + $response = $this->json('PUT', '/api/gifts/'.$gift->id, [ + 'contact_id' => $contact->id, + 'name' => 'the gift', + 'comment' => 'one comment', + ]); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_gifts_delete() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -280,4 +336,18 @@ public function test_gifts_delete_gift() 'id' => $gift->id, ]); } + + public function test_gifts_delete_error() + { + $user = $this->signin(); + + $response = $this->json('DELETE', '/api/gifts/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } } diff --git a/tests/Api/ApiNotesTest.php b/tests/Api/ApiNotesTest.php index e86a6ba3216..40f7061bfaa 100644 --- a/tests/Api/ApiNotesTest.php +++ b/tests/Api/ApiNotesTest.php @@ -28,7 +28,7 @@ class ApiNotesTest extends ApiTestCase 'updated_at', ]; - public function test_notes_get_all_notes() + public function test_notes_get_all() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -62,7 +62,7 @@ public function test_notes_get_all_notes() ]); } - public function test_notes_get_contact_all_notes() + public function test_notes_get_contact_all() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -96,7 +96,21 @@ public function test_notes_get_contact_all_notes() ]); } - public function test_notes_get_one_note() + public function test_notes_get_contact_all_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/contacts/0/notes'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_notes_get_one() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -127,7 +141,7 @@ public function test_notes_get_one_note() ]); } - public function test_notes_get_one_note_error() + public function test_notes_get_one_error() { $user = $this->signin(); @@ -141,7 +155,7 @@ public function test_notes_get_one_note_error() ]); } - public function test_notes_create_note() + public function test_notes_create() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -176,7 +190,7 @@ public function test_notes_create_note() ]); } - public function test_notes_create_note_error() + public function test_notes_create_error() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -195,7 +209,7 @@ public function test_notes_create_note_error() ]); } - public function test_notes_create_note_error_bad_account() + public function test_notes_create_error_bad_account() { $user = $this->signin(); @@ -216,7 +230,7 @@ public function test_notes_create_note_error_bad_account() ]); } - public function test_notes_update_note() + public function test_notes_update() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -256,7 +270,48 @@ public function test_notes_update_note() ]); } - public function test_notes_delete_note() + public function test_notes_update_error() + { + $user = $this->signin(); + + $response = $this->json('PUT', '/api/notes/0', []); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_notes_update_error_bad_account() + { + $user = $this->signin(); + + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create([ + 'account_id' => $account->id, + ]); + $note = factory(Note::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + + $response = $this->json('PUT', '/api/notes/'.$note->id, [ + 'contact_id' => $contact->id, + 'body' => 'the body of the note', + 'is_favorited' => false, + ]); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_notes_delete() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -281,4 +336,18 @@ public function test_notes_delete_note() 'id' => $note->id, ]); } + + public function test_notes_delete_error() + { + $user = $this->signin(); + + $response = $this->json('DELETE', '/api/notes/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } } diff --git a/tests/Api/ApiPetsTest.php b/tests/Api/ApiPetsTest.php index 2dc40b544f6..e854c4fa46b 100644 --- a/tests/Api/ApiPetsTest.php +++ b/tests/Api/ApiPetsTest.php @@ -34,7 +34,7 @@ class ApiPetsTest extends ApiTestCase ]; /* - public function test_pets_get_all_pets() + public function test_pets_get_all() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -69,7 +69,7 @@ public function test_pets_get_all_pets() } */ - public function test_pets_get_contact_all_pets() + public function test_pets_get_contact_all() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -103,7 +103,21 @@ public function test_pets_get_contact_all_pets() ]); } - public function test_pets_get_one_pet() + public function test_pets_get_contact_all_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/contacts/0/pets'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_pets_get_one() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -134,7 +148,7 @@ public function test_pets_get_one_pet() ]); } - public function test_pets_get_one_pet_error() + public function test_pets_get_one_error() { $user = $this->signin(); @@ -148,7 +162,7 @@ public function test_pets_get_one_pet_error() ]); } - public function test_pets_create_pet() + public function test_pets_create() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -160,6 +174,7 @@ public function test_pets_create_pet() 'contact_id' => $contact->id, 'pet_category_id' => $pet_category->id, ]); + // No 'name' parameter ? $response->assertStatus(201); $response->assertJsonStructure([ @@ -180,7 +195,7 @@ public function test_pets_create_pet() ]); } - public function test_pets_create_pet_error() + public function test_pets_create_error() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -199,7 +214,7 @@ public function test_pets_create_pet_error() ]); } - public function test_pets_create_pet_error_bad_account() + public function test_pets_create_error_bad_account() { $user = $this->signin(); @@ -220,7 +235,7 @@ public function test_pets_create_pet_error_bad_account() ]); } - public function test_pets_update_pet() + public function test_pets_update() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -257,7 +272,50 @@ public function test_pets_update_pet() ]); } - public function test_pets_delete_pet() + public function test_pets_update_error() + { + $user = $this->signin(); + + $response = $this->json('PUT', '/api/pets/0', []); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + /* + public function test_pets_update_error_bad_account() + { + $user = $this->signin(); + + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create([ + 'account_id' => $account->id, + ]); + $pet = factory(Pet::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + $pet_category = factory(PetCategory::class)->create(); + + $response = $this->json('PUT', '/api/pets/'.$pet->id, [ + 'contact_id' => $contact->id, + 'pet_category_id' => $pet_category->id, + ]); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + */ + + public function test_pets_delete() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -282,4 +340,18 @@ public function test_pets_delete_pet() 'id' => $pet->id, ]); } + + public function test_pets_delete_error() + { + $user = $this->signin(); + + $response = $this->json('DELETE', '/api/pets/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } } diff --git a/tests/Api/ApiRemindersTest.php b/tests/Api/ApiRemindersTest.php index cac35494800..ac400625dd1 100644 --- a/tests/Api/ApiRemindersTest.php +++ b/tests/Api/ApiRemindersTest.php @@ -32,7 +32,7 @@ class ApiRemindersTest extends ApiTestCase 'updated_at', ]; - public function test_reminders_get_all_reminders() + public function test_reminders_get_all() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -66,7 +66,7 @@ public function test_reminders_get_all_reminders() ]); } - public function test_reminders_get_contact_all_reminders() + public function test_reminders_get_contact_all() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -100,7 +100,21 @@ public function test_reminders_get_contact_all_reminders() ]); } - public function test_reminders_get_one_reminder() + public function test_reminders_get_contact_all_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/contacts/0/reminders'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_reminders_get_one() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -131,7 +145,7 @@ public function test_reminders_get_one_reminder() ]); } - public function test_reminders_get_one_reminder_error() + public function test_reminders_get_one_error() { $user = $this->signin(); @@ -145,7 +159,7 @@ public function test_reminders_get_one_reminder_error() ]); } - public function test_reminders_create_reminder() + public function test_reminders_create() { Carbon::setTestNow(Carbon::create(2018, 1, 1, 7, 0, 0)); @@ -188,7 +202,7 @@ public function test_reminders_create_reminder() ]); } - public function test_reminders_create_reminder_error() + public function test_reminders_create_error() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -207,7 +221,7 @@ public function test_reminders_create_reminder_error() ]); } - public function test_reminders_create_reminder_error_bad_account() + public function test_reminders_create_error_bad_account() { $user = $this->signin(); @@ -228,7 +242,7 @@ public function test_reminders_create_reminder_error_bad_account() ]); } - public function test_reminders_update_reminder() + public function test_reminders_update() { Carbon::setTestNow(Carbon::create(2018, 1, 1, 7, 0, 0)); @@ -276,7 +290,52 @@ public function test_reminders_update_reminder() ]); } - public function test_reminders_delete_reminder() + public function test_reminders_update_error() + { + $user = $this->signin(); + + $response = $this->json('PUT', '/api/reminders/0', []); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_reminders_update_error_bad_account() + { + Carbon::setTestNow(Carbon::create(2018, 1, 1, 7, 0, 0)); + + $user = $this->signin(); + + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create([ + 'account_id' => $account->id, + ]); + $reminder = factory(Reminder::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + + $response = $this->json('PUT', '/api/reminders/'.$reminder->id, [ + 'contact_id' => $contact->id, + 'title' => 'the title', + 'next_expected_date' => '2018-05-01', + 'frequency_type' => 'day', + 'description' => 'the description' + ]); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_reminders_delete() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -301,4 +360,18 @@ public function test_reminders_delete_reminder() 'id' => $reminder->id, ]); } + + public function test_reminders_delete_error() + { + $user = $this->signin(); + + $response = $this->json('DELETE', '/api/reminders/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } } diff --git a/tests/Api/ApiTasksTest.php b/tests/Api/ApiTasksTest.php index 528919f9e3b..34edc1e8b19 100644 --- a/tests/Api/ApiTasksTest.php +++ b/tests/Api/ApiTasksTest.php @@ -29,7 +29,7 @@ class ApiTasksTest extends ApiTestCase 'updated_at', ]; - public function test_tasks_get_all_tasks() + public function test_tasks_get_all() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -63,7 +63,7 @@ public function test_tasks_get_all_tasks() ]); } - public function test_tasks_get_contact_all_tasks() + public function test_tasks_get_contact_all() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -97,7 +97,21 @@ public function test_tasks_get_contact_all_tasks() ]); } - public function test_tasks_get_one_task() + public function test_tasks_get_contact_all_error() + { + $user = $this->signin(); + + $response = $this->json('GET', '/api/contacts/0/tasks'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_tasks_get_one() { $user = $this->signin(); $contact1 = factory(Contact::class)->create([ @@ -128,7 +142,7 @@ public function test_tasks_get_one_task() ]); } - public function test_tasks_get_one_task_error() + public function test_tasks_get_one_error() { $user = $this->signin(); @@ -142,7 +156,7 @@ public function test_tasks_get_one_task_error() ]); } - public function test_tasks_create_task() + public function test_tasks_create() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -175,7 +189,7 @@ public function test_tasks_create_task() ]); } - public function test_tasks_create_task_error() + public function test_tasks_create_error() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -194,7 +208,7 @@ public function test_tasks_create_task_error() ]); } - public function test_tasks_create_task_error_bad_account() + public function test_tasks_create_error_bad_account() { $user = $this->signin(); @@ -215,7 +229,7 @@ public function test_tasks_create_task_error_bad_account() ]); } - public function test_tasks_update_task() + public function test_tasks_update() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -253,7 +267,48 @@ public function test_tasks_update_task() ]); } - public function test_tasks_delete_task() + public function test_tasks_update_error() + { + $user = $this->signin(); + + $response = $this->json('PUT', '/api/tasks/0', []); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_tasks_update_error_bad_account() + { + $user = $this->signin(); + + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create([ + 'account_id' => $account->id, + ]); + $task = factory(Task::class)->create([ + 'account_id' => $user->account->id, + 'contact_id' => $contact->id, + ]); + + $response = $this->json('PUT', '/api/tasks/'.$task->id, [ + 'contact_id' => $contact->id, + 'title' => 'the task', + 'completed' => false, + ]); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_tasks_delete() { $user = $this->signin(); $contact = factory(Contact::class)->create([ @@ -278,4 +333,18 @@ public function test_tasks_delete_task() 'id' => $task->id, ]); } + + public function test_tasks_delete_error() + { + $user = $this->signin(); + + $response = $this->json('DELETE', '/api/tasks/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } } From 51e874f17313cee72e2cf8e580c0e37c535041ce Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 21 Oct 2018 13:21:30 +0000 Subject: [PATCH 10/16] Apply fixes from StyleCI --- tests/Api/ApiGiftsTest.php | 1 - tests/Api/ApiRemindersTest.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Api/ApiGiftsTest.php b/tests/Api/ApiGiftsTest.php index 2edb92bbe07..1ece07cbbf3 100644 --- a/tests/Api/ApiGiftsTest.php +++ b/tests/Api/ApiGiftsTest.php @@ -101,7 +101,6 @@ public function test_gifts_get_contact_all() ]); } - public function test_gifts_get_contact_all_error() { $user = $this->signin(); diff --git a/tests/Api/ApiRemindersTest.php b/tests/Api/ApiRemindersTest.php index 072e77646d0..27bf8224c85 100644 --- a/tests/Api/ApiRemindersTest.php +++ b/tests/Api/ApiRemindersTest.php @@ -324,7 +324,7 @@ public function test_reminders_update_error_bad_account() 'title' => 'the title', 'next_expected_date' => '2018-05-01', 'frequency_type' => 'day', - 'description' => 'the description' + 'description' => 'the description', ]); $response->assertStatus(404); From 34fe7f67b448884dff3ea748a175daabb9778d0e Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 21 Oct 2018 16:09:21 +0200 Subject: [PATCH 11/16] update --- tests/Api/ApiCallsTest.php | 6 +++-- tests/Api/ApiDebtsTest.php | 8 ++++-- tests/Api/ApiGiftsTest.php | 5 ++-- tests/Api/ApiJournalTest.php | 46 ++++++++++++++++++++++++++++++++++ tests/Api/ApiNotesTest.php | 6 +++-- tests/Api/ApiPetsTest.php | 6 +++-- tests/Api/ApiRemindersTest.php | 10 ++++++-- tests/Api/ApiTasksTest.php | 6 +++-- 8 files changed, 79 insertions(+), 14 deletions(-) diff --git a/tests/Api/ApiCallsTest.php b/tests/Api/ApiCallsTest.php index 158a454f808..a18d315bce5 100644 --- a/tests/Api/ApiCallsTest.php +++ b/tests/Api/ApiCallsTest.php @@ -217,12 +217,14 @@ public function test_calls_create_error_bad_account() $response = $this->json('POST', '/api/calls', [ 'contact_id' => $contact->id, + 'content' => 'the call', + 'called_at' => '2018-05-01', ]); - $response->assertStatus(200); + $response->assertStatus(404); $response->assertJson([ 'error' => [ - 'error_code' => 32, + 'error_code' => 31, ], ]); } diff --git a/tests/Api/ApiDebtsTest.php b/tests/Api/ApiDebtsTest.php index 6c9b953f358..2ce02f86ca4 100644 --- a/tests/Api/ApiDebtsTest.php +++ b/tests/Api/ApiDebtsTest.php @@ -237,12 +237,16 @@ public function test_debts_create_error_bad_account() $response = $this->json('POST', '/api/debts', [ 'contact_id' => $contact->id, + 'in_debt' => 'yes', + 'status' => 'inprogress', + 'amount' => 42, + 'reason' => 'that\'s why', ]); - $response->assertStatus(200); + $response->assertStatus(404); $response->assertJson([ 'error' => [ - 'error_code' => 32, + 'error_code' => 31, ], ]); } diff --git a/tests/Api/ApiGiftsTest.php b/tests/Api/ApiGiftsTest.php index 2edb92bbe07..b3b2eeebe0a 100644 --- a/tests/Api/ApiGiftsTest.php +++ b/tests/Api/ApiGiftsTest.php @@ -222,12 +222,13 @@ public function test_gifts_create_error_bad_account() $response = $this->json('POST', '/api/gifts', [ 'contact_id' => $contact->id, + 'name' => 'the gift', ]); - $response->assertStatus(200); + $response->assertStatus(404); $response->assertJson([ 'error' => [ - 'error_code' => 32, + 'error_code' => 31, ], ]); } diff --git a/tests/Api/ApiJournalTest.php b/tests/Api/ApiJournalTest.php index c3b64225910..79dec226f83 100644 --- a/tests/Api/ApiJournalTest.php +++ b/tests/Api/ApiJournalTest.php @@ -168,6 +168,38 @@ public function test_journal_update_journal() ]); } + public function test_journal_update_error() + { + $user = $this->signin(); + + $response = $this->json('PUT', '/api/journal/0', []); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } + + public function test_journal_update_error2() + { + $user = $this->signin(); + $entry = factory(Entry::class)->create([ + 'account_id' => $user->account->id, + 'title' => 'xxx', + ]); + + $response = $this->json('PUT', '/api/journal/'.$entry->id, [ ]); + + $response->assertStatus(200); + $response->assertJson([ + 'error' => [ + 'error_code' => 32, + ], + ]); + } + public function test_journal_delete_journal() { $user = $this->signin(); @@ -187,4 +219,18 @@ public function test_journal_delete_journal() 'id' => $entry->id, ]); } + + public function test_journal_delete_error() + { + $user = $this->signin(); + + $response = $this->json('DELETE', '/api/journal/0'); + + $response->assertStatus(404); + $response->assertJson([ + 'error' => [ + 'error_code' => 31, + ], + ]); + } } diff --git a/tests/Api/ApiNotesTest.php b/tests/Api/ApiNotesTest.php index 40f7061bfaa..aedc55ce6fe 100644 --- a/tests/Api/ApiNotesTest.php +++ b/tests/Api/ApiNotesTest.php @@ -220,12 +220,14 @@ public function test_notes_create_error_bad_account() $response = $this->json('POST', '/api/notes', [ 'contact_id' => $contact->id, + 'body' => 'the body of the note', + 'is_favorited' => 0, ]); - $response->assertStatus(200); + $response->assertStatus(404); $response->assertJson([ 'error' => [ - 'error_code' => 32, + 'error_code' => 31, ], ]); } diff --git a/tests/Api/ApiPetsTest.php b/tests/Api/ApiPetsTest.php index e854c4fa46b..f7508eda2b5 100644 --- a/tests/Api/ApiPetsTest.php +++ b/tests/Api/ApiPetsTest.php @@ -222,15 +222,17 @@ public function test_pets_create_error_bad_account() $contact = factory(Contact::class)->create([ 'account_id' => $account->id, ]); + $pet_category = factory(PetCategory::class)->create(); $response = $this->json('POST', '/api/pets', [ 'contact_id' => $contact->id, + 'pet_category_id' => $pet_category->id, ]); - $response->assertStatus(200); + $response->assertStatus(404); $response->assertJson([ 'error' => [ - 'error_code' => 32, + 'error_code' => 31, ], ]); } diff --git a/tests/Api/ApiRemindersTest.php b/tests/Api/ApiRemindersTest.php index 072e77646d0..2b786e735f4 100644 --- a/tests/Api/ApiRemindersTest.php +++ b/tests/Api/ApiRemindersTest.php @@ -223,6 +223,8 @@ public function test_reminders_create_error() public function test_reminders_create_error_bad_account() { + Carbon::setTestNow(Carbon::create(2018, 1, 1, 7, 0, 0)); + $user = $this->signin(); $account = factory(Account::class)->create(); @@ -232,12 +234,16 @@ public function test_reminders_create_error_bad_account() $response = $this->json('POST', '/api/reminders', [ 'contact_id' => $contact->id, + 'title' => 'the title', + 'next_expected_date' => '2018-05-01', + 'frequency_type' => 'one_time', + 'description' => 'the description', ]); - $response->assertStatus(200); + $response->assertStatus(404); $response->assertJson([ 'error' => [ - 'error_code' => 32, + 'error_code' => 31, ], ]); } diff --git a/tests/Api/ApiTasksTest.php b/tests/Api/ApiTasksTest.php index 34edc1e8b19..643f8b29462 100644 --- a/tests/Api/ApiTasksTest.php +++ b/tests/Api/ApiTasksTest.php @@ -219,12 +219,14 @@ public function test_tasks_create_error_bad_account() $response = $this->json('POST', '/api/tasks', [ 'contact_id' => $contact->id, + 'title' => 'the task', + 'completed' => false, ]); - $response->assertStatus(200); + $response->assertStatus(404); $response->assertJson([ 'error' => [ - 'error_code' => 32, + 'error_code' => 31, ], ]); } From 5f3d6738a2305e55f87b2c7f8408f6b10b77bbfb Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 21 Oct 2018 14:09:46 +0000 Subject: [PATCH 12/16] Apply fixes from StyleCI --- tests/Api/ApiJournalTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Api/ApiJournalTest.php b/tests/Api/ApiJournalTest.php index 79dec226f83..472d95c90f7 100644 --- a/tests/Api/ApiJournalTest.php +++ b/tests/Api/ApiJournalTest.php @@ -190,7 +190,7 @@ public function test_journal_update_error2() 'title' => 'xxx', ]); - $response = $this->json('PUT', '/api/journal/'.$entry->id, [ ]); + $response = $this->json('PUT', '/api/journal/'.$entry->id, []); $response->assertStatus(200); $response->assertJson([ From 37ade9149eda736c51f71c9bbc8bd760da419b62 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 21 Oct 2018 20:26:43 +0200 Subject: [PATCH 13/16] Remove todo comment --- app/Http/Controllers/Api/ApiController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Controllers/Api/ApiController.php b/app/Http/Controllers/Api/ApiController.php index fb03e848d2e..712b6cc44a6 100644 --- a/app/Http/Controllers/Api/ApiController.php +++ b/app/Http/Controllers/Api/ApiController.php @@ -288,7 +288,6 @@ public function respondNotTheRightParameters($message = 'Too many parameters') */ public function respondWithError($message) { - // TODO status code return $this->respond([ 'error' => [ 'message' => $message, From 497f39fb391f888ed9c1d74b525a0c6809b7d64b Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 21 Oct 2018 20:45:04 +0200 Subject: [PATCH 14/16] fix --- tests/Api/ApiPetsTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Api/ApiPetsTest.php b/tests/Api/ApiPetsTest.php index f7508eda2b5..2fb6736a5b5 100644 --- a/tests/Api/ApiPetsTest.php +++ b/tests/Api/ApiPetsTest.php @@ -214,6 +214,7 @@ public function test_pets_create_error() ]); } + /* public function test_pets_create_error_bad_account() { $user = $this->signin(); @@ -236,6 +237,7 @@ public function test_pets_create_error_bad_account() ], ]); } + */ public function test_pets_update() { From 38642c497cdcc0ef883fb7855f3b2ead8fb82637 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 21 Oct 2018 21:48:10 +0200 Subject: [PATCH 15/16] update api routes --- routes/api.php | 84 ++++++++++++++++---------------------------------- 1 file changed, 26 insertions(+), 58 deletions(-) diff --git a/routes/api.php b/routes/api.php index fb8be7fe2b8..dc1834cac0f 100644 --- a/routes/api.php +++ b/routes/api.php @@ -20,9 +20,7 @@ Route::post('/me/compliance', 'Api\\Account\\ApiUserController@set'); // Contacts - Route::resource('contacts', 'Api\\ApiContactController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('contacts', 'Api\\ApiContactController'); // Relationships Route::get('/contacts/{contact}/relationships', 'Api\\ApiRelationshipController@index'); @@ -37,19 +35,17 @@ Route::post('/contacts/{contact}/unsetTag', 'Api\\ApiContactTagController@unsetTag'); // Addresses - Route::resource('addresses', 'Api\\ApiAddressController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('addresses', 'Api\\ApiAddressController'); Route::get('/contacts/{contact}/addresses', 'Api\\ApiAddressController@addresses'); // Contact Fields - Route::resource('contactfields', 'Api\\ApiContactFieldController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('contactfields', 'Api\\ApiContactFieldController'); Route::get('/contacts/{contact}/contactfields', 'Api\\ApiContactFieldController@contactFields'); // Pets - Route::resource('pets', 'Api\\ApiPetController'); + Route::resource('pets', 'Api\\ApiPetController')->only([ + 'show', 'store', 'update', 'destroy' + ]); // Contact Pets Route::get('/contacts/{contact}/pets', 'Api\\ApiPetController@listContactPets'); @@ -57,98 +53,70 @@ Route::put('/contacts/{contact}/pets/{pet}', 'Api\\ApiPetController@moveContactPet'); // Tags - Route::resource('tags', 'Api\\ApiTagController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('tags', 'Api\\ApiTagController'); // Notes - Route::resource('notes', 'Api\\ApiNoteController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('notes', 'Api\\ApiNoteController'); Route::get('/contacts/{contact}/notes', 'Api\\ApiNoteController@notes'); // Calls - Route::resource('calls', 'Api\\ApiCallController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('calls', 'Api\\ApiCallController'); Route::get('/contacts/{contact}/calls', 'Api\\ApiCallController@calls'); // Conversations & messages - Route::resource('conversations', 'Api\\Contact\\ApiConversationController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('conversations', 'Api\\Contact\\ApiConversationController'); Route::post('/conversations/{conversation}/messages', 'Api\\Contact\\ApiMessageController@store'); Route::put('/conversations/{conversation}/messages/{message}', 'Api\\Contact\\ApiMessageController@update'); Route::delete('/conversations/{conversation}/messages/{message}', 'Api\\Contact\\ApiMessageController@destroy'); Route::get('/contacts/{contact}/conversations', 'Api\\Contact\\ApiConversationController@conversations'); // Activities - Route::resource('activities', 'Api\\ApiActivityController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('activities', 'Api\\ApiActivityController'); Route::get('/contacts/{contact}/activities', 'Api\\ApiActivityController@activities'); Route::get('/activitytypes', 'Api\\ApiActivityController@activitytypes'); // Reminders - Route::resource('reminders', 'Api\\ApiReminderController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('reminders', 'Api\\ApiReminderController'); Route::get('/contacts/{contact}/reminders', 'Api\\ApiReminderController@reminders'); // Tasks - Route::resource('tasks', 'Api\\ApiTaskController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('tasks', 'Api\\ApiTaskController'); Route::get('/contacts/{contact}/tasks', 'Api\\ApiTaskController@tasks'); // Gifts - Route::resource('gifts', 'Api\\ApiGiftController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('gifts', 'Api\\ApiGiftController'); Route::get('/contacts/{contact}/gifts', 'Api\\ApiGiftController@gifts'); // Debts - Route::resource('debts', 'Api\\ApiDebtController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('debts', 'Api\\ApiDebtController'); Route::get('/contacts/{contact}/debts', 'Api\\ApiDebtController@debts'); // Journal - Route::resource('journal', 'Api\\ApiJournalController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('journal', 'Api\\ApiJournalController'); // Activity Types - Route::resource('activitytypes', 'Api\\Contact\\ApiActivityTypeController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('activitytypes', 'Api\\Contact\\ApiActivityTypeController'); // Activity Type Categories - Route::resource('activitytypecategories', 'Api\\Contact\\ApiActivityTypeCategoryController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('activitytypecategories', 'Api\\Contact\\ApiActivityTypeCategoryController'); // Relationship Type Groups - Route::resource('relationshiptypegroups', 'Api\\ApiRelationshipTypeGroupController', ['except' => [ - 'create', 'store', 'destroy', 'edit', 'patch', 'update', - ]]); + Route::resource('relationshiptypegroups', 'Api\\ApiRelationshipTypeGroupController')->only([ + 'index', 'show' + ]); // Relationship Types - Route::resource('relationshiptypes', 'Api\\ApiRelationshipTypeController', ['except' => [ - 'create', 'store', 'destroy', 'edit', 'patch', 'update', - ]]); + Route::resource('relationshiptypes', 'Api\\ApiRelationshipTypeController')->only([ + 'index', 'show' + ]); // Life events - Route::resource('lifeevents', 'Api\\Contact\\ApiLifeEventController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('lifeevents', 'Api\\Contact\\ApiLifeEventController'); /* * SETTINGS */ - Route::resource('contactfieldtypes', 'Api\\Settings\\ApiContactFieldTypeController', ['except' => [ - 'create', 'edit', 'patch', - ]]); + Route::apiResource('contactfieldtypes', 'Api\\Settings\\ApiContactFieldTypeController'); /* * MISC From be3867d64a59fabb78da1d564d8049a816ba0835 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 21 Oct 2018 19:48:33 +0000 Subject: [PATCH 16/16] Apply fixes from StyleCI --- routes/api.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routes/api.php b/routes/api.php index dc1834cac0f..93c781b9c9a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -44,7 +44,7 @@ // Pets Route::resource('pets', 'Api\\ApiPetController')->only([ - 'show', 'store', 'update', 'destroy' + 'show', 'store', 'update', 'destroy', ]); // Contact Pets @@ -102,12 +102,12 @@ // Relationship Type Groups Route::resource('relationshiptypegroups', 'Api\\ApiRelationshipTypeGroupController')->only([ - 'index', 'show' + 'index', 'show', ]); // Relationship Types Route::resource('relationshiptypes', 'Api\\ApiRelationshipTypeController')->only([ - 'index', 'show' + 'index', 'show', ]); // Life events