generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
327 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rapkis\Controld\Entities; | ||
|
||
class ServiceCategory | ||
{ | ||
public function __construct( | ||
public readonly string $pk, | ||
public readonly string $name, | ||
public readonly string $description, | ||
public readonly int $count, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rapkis\Controld\Factories; | ||
|
||
use Rapkis\Controld\Contracts\Factories\Factory; | ||
use Rapkis\Controld\Entities\ServiceCategory; | ||
|
||
class ServiceCategoryFactory implements Factory | ||
{ | ||
public function make(array $data): ServiceCategory | ||
{ | ||
return new ServiceCategory( | ||
pk: $data['PK'], | ||
name: $data['name'], | ||
description: $data['description'], | ||
count: (int) $data['count'], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rapkis\Controld\Resources; | ||
|
||
use Illuminate\Http\Client\PendingRequest; | ||
use Rapkis\Controld\Factories\ServiceCategoryFactory; | ||
use Rapkis\Controld\Factories\ServiceFactory; | ||
use Rapkis\Controld\Responses\ServiceCategories; | ||
|
||
class Services | ||
{ | ||
public function __construct( | ||
private readonly PendingRequest $client, | ||
private readonly ServiceCategoryFactory $category, | ||
private readonly ServiceFactory $service, | ||
) { | ||
} | ||
|
||
public function categories(): ServiceCategories | ||
{ | ||
$response = $this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Rapkis\Controld\Responses; | ||
|
||
use Illuminate\Support\Collection; | ||
|
||
class ServiceCategories extends Collection | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rapkis\Controld\Entities\ServiceCategory; | ||
use Rapkis\Controld\Factories\ServiceCategoryFactory; | ||
|
||
it('builds a service category', function (array $data, ServiceCategory $expected) { | ||
expect((new ServiceCategoryFactory())->make($data))->toEqual($expected); | ||
})->with([ | ||
[ | ||
[ | ||
'PK' => 'audio', | ||
'name' => 'Audio', | ||
'description' => 'Description', | ||
'count' => 15, | ||
], | ||
new ServiceCategory( | ||
pk: 'audio', | ||
name: 'Audio', | ||
description: 'Description', | ||
count: 15, | ||
), | ||
], | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Support\Facades\Http; | ||
use Rapkis\Controld\Factories\ServiceCategoryFactory; | ||
use Rapkis\Controld\Factories\ServiceFactory; | ||
use Rapkis\Controld\Resources\Services; | ||
use Rapkis\Controld\Responses\ServiceCategories; | ||
|
||
beforeEach(function () { | ||
Http::preventStrayRequests(); | ||
}); | ||
|
||
it('lists service categories', function () { | ||
$request = Http::fake([ | ||
'services/categories' => 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); | ||
}); |