Skip to content

Commit

Permalink
Adding Missing Specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandin committed Sep 5, 2022
1 parent 0c36e6d commit 4ff5852
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 2 deletions.
12 changes: 12 additions & 0 deletions spec/TwitchApi/Resources/BitsApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,16 @@ function it_should_extension_transactions_with_after(RequestGenerator $requestGe
$requestGenerator->generate('GET', 'extensions/transactions', 'TEST_TOKEN', [['key' => 'extension_id', 'value' => '1'], ['key' => 'after', 'value' => '100']], [])->willReturn($request);
$this->getExtensionTransactions('TEST_TOKEN', '1', [], null, 100)->shouldBe($response);
}

function it_should_get_bits_leaderboard(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'bits/leaderboard', 'TEST_TOKEN', [], [])->willReturn($request);
$this->getBitsLeaderboard('TEST_TOKEN')->shouldBe($response);
}

function it_should_get_bits_leaderboard_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'bits/leaderboard', 'TEST_TOKEN', [['key' => 'count', 'value' => '100'], ['key' => 'period', 'value' => 'all'], ['key' => 'started_at', 'value' => '2019-10-12T07:20:50.52Z'], ['key' => 'user_id', 'value' => '123']], [])->willReturn($request);
$this->getBitsLeaderboard('TEST_TOKEN', 100, 'all', '2019-10-12T07:20:50.52Z', '123')->shouldBe($response);
}
}
78 changes: 78 additions & 0 deletions spec/TwitchApi/Resources/ClipsApiSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace spec\TwitchApi\Resources;

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use TwitchApi\RequestGenerator;
use TwitchApi\HelixGuzzleClient;
use PhpSpec\ObjectBehavior;

class ClipsApiSpec extends ObjectBehavior
{
function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response)
{
$this->beConstructedWith($guzzleClient, $requestGenerator);
$guzzleClient->send($request)->willReturn($response);
}

function it_should_get_clips_by_broadcaster_id(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
$this->getClips('TEST_TOKEN', '123')->shouldBe($response);
}

function it_should_get_clips_by_broadcaster_id_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
$this->getClipsByBroadcasterId('TEST_TOKEN', '123')->shouldBe($response);
}

function it_should_get_clips_by_game_id(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123']], [])->willReturn($request);
$this->getClips('TEST_TOKEN', null, '123')->shouldBe($response);
}

function it_should_get_clips_by_game_id_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123']], [])->willReturn($request);
$this->getClipsByGameId('TEST_TOKEN', '123')->shouldBe($response);
}

function it_should_get_one_clip_by_id(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request);
$this->getClips('TEST_TOKEN', null, null, '123')->shouldBe($response);
}

function it_should_get_one_clip_by_id_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request);
$this->getClipsByIds('TEST_TOKEN', '123')->shouldBe($response);
}

function it_should_get_multiple_clips_by_id(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'id', 'value' => '123,456']], [])->willReturn($request);
$this->getClips('TEST_TOKEN', null, null, '123,456')->shouldBe($response);
}

function it_should_get_multiple_clips_by_id_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'id', 'value' => '123,456']], [])->willReturn($request);
$this->getClipsByIds('TEST_TOKEN', '123,456')->shouldBe($response);
}

function it_should_get_clips_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'first', 'value' => '10'], ['key' => 'before', 'value' => 'abc'], ['key' => 'after', 'value' => 'def'], ['key' => 'started_at', 'value' => '2018-10-12T07:20:50.52Z'], ['key' => 'ended_at', 'value' => '2019-10-12T07:20:50.52Z']], [])->willReturn($request);
$this->getClips('TEST_TOKEN', '123', null, null, 10, 'abc', 'def', '2018-10-12T07:20:50.52Z', '2019-10-12T07:20:50.52Z')->shouldBe($response);
}

