also looking at this
Add More Tests
#42
6 files
+170
-26
| @@ -51,12 +51,14 @@ class Favorite | ||
| 51 | 51 | return $this->all(); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | if (! is_int($id)) { | |
| 55 | throw new InvalidFormatException(); | |
| 56 | } | |
| 57 | ||
| 58 | 54 | $ids = is_array($id) ? $id : func_get_args(); |
| 59 | 55 | |
| 56 | foreach ($ids as $id) { | |
| 57 | if (! is_int($id)) { | |
| 58 | throw new InvalidFormatException(); | |
| 59 | } | |
| 60 | } | |
| 61 | ||
| 60 | 62 | return $this->client->request('GET', 'favorites', ['favorite_ids' => $ids]); |
| 61 | 63 | } |
| 62 | 64 | |
| @@ -60,12 +60,14 @@ class Tag | ||
| 60 | 60 | return $this->all(); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | if (! is_int($id)) { | |
| 64 | throw new InvalidFormatException(); | |
| 65 | } | |
| 66 | ||
| 67 | 63 | $ids = is_array($id) ? $id : func_get_args(); |
| 68 | 64 | |
| 65 | foreach ($ids as $id) { | |
| 66 | if (! is_int($id)) { | |
| 67 | throw new InvalidFormatException(); | |
| 68 | } | |
| 69 | } | |
| 70 | ||
| 69 | 71 | return $this->client->request('GET', 'tags', ['tag_ids' => $ids]); |
| 70 | 72 | } |
| 71 | 73 | |
| @@ -87,20 +89,6 @@ class Tag | ||
| 87 | 89 | return new Response($this, $response); |
| 88 | 90 | } |
| 89 | 91 | |
| 90 | /** | |
| 91 | * Create folder. | |
| 92 | * | |
| 93 | * @param string $name | |
| 94 | * | |
| 95 | * @return array | |
| 96 | */ | |
| 97 | public function create($name): array | |
| 98 | { | |
| 99 | $name = is_array($name) ? $name : compact('name'); | |
| 100 | ||
| 101 | return $this->client->request('POST', "tags/{$this->client->getAccessKey()}", $name); | |
| 102 | } | |
| 103 | ||
| 104 | 92 | /** |
| 105 | 93 | * Update folder. |
| 106 | 94 | * |
| @@ -109,12 +97,18 @@ class Tag | ||
| 109 | 97 | * |
| 110 | 98 | * @return array |
| 111 | 99 | */ |
| 112 | public function update($id, $data): array | |
| 100 | public function update($id, $color): array | |
| 113 | 101 | { |
| 114 | 102 | if (! is_int($id)) { |
| 115 | 103 | throw new InvalidFormatException(); |
| 116 | 104 | } |
| 117 | 105 | |
| 106 | $data = [ | |
| 107 | 'color' => $color, | |
| 108 | 'tag_id' => $id, | |
| 109 | 'team_id' => 1, | |
| 110 | ]; | |
| 111 | ||
| 118 | 112 | return $this->client->request('PATCH', 'tags/color', $data); |
| 119 | 113 | } |
| 120 | 114 | |
| @@ -0,0 +1,60 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | uses(Tests\ClientTest::class); | |
| 4 | ||
| 5 | beforeEach(function () { | |
| 6 | $this->initializeDotEnv(); | |
| 7 | $this->initializeClient(); | |
| 8 | }); | |
| 9 | ||
| 10 | it('can fetch all favorites', function () { | |
| 11 | $favorites = $this->client->favorites()->get(); | |
| 12 | ||
| 13 | $this->assertTrue(is_array($favorites)); | |
| 14 | $this->assertTrue(count($favorites) > 0); | |
| 15 | }); | |
| 16 | ||
| 17 | it('can fetch specific group of favorites', function () { | |
| 18 | $ids = [7, 8, 9]; | |
| 19 | ||
| 20 | $favorites = $this->client->favorites()->get($ids); | |
| 21 | ||
| 22 | $this->assertTrue(is_array($favorites)); | |
| 23 | $this->assertTrue(count($favorites['data']) === count($ids)); | |
| 24 | }); | |
| 25 | ||
| 26 | it('can find a single favorite', function () { | |
| 27 | $id = 7; | |
| 28 | ||
| 29 | $favorites = $this->client->favorites()->find($id)->toArray(); | |
| 30 | ||
| 31 | $this->assertTrue(is_array($favorites)); | |
| 32 | $this->assertTrue(count($favorites) === 1); | |
| 33 | }); | |
| 34 | ||
| 35 | it('can create a favorite', function () { | |
| 36 | $data = ['name' => 'test favorite', 'icon' => 'house']; | |
| 37 | ||
| 38 | $favorite = $this->client->favorites()->create($data); | |
| 39 | ||
| 40 | $this->assertTrue(is_array($favorite)); | |
| 41 | $this->assertTrue($favorite['data']['name'] === $data['name']); | |
| 42 | }); | |
| 43 | ||
| 44 | it('can update a favorite', function () { | |
| 45 | $data = ['name' => 'test favorite update', 'icon' => 'home']; | |
| 46 | ||
| 47 | $favorites = $this->client->favorites()->update(7, $data); | |
| 48 | ||
| 49 | $this->assertTrue(is_array($favorites)); | |
| 50 | $this->assertTrue($favorites['data']['name'] === $data['name']); | |
| 51 | }); | |
| 52 | ||
| 53 | it('can delete a favorite', function () { | |
| 54 | $favorites = $this->client->tags()->get(); | |
| 55 | ||
| 56 | $favorites = array_reverse($favorites['data']); | |
| 57 | $response = $this->client->tags()->delete($favorites[0]['id']); | |
| 58 | ||
| 59 | $this->assertTrue(is_null($response)); | |
| 60 | }); | |
| @@ -7,14 +7,14 @@ beforeEach(function () { | ||
| 7 | 7 | $this->initializeClient(); |
| 8 | 8 | }); |
| 9 | 9 | |
| 10 | it('can be fetch all folders', function () { | |
| 10 | it('can fetch all folders', function () { | |
| 11 | 11 | $folders = $this->client->folders()->get(); |
| 12 | 12 | |
| 13 | 13 | $this->assertTrue(is_array($folders)); |
| 14 | 14 | $this->assertTrue(count($folders) > 0); |
| 15 | 15 | }); |
| 16 | 16 | |
| 17 | it('can be fetch specific group of folders', function () { | |
| 17 | it('can fetch specific group of folders', function () { | |
| 18 | 18 | $ids = [1, 2, 3]; |
| 19 | 19 | |
| 20 | 20 | $folders = $this->client->folders()->get($ids); |
| @@ -14,6 +14,26 @@ it('can be fetch all media', function () { | ||
| 14 | 14 | $this->assertTrue(count($media) > 0); |
| 15 | 15 | }); |
| 16 | 16 | |
| 17 | it('can be fetch all media for a tag', function () { | |
| 18 | // 8 is the tag id for images | |
| 19 | $tag = $this->client->tags()->find(8); | |
| 20 | ||
| 21 | $media = $tag->media()->get(); | |
| 22 | ||
| 23 | $this->assertTrue(is_array($media)); | |
| 24 | $this->assertTrue(count($media) > 0); | |
| 25 | }); | |
| 26 | ||
| 27 | it('can be fetch all media for a folder', function () { | |
| 28 | // 8 is the tag id for images | |
| 29 | $folder = $this->client->folders()->find(1); | |
| 30 | ||
| 31 | $media = $folder->media()->get(); | |
| 32 | ||
| 33 | $this->assertTrue(is_array($media)); | |
| 34 | $this->assertTrue(count($media) > 0); | |
| 35 | }); | |
| 36 | ||
| 17 | 37 | it('can be fetch specific group of media', function () { |
| 18 | 38 | $ids = [1, 2, 3]; |
| 19 | 39 | |
| @@ -42,7 +62,8 @@ it('can update a media', function () { | ||
| 42 | 62 | }); |
| 43 | 63 | |
| 44 | 64 | it('can search a media', function () { |
| 45 | $query = 'people'; | |
| 65 | $mediaName = $this->client->media()->find(1)->toArray(); | |
| 66 | $query = $mediaName['name']; | |
| 46 | 67 | |
| 47 | 68 | $media = $this->client->media()->search($query); |
| 48 | 69 | |
| @@ -0,0 +1,67 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | uses(Tests\ClientTest::class); | |
| 4 | ||
| 5 | beforeEach(function () { | |
| 6 | $this->initializeDotEnv(); | |
| 7 | $this->initializeClient(); | |
| 8 | }); | |
| 9 | ||
| 10 | it('can fetch all tags', function () { | |
| 11 | $tags = $this->client->tags()->get(); | |
| 12 | ||
| 13 | $this->assertTrue(is_array($tags)); | |
| 14 | $this->assertTrue(count($tags) > 0); | |
| 15 | }); | |
| 16 | ||
| 17 | it('can fetch specific group of tags', function () { | |
| 18 | $ids = [7, 8, 9]; | |
| 19 | ||
| 20 | $tags = $this->client->tags()->get($ids); | |
| 21 | ||
| 22 | $this->assertTrue(is_array($tags)); | |
| 23 | $this->assertTrue(count($tags['data']) === count($ids)); | |
| 24 | }); | |
| 25 | ||
| 26 | it('can find a single tag', function () { | |
| 27 | $id = 7; | |
| 28 | ||
| 29 | $tags = $this->client->tags()->find($id)->toArray(); | |
| 30 | ||
| 31 | $this->assertTrue(is_array($tags)); | |
| 32 | $this->assertTrue(count($tags) === 1); | |
| 33 | }); | |
| 34 | ||
| 35 | it('can update a tag', function () { | |
| 36 | $color = 'purple-600'; | |
| 37 | ||
| 38 | $tags = $this->client->tags()->update(7, $color); | |
| 39 | ||
| 40 | $this->assertTrue(is_array($tags)); | |
| 41 | $this->assertTrue($tags['data']['color'] === $color); | |
| 42 | }); | |
| 43 | ||
| 44 | it('can delete a tag', function () { | |
| 45 | $tags = $this->client->tags()->get(); | |
| 46 | ||
| 47 | $tags = array_reverse($tags['data']); | |
| 48 | $response = $this->client->tags()->delete($tags[0]['id']); | |
| 49 | ||
| 50 | $this->assertTrue(is_null($response)); | |
| 51 | }); | |
| 52 | ||
| 53 | it('can fetch all media tags', function () { | |
| 54 | $media = $this->client->media()->find(1); | |
| 55 | $tags = $media->tags()->get(); | |
| 56 | ||
| 57 | $this->assertTrue(is_array($tags)); | |
| 58 | $this->assertTrue(count($tags['data'][0]) > 0); | |
| 59 | }); | |
| 60 | ||
| 61 | it('can fetch all folder tags', function () { | |
| 62 | $folder = $this->client->folders()->find(1); | |
| 63 | $tags = $folder->tags()->get(); | |
| 64 | ||
| 65 | $this->assertTrue(is_array($tags)); | |
| 66 | $this->assertTrue(count($tags['data'][0]) > 0); | |
| 67 | }); | |