Skip to content

Commit

Permalink
Updated to account for new fixes to underlying API library
Browse files Browse the repository at this point in the history
  • Loading branch information
gnikyt committed Jun 18, 2020
1 parent 498d0ee commit f949093
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 61 deletions.
5 changes: 3 additions & 2 deletions src/ShopifyApp/Actions/CreateScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Osiset\ShopifyApp\Actions;

use Osiset\BasicShopifyAPI\ResponseAccess;
use Osiset\ShopifyApp\Objects\Values\ShopId;
use Osiset\ShopifyApp\Traits\ConfigAccessible;
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
Expand Down Expand Up @@ -47,11 +48,11 @@ public function __invoke(ShopId $shopId, array $configScripts): array
* Checks if a scripttag exists already in the shop.
*
* @param array $script The scripttag config.
* @param array $scripts The current scripttags to search.
* @param ResponseAccess $scripts The current scripttags to search.
*
* @return bool
*/
$exists = function (array $script, array $scripts): bool {
$exists = function (array $script, ResponseAccess $scripts): bool {
foreach ($scripts as $shopScript) {
if ($shopScript['src'] === $script['src']) {
// Found the scripttag in our list
Expand Down
9 changes: 5 additions & 4 deletions src/ShopifyApp/Actions/CreateWebhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Osiset\ShopifyApp\Actions;

use Osiset\ShopifyApp\Contracts\ApiHelper as IApiHelper;
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
use Osiset\BasicShopifyAPI\ResponseAccess;
use Osiset\ShopifyApp\Objects\Values\ShopId;
use Osiset\ShopifyApp\Traits\ConfigAccessible;
use Osiset\ShopifyApp\Contracts\ApiHelper as IApiHelper;
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;

/**
* Create webhooks for this app on the shop.
Expand Down Expand Up @@ -48,11 +49,11 @@ public function __invoke(ShopId $shopId, array $configWebhooks): array
* Checks if a webhooks exists already in the shop.
*
* @param array $webhook The webhook config.
* @param array $webhooks The current webhooks to search.
* @param ResponseAccess $webhooks The current webhooks to search.
*
* @return bool
*/
$exists = function (array $webhook, array $webhooks): bool {
$exists = function (array $webhook, ResponseAccess $webhooks): bool {
foreach ($webhooks as $shopWebhook) {
if ($shopWebhook['address'] === $webhook['address']) {
// Found the webhook in our list
Expand Down
22 changes: 11 additions & 11 deletions src/ShopifyApp/Contracts/ApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public function getAccessData(string $code): ResponseAccess;
*
* @throws RequestException
*
* @return array
* @return ResponseAccess
*/
public function getScriptTags(array $params = []): array;
public function getScriptTags(array $params = []): ResponseAccess;

/**
* Create a script tag for the shop.
Expand All @@ -100,9 +100,9 @@ public function createScriptTag(array $payload): ResponseAccess;
*
* @throws RequestException
*
* @return array
* @return ResponseAccess
*/
public function getCharge(ChargeType $chargeType, ChargeReference $chargeRef): array;
public function getCharge(ChargeType $chargeType, ChargeReference $chargeRef): ResponseAccess;

/**
* Activate a charge.
Expand All @@ -112,19 +112,19 @@ public function getCharge(ChargeType $chargeType, ChargeReference $chargeRef): a
*
* @throws RequestExcpetion
*
* @return array
* @return ResponseAccess
*/
public function activateCharge(ChargeType $chargeType, ChargeReference $chargeRef): array;
public function activateCharge(ChargeType $chargeType, ChargeReference $chargeRef): ResponseAccess;

/**
* Create a charge.
*
* @param ChargeType $chargeType The type of charge (plural).
* @param PlanDetails $payload The data for the charge creation.
*
* @return array
* @return ResponseAccess
*/
public function createCharge(ChargeType $chargeType, PlanDetails $payload): array;
public function createCharge(ChargeType $chargeType, PlanDetails $payload): ResponseAccess;

/**
* Get webhooks for the shop.
Expand All @@ -133,9 +133,9 @@ public function createCharge(ChargeType $chargeType, PlanDetails $payload): arra
*
* @throws RequestException
*
* @return array
* @return ResponseAccess
*/
public function getWebhooks(array $params = []): array;
public function getWebhooks(array $params = []): ResponseAccess;

/**
* Create a webhook.
Expand All @@ -144,7 +144,7 @@ public function getWebhooks(array $params = []): array;
*
* @return ResponseAccess
*/
public function createWebhook(array $payload): array;
public function createWebhook(array $payload): ResponseAccess;

/**
* Delete a webhook.
Expand Down
12 changes: 6 additions & 6 deletions src/ShopifyApp/Services/ApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function getAccessData(string $code): ResponseAccess
/**
* {@inheritdoc}
*/
public function getScriptTags(array $params = []): array
public function getScriptTags(array $params = []): ResponseAccess
{
// Setup the params
$reqParams = array_merge(
Expand Down Expand Up @@ -189,7 +189,7 @@ public function createScriptTag(array $payload): ResponseAccess
/**
* {@inheritdoc}
*/
public function getCharge(ChargeType $chargeType, ChargeReference $chargeRef): array
public function getCharge(ChargeType $chargeType, ChargeReference $chargeRef): ResponseAccess
{
// API path
$typeString = $this->chargeApiPath($chargeType);
Expand All @@ -206,7 +206,7 @@ public function getCharge(ChargeType $chargeType, ChargeReference $chargeRef): a
/**
* {@inheritdoc}
*/
public function activateCharge(ChargeType $chargeType, ChargeReference $chargeRef): array
public function activateCharge(ChargeType $chargeType, ChargeReference $chargeRef): ResponseAccess
{
// API path
$typeString = $this->chargeApiPath($chargeType);
Expand All @@ -223,7 +223,7 @@ public function activateCharge(ChargeType $chargeType, ChargeReference $chargeRe
/**
* {@inheritdoc}
*/
public function createCharge(ChargeType $chargeType, PlanDetailsTransfer $payload): array
public function createCharge(ChargeType $chargeType, PlanDetailsTransfer $payload): ResponseAccess
{
// API path
$typeString = $this->chargeApiPath($chargeType);
Expand All @@ -241,7 +241,7 @@ public function createCharge(ChargeType $chargeType, PlanDetailsTransfer $payloa
/**
* {@inheritdoc}
*/
public function getWebhooks(array $params = []): array
public function getWebhooks(array $params = []): ResponseAccess
{
// Setup the params
$reqParams = array_merge(
Expand All @@ -265,7 +265,7 @@ public function getWebhooks(array $params = []): array
/**
* {@inheritdoc}
*/
public function createWebhook(array $payload): array
public function createWebhook(array $payload): ResponseAccess
{
// Fire the request
$response = $this->doRequest(
Expand Down
4 changes: 2 additions & 2 deletions src/ShopifyApp/Services/ShopSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ public function getToken(bool $strict = false): AccessTokenValue
/**
* Gets the associated user (if any).
*
* @return array|null
* @return ResponseAccess|null
*/
public function getUser(): ?array
public function getUser(): ?ResponseAccess
{
return Session::get(self::USER);
}
Expand Down
66 changes: 33 additions & 33 deletions tests/Services/ApiHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ public function testGetScriptTags(): void
$this->setApiStub();
ApiStub::stubResponses(['get_script_tags']);

$this->assertIsArray(
$shop->apiHelper()->getScriptTags()
);
$data = $shop->apiHelper()->getScriptTags();
$this->assertInstanceOf(ResponseAccess::class, $data);
$this->assertEquals('onload', $data[0]['event']);
$this->assertEquals(2, count($data));
}

public function testCreateScriptTags(): void
Expand All @@ -94,9 +95,8 @@ public function testCreateScriptTags(): void
$this->setApiStub();
ApiStub::stubResponses(['empty']);

$this->assertIsObject(
$shop->apiHelper()->createScriptTag([])
);
$data = $shop->apiHelper()->createScriptTag([]);
$this->assertInstanceOf(ResponseAccess::class, $data);
}

public function testGetCharge(): void
Expand All @@ -108,9 +108,10 @@ public function testGetCharge(): void
$this->setApiStub();
ApiStub::stubResponses(['get_application_charge']);

$this->assertIsArray(
$shop->apiHelper()->getCharge(ChargeType::CHARGE(), new ChargeReference(1234))
);
$data = $shop->apiHelper()->getCharge(ChargeType::CHARGE(), new ChargeReference(1234));
$this->assertInstanceOf(ResponseAccess::class, $data);
$this->assertEquals('iPod Cleaning', $data->name);
$this->assertEquals('accepted', $data['status']);
}

public function testActivateCharge(): void
Expand All @@ -122,9 +123,9 @@ public function testActivateCharge(): void
$this->setApiStub();
ApiStub::stubResponses(['post_recurring_application_charges_activate']);

$this->assertIsArray(
$shop->apiHelper()->activateCharge(ChargeType::RECURRING(), new ChargeReference(1234))
);
$data = $shop->apiHelper()->activateCharge(ChargeType::RECURRING(), new ChargeReference(1234));
$this->assertInstanceOf(ResponseAccess::class, $data);
$this->assertEquals('Super Mega Plan', $data['name']);
}

public function testCreateCharge(): void
Expand All @@ -136,20 +137,20 @@ public function testCreateCharge(): void
$this->setApiStub();
ApiStub::stubResponses(['post_recurring_application_charges']);

$this->assertIsArray(
$shop->apiHelper()->createCharge(
ChargeType::RECURRING(),
new PlanDetailsTransfer(
'Test',
12.00,
true,
7,
null,
null,
null
)
$data = $shop->apiHelper()->createCharge(
ChargeType::RECURRING(),
new PlanDetailsTransfer(
'Test',
12.00,
true,
7,
null,
null,
null
)
);
$this->assertInstanceOf(ResponseAccess::class, $data);
$this->assertEquals('Basic Plan', $data['name']);
}

public function testGetWebhooks(): void
Expand All @@ -161,9 +162,9 @@ public function testGetWebhooks(): void
$this->setApiStub();
ApiStub::stubResponses(['get_webhooks']);

$this->assertIsArray(
$shop->apiHelper()->getWebhooks()
);
$data = $shop->apiHelper()->getWebhooks();
$this->assertInstanceOf(ResponseAccess::class, $data);
$this->assertTrue(count($data) > 0);
}

public function testCreateWebhook(): void
Expand All @@ -175,9 +176,9 @@ public function testCreateWebhook(): void
$this->setApiStub();
ApiStub::stubResponses(['post_webhook']);

$this->assertIsArray(
$shop->apiHelper()->createWebhook([])
);
$data = $shop->apiHelper()->createWebhook([]);
$this->assertInstanceOf(ResponseAccess::class, $data);
$this->assertEquals('app/uninstalled', $data['topic']);
}

public function testDeleteWebhook(): void
Expand Down Expand Up @@ -209,9 +210,8 @@ public function testCreateUsageCharge(): void
$tranfer->price = 12.00;
$tranfer->description = 'Hello!';

$this->assertIsArray(
$shop->apiHelper()->createUsageCharge($tranfer)
);
$data = $shop->apiHelper()->createUsageCharge($tranfer);
$this->assertInstanceOf(ResponseAccess::class, $data);
}

public function testErrors(): void
Expand Down
7 changes: 4 additions & 3 deletions tests/Services/ChargeHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Osiset\ShopifyApp\Test\Services;

use Illuminate\Support\Carbon;
use Osiset\BasicShopifyAPI\ResponseAccess;
use Osiset\ShopifyApp\Objects\Enums\ChargeStatus;
use Osiset\ShopifyApp\Objects\Transfers\PlanDetails;
use Osiset\ShopifyApp\Test\TestCase;
Expand Down Expand Up @@ -45,9 +46,9 @@ public function testRetrieveCharge(): void
$this->setApiStub();
ApiStub::stubResponses(['get_application_charge']);

$this->assertIsArray(
$this->chargeHelper->retrieve($seed->shop)
);
$data = $this->chargeHelper->retrieve($seed->shop);
$this->assertInstanceOf(ResponseAccess::class, $data);
$this->assertEquals('accepted', $data->status);
}

public function testTrial(): void
Expand Down

0 comments on commit f949093

Please sign in to comment.