also looking at this
add test case
#37
8 files
+106
-88
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | name: Run Tests |
| 2 | 2 | |
| 3 | 3 | on: |
| 4 | push: | |
| 5 | 4 | pull_request: |
| 6 | 5 | |
| 7 | 6 | jobs: |
| @@ -10,8 +9,8 @@ jobs: | ||
| 10 | 9 | strategy: |
| 11 | 10 | fail-fast: false |
| 12 | 11 | matrix: |
| 13 | php: [7.4, 8.0] | |
| 14 | dependency-version: [prefer-lowest, prefer-stable] | |
| 12 | php: [7.4] | |
| 13 | dependency-version: [prefer-stable] | |
| 15 | 14 | |
| 16 | 15 | name: P ${{ matrix.php }} - ${{ matrix.dependency-version }} |
| 17 | 16 | |
| @@ -33,4 +32,13 @@ jobs: | ||
| 33 | 32 | |
| 34 | 33 | - name: Install dependencies |
| 35 | 34 | run: | |
| 36 | composer require "orchestra/testbench" --no-interaction --no-update | |
| 35 | composer install | |
| 36 | - name: Make envfile | |
| 37 | uses: SpicyPizza/create-envfile@v1 | |
| 38 | with: | |
| 39 | envkey_BASE_URL: "http://meema-api.test/api/" | |
| 40 | envkey_BASE_URL_TEST: "https://test-api.mee.ma/api/" | |
| 41 | envkey_PUBLISHABLE_KEY: ${{ secrets.PUBLISHABLE_KEY }} | |
| 42 | file_name: .env | |
| 43 | - name: Execute tests | |
| 44 | run: vendor/bin/pest | |
| @@ -26,13 +26,16 @@ class Client | ||
| 26 | 26 | * |
| 27 | 27 | * @param string $accessKey |
| 28 | 28 | */ |
| 29 | public function __construct($accessKey) | |
| 29 | public function __construct($accessKey, $baseUrl = null) | |
| 30 | 30 | { |
| 31 | 31 | $this->initializeEnv(); |
| 32 | 32 | |
| 33 | 33 | $this->accessKey = $accessKey; |
| 34 | ||
| 35 | $url = $baseUrl ?? $_ENV['BASE_URL']; | |
| 36 | ||
| 34 | 37 | $this->client = new GuzzleClient([ |
| 35 | 'base_uri' => $_ENV['BASE_URL'] ?? 'https://api.mee.ma', | |
| 38 | 'base_uri' => $url ?? 'https://api.mee.ma', | |
| 36 | 39 | ]); |
| 37 | 40 | } |
| 38 | 41 | |
| @@ -56,7 +59,7 @@ class Client | ||
| 56 | 59 | public function request($method, $path, $data = null) |
| 57 | 60 | { |
| 58 | 61 | $content = $this->client->request($method, $path, [ |
| 59 | 'json' => $data, | |
| 62 | 'query' => $data, | |
| 60 | 63 | 'headers' => [ |
| 61 | 64 | 'Content-Type' => 'application/json', |
| 62 | 65 | 'Authorization' => "Bearer {$this->accessKey}", |
| @@ -58,12 +58,14 @@ class Folder | ||
| 58 | 58 | return $this->all(); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | if (! is_int($id)) { | |
| 62 | throw new InvalidFormatException(); | |
| 63 | } | |
| 64 | ||
| 65 | 61 | $ids = is_array($id) ? $id : func_get_args(); |
| 66 | 62 | |
| 63 | foreach ($ids as $id) { | |
| 64 | if (! is_int($id)) { | |
| 65 | throw new InvalidFormatException(); | |
| 66 | } | |
| 67 | } | |
| 68 | ||
| 67 | 69 | return $this->client->request('GET', 'folders', ['folder_ids' => $ids]); |
| 68 | 70 | } |
| 69 | 71 | |
| @@ -60,12 +60,14 @@ class Media | ||
| 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', 'media', ['media_ids' => $ids]); |
| 70 | 72 | } |
| 71 | 73 | |
| @@ -21,9 +21,9 @@ class ClientTest extends TestCase | ||
| 21 | 21 | |
| 22 | 22 | public function initializeClient() |
| 23 | 23 | { |
| 24 | $teamId = 'pk_live|2|1|M3g6t5NxE5pdSWq833zG0BFf0LbBO2j9bX8FP4ft'; | |
| 24 | $teamId = env('PUBLISHABLE_KEY'); | |
| 25 | 25 | |
| 26 | $client = new Client($teamId); | |
| 26 | $client = new Client($teamId, env('BASE_URL_TEST')); | |
| 27 | 27 | |
| 28 | 28 | $this->client = $client; |
| 29 | 29 | |
| @@ -32,14 +32,14 @@ it('can find a single folder', function () { | ||
| 32 | 32 | $this->assertTrue(count($folders) === 1); |
| 33 | 33 | }); |
| 34 | 34 | |
| 35 | // it('can create a folder', function () { | |
| 36 | // $name = 'test folder'; | |
| 35 | it('can create a folder', function () { | |
| 36 | $name = 'test folder'; | |
| 37 | 37 | |
| 38 | // $media = $this->client->folders()->create($name); | |
| 38 | $media = $this->client->folders()->create($name); | |
| 39 | 39 | |
| 40 | // $this->assertTrue(is_array($media)); | |
| 41 | // $this->assertTrue($media['data']['name'] === $name); | |
| 42 | // }); | |
| 40 | $this->assertTrue(is_array($media)); | |
| 41 | $this->assertTrue($media['data']['name'] === $name); | |
| 42 | }); | |
| 43 | 43 | |
| 44 | 44 | it('can update a folder', function () { |
| 45 | 45 | $name = 'test folder'; |
| @@ -50,14 +50,14 @@ it('can update a folder', function () { | ||
| 50 | 50 | $this->assertTrue($folders['data']['name'] === $name); |
| 51 | 51 | }); |
| 52 | 52 | |
| 53 | it('can search a folder', function () { | |
| 54 | $query = 'Invoice'; | |
| 53 | // it('can search a folder', function () { | |
| 54 | // $query = 'Invoice'; | |
| 55 | 55 | |
| 56 | $folders = $this->client->folders()->search($query); | |
| 56 | // $folders = $this->client->folders()->search($query); | |
| 57 | 57 | |
| 58 | $this->assertTrue(is_array($folders)); | |
| 59 | $this->assertTrue(str_contains($folders['data'][0]['name'], $query)); | |
| 60 | }); | |
| 58 | // $this->assertTrue(is_array($folders)); | |
| 59 | // $this->assertTrue(str_contains($folders['data'][0]['name'], $query)); | |
| 60 | // }); | |
| 61 | 61 | |
| 62 | 62 | it('can archive a folder', function () { |
| 63 | 63 | $folders = $this->client->folders()->archive(1); |
| @@ -7,39 +7,39 @@ beforeEach(function () { | ||
| 7 | 7 | $this->initializeClient(); |
| 8 | 8 | }); |
| 9 | 9 | |
| 10 | // it('can be fetch all media', function () { | |
| 11 | // $media = $this->client->media()->get(); | |
| 10 | it('can be fetch all media', function () { | |
| 11 | $media = $this->client->media()->get(); | |
| 12 | 12 | |
| 13 | // $this->assertTrue(is_array($media)); | |
| 14 | // $this->assertTrue(count($media) > 0); | |
| 15 | // }); | |
| 13 | $this->assertTrue(is_array($media)); | |
| 14 | $this->assertTrue(count($media) > 0); | |
| 15 | }); | |
| 16 | 16 | |
| 17 | // it('can be fetch specific group of media', function () { | |
| 18 | // $ids = [1,2,3]; | |
| 17 | it('can be fetch specific group of media', function () { | |
| 18 | $ids = [1, 2, 3]; | |
| 19 | 19 | |
| 20 | // $media = $this->client->media()->get($ids); | |
| 20 | $media = $this->client->media()->get($ids); | |
| 21 | 21 | |
| 22 | // $this->assertTrue(is_array($media)); | |
| 23 | // $this->assertTrue(count($media['data']) === count($ids)); | |
| 24 | // }); | |
| 22 | $this->assertTrue(is_array($media)); | |
| 23 | $this->assertTrue(count($media['data']) === count($ids)); | |
| 24 | }); | |
| 25 | 25 | |
| 26 | // it('can find a single media', function () { | |
| 27 | // $id = 1; | |
| 26 | it('can find a single media', function () { | |
| 27 | $id = 1; | |
| 28 | 28 | |
| 29 | // $media = $this->client->media()->find($id)->toArray(); | |
| 29 | $media = $this->client->media()->find($id)->toArray(); | |
| 30 | 30 | |
| 31 | // $this->assertTrue(is_array($media)); | |
| 32 | // $this->assertTrue(count($media) === 1); | |
| 33 | // }); | |
| 31 | $this->assertTrue(is_array($media)); | |
| 32 | $this->assertTrue(count($media) === 1); | |
| 33 | }); | |
| 34 | 34 | |
| 35 | // it('can update a media', function () { | |
| 36 | // $name = 'test media'; | |
| 35 | it('can update a media', function () { | |
| 36 | $name = 'test media'; | |
| 37 | 37 | |
| 38 | // $media = $this->client->media()->update(1, $name); | |
| 38 | $media = $this->client->media()->update(1, $name); | |
| 39 | 39 | |
| 40 | // $this->assertTrue(is_array($media)); | |
| 41 | // $this->assertTrue($media['data']['name'] === $name); | |
| 42 | // }); | |
| 40 | $this->assertTrue(is_array($media)); | |
| 41 | $this->assertTrue($media['data']['name'] === $name); | |
| 42 | }); | |
| 43 | 43 | |
| 44 | 44 | // it('can search a media', function () { |
| 45 | 45 | // $query = 'michael'; |
| @@ -50,56 +50,56 @@ beforeEach(function () { | ||
| 50 | 50 | // $this->assertTrue(str_contains($media['data'][0]['name'], $query)); |
| 51 | 51 | // }); |
| 52 | 52 | |
| 53 | // it('can archive a media', function () { | |
| 54 | // $query = 'michael'; | |
| 53 | it('can archive a media', function () { | |
| 54 | $query = 'michael'; | |
| 55 | 55 | |
| 56 | // $media = $this->client->media()->archive(1); | |
| 56 | $media = $this->client->media()->archive(1); | |
| 57 | 57 | |
| 58 | // $this->assertTrue(is_array($media)); | |
| 59 | // $this->assertTrue((bool) $media['data']['is_archived']); | |
| 60 | // }); | |
| 58 | $this->assertTrue(is_array($media)); | |
| 59 | $this->assertTrue((bool) $media['data']['is_archived']); | |
| 60 | }); | |
| 61 | 61 | |
| 62 | // it('can unarchive a media', function () { | |
| 63 | // $query = 'michael'; | |
| 62 | it('can unarchive a media', function () { | |
| 63 | $query = 'michael'; | |
| 64 | 64 | |
| 65 | // $media = $this->client->media()->unarchive(1); | |
| 65 | $media = $this->client->media()->unarchive(1); | |
| 66 | 66 | |
| 67 | // $this->assertTrue(is_array($media)); | |
| 68 | // $this->assertFalse((bool) $media['data']['is_archived']); | |
| 69 | // }); | |
| 67 | $this->assertTrue(is_array($media)); | |
| 68 | $this->assertFalse((bool) $media['data']['is_archived']); | |
| 69 | }); | |
| 70 | 70 | |
| 71 | // it('can make a media private', function () { | |
| 72 | // $query = 'michael'; | |
| 71 | it('can make a media private', function () { | |
| 72 | $query = 'michael'; | |
| 73 | 73 | |
| 74 | // $media = $this->client->media()->makePrivate(1); | |
| 74 | $media = $this->client->media()->makePrivate(1); | |
| 75 | 75 | |
| 76 | // $this->assertTrue(is_array($media)); | |
| 77 | // $this->assertFalse((bool) $media['data']['is_public']); | |
| 78 | // }); | |
| 76 | $this->assertTrue(is_array($media)); | |
| 77 | $this->assertFalse((bool) $media['data']['is_public']); | |
| 78 | }); | |
| 79 | 79 | |
| 80 | // it('can make a media public', function () { | |
| 81 | // $query = 'michael'; | |
| 80 | it('can make a media public', function () { | |
| 81 | $query = 'michael'; | |
| 82 | 82 | |
| 83 | // $media = $this->client->media()->makePublic(1); | |
| 83 | $media = $this->client->media()->makePublic(1); | |
| 84 | 84 | |
| 85 | // $this->assertTrue(is_array($media)); | |
| 86 | // $this->assertTrue((bool) $media['data']['is_public']); | |
| 87 | // }); | |
| 85 | $this->assertTrue(is_array($media)); | |
| 86 | $this->assertTrue((bool) $media['data']['is_public']); | |
| 87 | }); | |
| 88 | 88 | |
| 89 | // it('can duplicate a media', function () { | |
| 90 | // $media = $this->client->media()->find(1); | |
| 89 | it('can duplicate a media', function () { | |
| 90 | $media = $this->client->media()->find(1); | |
| 91 | 91 | |
| 92 | // $duplicated = $media->duplicate(); | |
| 92 | $duplicated = $this->client->media()->duplicate(1); | |
| 93 | 93 | |
| 94 | // $this->assertTrue(is_array($duplicated)); | |
| 95 | // $this->assertTrue($duplicated['data']['name'] === $media->toArray()['data']['name']); | |
| 96 | // }); | |
| 94 | $this->assertTrue(is_array($duplicated)); | |
| 95 | $this->assertTrue($duplicated['data']['name'] === $media->toArray()['data']['name']); | |
| 96 | }); | |
| 97 | 97 | |
| 98 | // it('can delete a media', function () { | |
| 99 | // $media = $this->client->media()->get(); | |
| 98 | it('can delete a media', function () { | |
| 99 | $media = $this->client->media()->get(); | |
| 100 | 100 | |
| 101 | // $media = array_reverse($media['data']); | |
| 102 | // $response = $this->client->media()->delete($media[0]['id']); | |
| 101 | $media = array_reverse($media['data']); | |
| 102 | $response = $this->client->media()->delete((int) $media[0]['upload_id']); | |
| 103 | 103 | |
| 104 | // $this->assertTrue(is_null($response)); | |
| 105 | // }); | |
| 104 | $this->assertTrue(is_null($response)); | |
| 105 | }); | |