Skip to content

Commit bc93798

Browse files
committed
update tests
1 parent f5afea8 commit bc93798

17 files changed

+138
-578
lines changed

tests/Actions/VerifyThemeSupportTest.php

+17-40
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,24 @@
22

33
namespace Osiset\ShopifyApp\Test\Actions;
44

5+
use Gnikyt\BasicShopifyAPI\BasicShopifyAPI;
56
use Osiset\ShopifyApp\Actions\VerifyThemeSupport;
6-
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
77
use Osiset\ShopifyApp\Objects\Enums\ThemeSupportLevel;
8-
use Osiset\ShopifyApp\Objects\Values\ShopId;
9-
use Osiset\ShopifyApp\Services\ThemeHelper;
108
use Osiset\ShopifyApp\Test\TestCase;
9+
use Osiset\ShopifyApp\Test\Stubs\Api as ApiStub;
10+
1111

1212
class VerifyThemeSupportTest extends TestCase
1313
{
14-
public function setUp(): void
15-
{
16-
parent::setUp();
17-
}
18-
1914
public function testStoreWithUndefinedMainTheme(): void
2015
{
16+
$this->fakeGraphqlApi(['empty_theme']);
2117
$shop = factory($this->model)->create();
2218
$action = $this->app->make(VerifyThemeSupport::class);
2319

2420
$result = call_user_func(
2521
$action,
26-
ShopId::fromNative($shop->id)
22+
$shop->getId()
2723
);
2824

2925
$this->assertNotNull($result);
@@ -32,13 +28,13 @@ public function testStoreWithUndefinedMainTheme(): void
3228

3329
public function testStoreWithFullExtensionSupport(): void
3430
{
31+
$this->fakeGraphqlApi(['main_theme', 'theme_with_one_asset', 'theme_with_one_section']);
3532
$shop = factory($this->model)->create();
36-
$themeHelperStub = $this->createThemeHelperStub(ThemeSupportLevel::FULL);
37-
$action = new VerifyThemeSupport($this->app->make(IShopQuery::class), $themeHelperStub);
33+
$action = $this->app->make(VerifyThemeSupport::class);
3834

3935
$result = call_user_func(
4036
$action,
41-
ShopId::fromNative($shop->id)
37+
$shop->getId()
4238
);
4339

4440
$this->assertNotNull($result);
@@ -48,12 +44,12 @@ public function testStoreWithFullExtensionSupport(): void
4844
public function testStoreWithPartialExtensionSupport(): void
4945
{
5046
$shop = factory($this->model)->create();
51-
$themeHelperStub = $this->createThemeHelperStub(ThemeSupportLevel::PARTIAL);
52-
$action = new VerifyThemeSupport($this->app->make(IShopQuery::class), $themeHelperStub);
47+
$this->fakeGraphqlApi(['main_theme', 'theme_with_three_assets', 'theme_with_one_section']);
48+
$action = $this->app->make(VerifyThemeSupport::class);
5349

5450
$result = call_user_func(
5551
$action,
56-
ShopId::fromNative($shop->id)
52+
$shop->getId()
5753
);
5854

5955
$this->assertNotNull($result);
@@ -63,12 +59,12 @@ public function testStoreWithPartialExtensionSupport(): void
6359
public function testStoreWithoutExtensionSupport(): void
6460
{
6561
$shop = factory($this->model)->create();
66-
$themeHelperStub = $this->createThemeHelperStub(ThemeSupportLevel::UNSUPPORTED);
67-
$action = new VerifyThemeSupport($this->app->make(IShopQuery::class), $themeHelperStub);
62+
$this->fakeGraphqlApi(['main_theme', 'theme_with_empty_assets', 'theme_with_empty_sections']);
63+
$action = $this->app->make(VerifyThemeSupport::class);
6864

6965
$result = call_user_func(
7066
$action,
71-
ShopId::fromNative($shop->id)
67+
$shop->getId()
7268
);
7369

7470
$this->assertNotNull($result);
@@ -77,30 +73,11 @@ public function testStoreWithoutExtensionSupport(): void
7773

7874
/**
7975
* Create ThemeHelper stub
80-
*
81-
* @param int $level
82-
*
83-
* @return ThemeHelper
8476
*/
85-
protected function createThemeHelperStub(int $level): ThemeHelper
77+
protected function fakeGraphqlApi(array $responses): void
8678
{
87-
$themeHelperStub = $this->createStub(ThemeHelper::class);
88-
89-
$defaultThemeResponse = [];
90-
91-
if ($level === ThemeSupportLevel::FULL) {
92-
$defaultThemeResponse = [0, 1, 2, 3];
93-
}
94-
95-
$themeHelperStub->method('themeIsReady')->willReturn(true);
96-
$themeHelperStub->method('templateJSONFiles')->willReturn($defaultThemeResponse);
97-
$themeHelperStub->method('mainSections')->willReturn($defaultThemeResponse);
98-
$themeHelperStub->method('sectionsWithAppBlock')->willReturn(
99-
$level === ThemeSupportLevel::PARTIAL
100-
? array_merge($defaultThemeResponse, [random_int(1, 99)])
101-
: $defaultThemeResponse
102-
);
79+
$this->setApiStub();
10380

104-
return $themeHelperStub;
81+
ApiStub::stubResponses($responses);
10582
}
10683
}

tests/Http/Middleware/VerifyShopifyTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public function testTokenProcessingAndNotInstalledShop(): void
162162
[
163163
'token' => $this->buildToken(),
164164
'shop' => 'non-existent.myshopify.com',
165+
'host' => 'loremipsum'
165166
],
166167
// Request Params
167168
null,

tests/Objects/Values/MainThemeTest.php

-58
This file was deleted.

tests/Services/ThemeHelperTest.php

-130
This file was deleted.

tests/fixtures/empty_theme.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"data": {
3+
"themes": {
4+
"nodes": []
5+
}
6+
}
7+
}

tests/fixtures/empty_with_error.json

-3
This file was deleted.

tests/fixtures/get_theme_asset_product_section.json

-13
This file was deleted.

tests/fixtures/get_theme_asset_template_json.json

-13
This file was deleted.

0 commit comments

Comments
 (0)