mirror of
https://github.com/koel/koel
synced 2025-02-16 13:28:32 +00:00
Finish unit tests for iTunes service
This commit is contained in:
parent
75a79595a9
commit
5b6067426d
2 changed files with 62 additions and 30 deletions
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Services\iTunes;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Mockery as m;
|
||||
use Tests\BrowserKitTestCase;
|
||||
|
||||
class iTunesTest extends BrowserKitTestCase
|
||||
{
|
||||
use WithoutMiddleware;
|
||||
|
||||
public function testGetTrackUrl()
|
||||
{
|
||||
$client = m::mock(Client::class, [
|
||||
'get' => new Response(200, [], file_get_contents(__DIR__.'../../blobs/itunes/track.json')),
|
||||
]);
|
||||
|
||||
$api = new iTunes($client);
|
||||
self::assertEquals(
|
||||
'https://itunes.apple.com/us/album/i-remember-you/id265611220?i=265611396&uo=4&at=1000lsGu',
|
||||
$api->getTrackUrl('Foo Bar')
|
||||
);
|
||||
|
||||
self::assertNotNull(cache(md5('itunes_track_url_Foo Bar')));
|
||||
}
|
||||
}
|
62
tests/Unit/iTunesTest.php
Normal file
62
tests/Unit/iTunesTest.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Services\iTunes;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
|
||||
class iTunesTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function it_can_be_instantiated()
|
||||
{
|
||||
$this->assertInstanceOf(iTunes::class, new iTunes());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function its_usage_status_is_determined_by_configuration()
|
||||
{
|
||||
// Given the configuration to use the iTunes service is set to TRUE
|
||||
config(['koel.itunes.enabled' => true]);
|
||||
$iTunes = new iTunes();
|
||||
|
||||
// When I check if the iTunes service should be used
|
||||
$used = $iTunes->used();
|
||||
|
||||
// Then I see TRUE
|
||||
$this->assertTrue($used);
|
||||
|
||||
// If the configuration is set to FALSE
|
||||
config(['koel.itunes.enabled' => false]);
|
||||
|
||||
// When I check if the iTunes service should be used
|
||||
$used = $iTunes->used();
|
||||
|
||||
// Then I see FALSE
|
||||
$this->assertFalse($used);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_itunes_track_url()
|
||||
{
|
||||
// Given there's a search term
|
||||
$term = 'Foo Bar';
|
||||
|
||||
// When I request the iTunes track URL for the song
|
||||
$client = m::mock(Client::class, [
|
||||
'get' => new Response(200, [], file_get_contents(__DIR__.'../../blobs/itunes/track.json')),
|
||||
]);
|
||||
|
||||
$url = (new iTunes($client))->getTrackUrl($term);
|
||||
|
||||
// Then I retrieve the track URL
|
||||
$this->assertEquals('https://itunes.apple.com/us/album/i-remember-you/id265611220?i=265611396&uo=4&at=1000lsGu',
|
||||
$url);
|
||||
|
||||
// And the track url is cached
|
||||
$this->assertNotNull(cache('b57a14784d80c58a856e0df34ff0c8e2'));
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue