2
2
3
3
namespace Osiset \ShopifyApp \Test \Actions ;
4
4
5
+ use Gnikyt \BasicShopifyAPI \BasicShopifyAPI ;
5
6
use Osiset \ShopifyApp \Actions \VerifyThemeSupport ;
6
- use Osiset \ShopifyApp \Contracts \Queries \Shop as IShopQuery ;
7
7
use Osiset \ShopifyApp \Objects \Enums \ThemeSupportLevel ;
8
- use Osiset \ShopifyApp \Objects \Values \ShopId ;
9
- use Osiset \ShopifyApp \Services \ThemeHelper ;
10
8
use Osiset \ShopifyApp \Test \TestCase ;
9
+ use Osiset \ShopifyApp \Test \Stubs \Api as ApiStub ;
10
+
11
11
12
12
class VerifyThemeSupportTest extends TestCase
13
13
{
14
- public function setUp (): void
15
- {
16
- parent ::setUp ();
17
- }
18
-
19
14
public function testStoreWithUndefinedMainTheme (): void
20
15
{
16
+ $ this ->fakeGraphqlApi (['empty_theme ' ]);
21
17
$ shop = factory ($ this ->model )->create ();
22
18
$ action = $ this ->app ->make (VerifyThemeSupport::class);
23
19
24
20
$ result = call_user_func (
25
21
$ action ,
26
- ShopId:: fromNative ( $ shop ->id )
22
+ $ shop ->getId ( )
27
23
);
28
24
29
25
$ this ->assertNotNull ($ result );
@@ -32,13 +28,13 @@ public function testStoreWithUndefinedMainTheme(): void
32
28
33
29
public function testStoreWithFullExtensionSupport (): void
34
30
{
31
+ $ this ->fakeGraphqlApi (['main_theme ' , 'theme_with_one_asset ' , 'theme_with_one_section ' ]);
35
32
$ 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);
38
34
39
35
$ result = call_user_func (
40
36
$ action ,
41
- ShopId:: fromNative ( $ shop ->id )
37
+ $ shop ->getId ( )
42
38
);
43
39
44
40
$ this ->assertNotNull ($ result );
@@ -48,12 +44,12 @@ public function testStoreWithFullExtensionSupport(): void
48
44
public function testStoreWithPartialExtensionSupport (): void
49
45
{
50
46
$ 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);
53
49
54
50
$ result = call_user_func (
55
51
$ action ,
56
- ShopId:: fromNative ( $ shop ->id )
52
+ $ shop ->getId ( )
57
53
);
58
54
59
55
$ this ->assertNotNull ($ result );
@@ -63,12 +59,12 @@ public function testStoreWithPartialExtensionSupport(): void
63
59
public function testStoreWithoutExtensionSupport (): void
64
60
{
65
61
$ 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);
68
64
69
65
$ result = call_user_func (
70
66
$ action ,
71
- ShopId:: fromNative ( $ shop ->id )
67
+ $ shop ->getId ( )
72
68
);
73
69
74
70
$ this ->assertNotNull ($ result );
@@ -77,30 +73,11 @@ public function testStoreWithoutExtensionSupport(): void
77
73
78
74
/**
79
75
* Create ThemeHelper stub
80
- *
81
- * @param int $level
82
- *
83
- * @return ThemeHelper
84
76
*/
85
- protected function createThemeHelperStub ( int $ level ): ThemeHelper
77
+ protected function fakeGraphqlApi ( array $ responses ): void
86
78
{
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 ();
103
80
104
- return $ themeHelperStub ;
81
+ ApiStub:: stubResponses ( $ responses ) ;
105
82
}
106
83
}
0 commit comments