ReviewOS

also looking at this

meemalabs/meema-client-php

Add More Tests

#42
Merged glennmichael123 wants to merge add-more-tests into main
6 files +170 -26
src/Models/Favorite.phpmodified+6-4
Changes to src/Models/Favorite.php
@@ -51,12 +51,14 @@ class Favorite
5151 return $this->all();
5252 }
5353
54 if (! is_int($id)) {
55 throw new InvalidFormatException();
56 }
57
5854 $ids = is_array($id) ? $id : func_get_args();
5955
56 foreach ($ids as $id) {
57 if (! is_int($id)) {
58 throw new InvalidFormatException();
59 }
60 }
61
6062 return $this->client->request('GET', 'favorites', ['favorite_ids' => $ids]);
6163 }
6264
src/Models/Tag.phpmodified+13-19
Changes to src/Models/Tag.php
@@ -60,12 +60,14 @@ class Tag
6060 return $this->all();
6161 }
6262
63 if (! is_int($id)) {
64 throw new InvalidFormatException();
65 }
66
6763 $ids = is_array($id) ? $id : func_get_args();
6864
65 foreach ($ids as $id) {
66 if (! is_int($id)) {
67 throw new InvalidFormatException();
68 }
69 }
70
6971 return $this->client->request('GET', 'tags', ['tag_ids' => $ids]);
7072 }
7173
@@ -87,20 +89,6 @@ class Tag
8789 return new Response($this, $response);
8890 }
8991
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
10492 /**
10593 * Update folder.
10694 *
@@ -109,12 +97,18 @@ class Tag
10997 *
11098 * @return array
11199 */
112 public function update($id, $data): array
100 public function update($id, $color): array
113101 {
114102 if (! is_int($id)) {
115103 throw new InvalidFormatException();
116104 }
117105
106 $data = [
107 'color' => $color,
108 'tag_id' => $id,
109 'team_id' => 1,
110 ];
111
118112 return $this->client->request('PATCH', 'tags/color', $data);
119113 }
120114
tests/MeemaFavoriteTest.phpadded+60-0
Changes to tests/MeemaFavoriteTest.php
@@ -0,0 +1,60 @@
1<?php
2
3uses(Tests\ClientTest::class);
4
5beforeEach(function () {
6 $this->initializeDotEnv();
7 $this->initializeClient();
8});
9
10it('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
17it('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
26it('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
35it('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
44it('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
53it('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});
tests/MeemaFolderTest.phpmodified+2-2
Changes to tests/MeemaFolderTest.php
@@ -7,14 +7,14 @@ beforeEach(function () {
77 $this->initializeClient();
88});
99
10it('can be fetch all folders', function () {
10it('can fetch all folders', function () {
1111 $folders = $this->client->folders()->get();
1212
1313 $this->assertTrue(is_array($folders));
1414 $this->assertTrue(count($folders) > 0);
1515});
1616
17it('can be fetch specific group of folders', function () {
17it('can fetch specific group of folders', function () {
1818 $ids = [1, 2, 3];
1919
2020 $folders = $this->client->folders()->get($ids);
tests/MeemaMediaTest.phpmodified+22-1
Changes to tests/MeemaMediaTest.php
@@ -14,6 +14,26 @@ it('can be fetch all media', function () {
1414 $this->assertTrue(count($media) > 0);
1515});
1616
17it('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
27it('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
1737it('can be fetch specific group of media', function () {
1838 $ids = [1, 2, 3];
1939
@@ -42,7 +62,8 @@ it('can update a media', function () {
4262});
4363
4464it('can search a media', function () {
45 $query = 'people';
65 $mediaName = $this->client->media()->find(1)->toArray();
66 $query = $mediaName['name'];
4667
4768 $media = $this->client->media()->search($query);
4869
tests/MeemaTagTest.phpadded+67-0
Changes to tests/MeemaTagTest.php
@@ -0,0 +1,67 @@
1<?php
2
3uses(Tests\ClientTest::class);
4
5beforeEach(function () {
6 $this->initializeDotEnv();
7 $this->initializeClient();
8});
9
10it('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
17it('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
26it('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
35it('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
44it('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
53it('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
61it('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});