diff --git a/src/ControlD.php b/src/ControlD.php index ede9fba..92faa34 100644 --- a/src/ControlD.php +++ b/src/ControlD.php @@ -8,6 +8,7 @@ use Rapkis\Controld\Resources\Access; use Rapkis\Controld\Resources\Devices; use Rapkis\Controld\Resources\Profiles; +use Rapkis\Controld\Resources\Services; class ControlD { @@ -29,4 +30,9 @@ public function access(): Access { return app(Access::class, ['client' => $this->request]); } + + public function services(): Services + { + return app(Services::class, ['client' => $this->request]); + } } diff --git a/src/Entities/ServiceCategory.php b/src/Entities/ServiceCategory.php new file mode 100644 index 0000000..c8f27da --- /dev/null +++ b/src/Entities/ServiceCategory.php @@ -0,0 +1,16 @@ +client->get('services/categories')->json('body.categories'); + + $result = new ServiceCategories(); + + foreach ($response as $category) { + $category = $this->category->make($category); + $result->put($category->pk, $category); + } + + return $result; + } + + public function services(string $categoryPk): \Rapkis\Controld\Responses\Services + { + $response = $this->client->get("services/categories/{$categoryPk}")->json('body.services'); + + $result = new \Rapkis\Controld\Responses\Services(); + + foreach ($response as $service) { + $service = $this->service->make($service); + $result[$service->pk] = $service; + } + + return $result; + } +} diff --git a/src/Responses/ServiceCategories.php b/src/Responses/ServiceCategories.php new file mode 100644 index 0000000..03d6841 --- /dev/null +++ b/src/Responses/ServiceCategories.php @@ -0,0 +1,9 @@ +createStub(PendingRequest::class)); @@ -22,3 +23,8 @@ $client = new ControlD($this->createStub(PendingRequest::class)); expect($client->access())->toBeInstanceOf(Access::class); }); + +it('accesses services resource', function () { + $client = new ControlD($this->createStub(PendingRequest::class)); + expect($client->services())->toBeInstanceOf(Services::class); +}); diff --git a/tests/Factories/ServiceCategoryFactoryTest.php b/tests/Factories/ServiceCategoryFactoryTest.php new file mode 100644 index 0000000..786bbac --- /dev/null +++ b/tests/Factories/ServiceCategoryFactoryTest.php @@ -0,0 +1,25 @@ +make($data))->toEqual($expected); +})->with([ + [ + [ + 'PK' => 'audio', + 'name' => 'Audio', + 'description' => 'Description', + 'count' => 15, + ], + new ServiceCategory( + pk: 'audio', + name: 'Audio', + description: 'Description', + count: 15, + ), + ], +]); diff --git a/tests/Mocks/Endpoints/services-categories.json b/tests/Mocks/Endpoints/services-categories.json new file mode 100644 index 0000000..9cf5277 --- /dev/null +++ b/tests/Mocks/Endpoints/services-categories.json @@ -0,0 +1,43 @@ +{ + "body": { + "categories": [ + { + "PK": "audio", + "name": "Audio", + "description": "Audio streaming services and radio stations", + "count": 15 + }, + { + "PK": "gaming", + "name": "Gaming", + "description": "Gaming services and individual online games", + "count": 19 + }, + { + "PK": "shop", + "name": "Shop", + "description": "Shopping and auction websites", + "count": 16 + }, + { + "PK": "social", + "name": "Social", + "description": "Social networks and messaging tools", + "count": 29 + }, + { + "PK": "tools", + "name": "Tools", + "description": "Productivity tools and knowledge bases", + "count": 33 + }, + { + "PK": "video", + "name": "Video", + "description": "Video streaming services and live TV channels", + "count": 293 + } + ] + }, + "success": true +} diff --git a/tests/Mocks/Endpoints/services-services.json b/tests/Mocks/Endpoints/services-services.json new file mode 100644 index 0000000..3b8a5df --- /dev/null +++ b/tests/Mocks/Endpoints/services-services.json @@ -0,0 +1,106 @@ +{ + "body": { + "services": [ + { + "category": "audio", + "name": "Apple Music", + "warning": "This will also disable the App Store and iTunes. ", + "unlock_location": "DFW", + "PK": "applemusic" + }, + { + "warning": "", + "category": "audio", + "name": "Audacy", + "unlock_location": "JFK", + "PK": "audacy" + }, + { + "warning": "", + "category": "audio", + "name": "Audible", + "unlock_location": "JFK", + "PK": "audible" + }, + { + "category": "audio", + "name": "Deezer", + "unlock_location": "DFW", + "PK": "deezer" + }, + { + "category": "audio", + "name": "JOOX", + "unlock_location": "HKG", + "PK": "joox" + }, + { + "warning": "", + "category": "audio", + "name": "Last.fm", + "unlock_location": "JFK", + "PK": "lastfm" + }, + { + "warning": "", + "category": "audio", + "name": "Napster", + "unlock_location": "JFK", + "PK": "napster" + }, + { + "category": "audio", + "name": "Pandora", + "unlock_location": "DFW", + "PK": "pandora" + }, + { + "warning": "", + "category": "audio", + "name": "Shazam", + "unlock_location": "JFK", + "PK": "shazam" + }, + { + "warning": "", + "category": "audio", + "name": "SiriusXM", + "unlock_location": "JFK", + "PK": "siriusxm" + }, + { + "warning": "", + "category": "audio", + "name": "Sonos", + "unlock_location": "JFK", + "PK": "sonos" + }, + { + "category": "audio", + "name": "Soundcloud", + "unlock_location": "DFW", + "PK": "soundcloud" + }, + { + "name": "Spotify", + "unlock_location": "DFW", + "category": "audio", + "PK": "spotify" + }, + { + "category": "audio", + "name": "Tidal", + "unlock_location": "DFW", + "PK": "tidal" + }, + { + "warning": "", + "category": "audio", + "name": "TuneIn", + "unlock_location": "JFK", + "PK": "tunein" + } + ] + }, + "success": true +} diff --git a/tests/Resources/ServicesTest.php b/tests/Resources/ServicesTest.php new file mode 100644 index 0000000..1328fda --- /dev/null +++ b/tests/Resources/ServicesTest.php @@ -0,0 +1,47 @@ + Http::response(mockJsonEndpoint('services-categories')), + ])->asJson(); + + $resource = new Services( + $request, + app(ServiceCategoryFactory::class), + $this->createStub(ServiceFactory::class), + ); + + $result = $resource->categories(); + + expect($result)->toBeInstanceOf(ServiceCategories::class) + ->and($result)->toHaveCount(6); +}); + +it('lists services for category', function () { + $request = Http::fake([ + 'services/categories/category_pk' => Http::response(mockJsonEndpoint('services-services')), + ])->asJson(); + + $resource = new Services( + $request, + $this->createStub(ServiceCategoryFactory::class), + app(ServiceFactory::class), + ); + + $result = $resource->services('category_pk'); + + expect($result)->toBeInstanceOf(\Rapkis\Controld\Responses\Services::class) + ->and($result)->toHaveCount(15); +});