function it_should_create_a_clip(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('POST', 'clips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'has_delay', 'value' => 'true']], [])->willReturn($request);
$this->createClip('TEST_TOKEN', '123', true)->shouldBe($response);
}
}
18 changes: 18 additions & 0 deletions spec/TwitchApi/Resources/EntitlementsApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,22 @@ function it_should_redeem_codes(RequestGenerator $requestGenerator, Request $req
$requestGenerator->generate('POST', 'entitlements/code', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'code', 'value' => 'abc'], ['key' => 'code', 'value' => 'def']], [])->willReturn($request);
$this->redeemCode('TEST_TOKEN', '123', ['abc', 'def'])->shouldBe($response);
}

function it_should_update_drop_entitlements(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('PATCH', 'entitlements/drops', 'TEST_TOKEN', [], [])->willReturn($request);
$this->updateDropsEntitlements('TEST_TOKEN')->shouldBe($response);
}

function it_should_update_one_drop_entitlements(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('PATCH', 'entitlements/drops', 'TEST_TOKEN', [], [['key' => 'entitlement_ids', 'value' => ['123']], ['key' => 'fulfillment_status', 'value' => 'FULFILLED']])->willReturn($request);
$this->updateDropsEntitlements('TEST_TOKEN', ['123'], 'FULFILLED')->shouldBe($response);
}

function it_should_update_multiple_drop_entitlements(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('PATCH', 'entitlements/drops', 'TEST_TOKEN', [], [['key' => 'entitlement_ids', 'value' => ['123', '456']], ['key' => 'fulfillment_status', 'value' => 'FULFILLED']])->willReturn($request);
$this->updateDropsEntitlements('TEST_TOKEN', ['123', '456'], 'FULFILLED')->shouldBe($response);
}
}
12 changes: 12 additions & 0 deletions spec/TwitchApi/Resources/EventSubApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,16 @@ function it_should_subscribe_to_channel_goal_end(RequestGenerator $requestGenera
$this->createEventSubSubscription('channel.goal.end', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
$this->subscribeToChannelGoalEnd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
}

function it_should_subscribe_to_drop_entitelement_grant(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$this->createEventSubSubscription('drop.entitlement.grant', '1', ['organization_id' => '12345'], $requestGenerator)->willReturn($request);
$this->subscribeToDropEntitlementGrant($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
}

function it_should_subscribe_to_drop_entitelement_grant_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$this->createEventSubSubscription('drop.entitlement.grant', '1', ['organization_id' => '123', 'category_id' => '456', 'campaign_id' => '789'], $requestGenerator)->willReturn($request);
$this->subscribeToDropEntitlementGrant($this->bearer, $this->secret, $this->callback, '123', '456', '789')->shouldBe($response);
}
}
24 changes: 24 additions & 0 deletions spec/TwitchApi/Resources/ModerationApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,28 @@ function it_should_remove_vip_for_a_channel(RequestGenerator $requestGenerator,
$requestGenerator->generate('DELETE', 'channels/vips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '456']], [])->willReturn($request);
$this->removeChannelVip('TEST_TOKEN', '123', '456')->shouldBe($response);
}

function it_should_get_banned_users(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'moderation/banned', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
$this->getBannedUsers('TEST_TOKEN', '123')->shouldBe($response);
}

function it_should_get_banned_users_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'moderation/banned', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => 'abc'], ['key' => 'user_id', 'value' => 'def'], ['key' => 'before', 'value' => 'abc'], ['key' => 'after', 'value' => 'def'], ['key' => 'first', 'value' => '100']], [])->willReturn($request);
$this->getBannedUsers('TEST_TOKEN', '123', ['abc', 'def'], 'abc', 'def', '100')->shouldBe($response);
}

function it_should_get_moderators(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'moderation/moderators', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
$this->getModerators('TEST_TOKEN', '123')->shouldBe($response);
}

function it_should_get_moderators_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'moderation/moderators', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => 'abc'], ['key' => 'user_id', 'value' => 'def'], ['key' => 'after', 'value' => 'abc'], ['key' => 'first', 'value' => '100']], [])->willReturn($request);
$this->getModerators('TEST_TOKEN', '123', ['abc', 'def'], 'abc', '100')->shouldBe($response);
}
}
42 changes: 42 additions & 0 deletions spec/TwitchApi/Resources/SearchApiSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace spec\TwitchApi\Resources;

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use TwitchApi\RequestGenerator;
use TwitchApi\HelixGuzzleClient;
use PhpSpec\ObjectBehavior;

class SearchApiSpec extends ObjectBehavior
{
function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response)
{
$this->beConstructedWith($guzzleClient, $requestGenerator);
$guzzleClient->send($request)->willReturn($response);
}

function it_should_search_categories(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'search/categories', 'TEST_TOKEN', [['key' => 'query', 'value' => 'test']], [])->willReturn($request);
$this->searchCategories('TEST_TOKEN', 'test')->shouldBe($response);
}

function it_should_search_categories_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'search/categories', 'TEST_TOKEN', [['key' => 'query', 'value' => 'test'], ['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request);
$this->searchCategories('TEST_TOKEN', 'test', 100, 'abc')->shouldBe($response);
}

function it_should_search_channels(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'search/channels', 'TEST_TOKEN', [['key' => 'query', 'value' => 'test']], [])->willReturn($request);
$this->searchChannels('TEST_TOKEN', 'test')->shouldBe($response);
}

function it_should_search_channels_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'search/channels', 'TEST_TOKEN', [['key' => 'query', 'value' => 'test'], ['key' => 'live_only', 'value' => true], ['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request);
$this->searchChannels('TEST_TOKEN', 'test', true, 100, 'abc')->shouldBe($response);
}
}
22 changes: 20 additions & 2 deletions spec/TwitchApi/TwitchApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use TwitchApi\Resources\BitsApi;
use TwitchApi\Resources\ChannelPointsApi;
use TwitchApi\Resources\ChannelsApi;
use TwitchApi\Resources\ChatApi;
use TwitchApi\Resources\ClipsApi;
use TwitchApi\Resources\EntitlementsApi;
use TwitchApi\Resources\EventSubApi;
use TwitchApi\Resources\GamesApi;
Expand All @@ -19,6 +21,7 @@
use TwitchApi\Resources\PredictionsApi;
use TwitchApi\Resources\RaidsApi;
use TwitchApi\Resources\ScheduleApi;
use TwitchApi\Resources\SearchApi;
use TwitchApi\Resources\StreamsApi;
use TwitchApi\Resources\SubscriptionsApi;
use TwitchApi\Resources\TagsApi;
Expand Down Expand Up @@ -67,6 +70,16 @@ function it_should_provide_channels_api()
$this->getChannelsApi()->shouldBeAnInstanceOf(ChannelsApi::class);
}

function it_should_provide_chat_api()
{
$this->getChatApi()->shouldBeAnInstanceOf(ChatApi::class);
}

function it_should_provide_clips_api()
{
$this->getClipsApi()->shouldBeAnInstanceOf(ClipsApi::class);
}

function it_should_provide_entitlements_api()
{
$this->getEntitlementsApi()->shouldBeAnInstanceOf(EntitlementsApi::class);
Expand Down Expand Up @@ -111,16 +124,21 @@ function it_should_provide_schedule_api()
$this->getScheduleApi()->shouldBeAnInstanceOf(ScheduleApi::class);
}

function it_should_provide_subscriptions_api()
function it_should_provide_search_api()
{
$this->getSubscriptionsApi()->shouldBeAnInstanceOf(SubscriptionsApi::class);
$this->getSearchApi()->shouldBeAnInstanceOf(SearchApi::class);
}

function it_should_provide_streams_api()
{
$this->getStreamsApi()->shouldBeAnInstanceOf(StreamsApi::class);
}

function it_should_provide_subscriptions_api()
{
$this->getSubscriptionsApi()->shouldBeAnInstanceOf(SubscriptionsApi::class);
}

function it_should_provide_tags_api()
{
$this->getTagsApi()->shouldBeAnInstanceOf(TagsApi::class);
Expand Down

0 comments on commit 4ff5852

Please sign in to comment.