3
3
namespace Osiset \ShopifyApp \Test \Http \Middleware ;
4
4
5
5
use Illuminate \Auth \AuthManager ;
6
+ use Illuminate \Support \Facades \Request ;
6
7
use Osiset \ShopifyApp \Http \Middleware \Billable as BillableMiddleware ;
7
8
use Osiset \ShopifyApp \Storage \Models \Charge ;
8
9
use Osiset \ShopifyApp \Storage \Models \Plan ;
@@ -25,13 +26,15 @@ public function setUp(): void
25
26
26
27
public function testEnabledBillingWithUnpaidShop (): void
27
28
{
29
+ $ currentRequest = Request::instance ();
30
+ $ newRequest = $ currentRequest ->duplicate (['shop ' => 'mystore123.myshopify.com ' ]);
31
+
28
32
// Enable billing and set a shop
29
- $ shop = factory ($ this ->model )->create ();
30
- $ this ->auth ->login ($ shop );
31
33
$ this ->app ['config ' ]->set ('shopify-app.billing_enabled ' , true );
34
+ factory ($ this ->model )->create (['name ' => 'mystore123.myshopify.com ' ]);
32
35
33
36
// Run the middleware
34
- $ result = $ this ->runMiddleware (BillableMiddleware::class);
37
+ $ result = $ this ->runMiddleware (BillableMiddleware::class, $ newRequest );
35
38
36
39
// Assert it was not called and redirect happened
37
40
$ this ->assertFalse ($ result [0 ]);
@@ -40,49 +43,65 @@ public function testEnabledBillingWithUnpaidShop(): void
40
43
41
44
public function testEnabledBillingWithPaidShop (): void
42
45
{
46
+ $ currentRequest = Request::instance ();
47
+ $ newRequest = $ currentRequest ->duplicate (['shop ' => 'mystore123.myshopify.com ' ]);
48
+
43
49
// Enable billing and set a shop
50
+ $ this ->app ['config ' ]->set ('shopify-app.billing_enabled ' , true );
51
+
44
52
$ plan = factory (Util::getShopifyConfig ('models.plan ' , Plan::class))->states ('type_recurring ' )->create ();
45
53
$ shop = factory ($ this ->model )->create ([
54
+ 'name ' => 'mystore123.myshopify.com ' ,
46
55
'plan_id ' => $ plan ->getId ()->toNative (),
47
56
]);
57
+
48
58
factory (Util::getShopifyConfig ('models.charge ' , Charge::class))->states ('type_recurring ' )->create ([
49
59
'plan_id ' => $ plan ->getId ()->toNative (),
50
60
'user_id ' => $ shop ->getId ()->toNative (),
51
61
]);
52
62
53
- $ this ->auth ->login ($ shop );
54
- $ this ->app ['config ' ]->set ('shopify-app.billing_enabled ' , true );
55
-
56
63
// Run the middleware
57
- $ result = $ this ->runMiddleware (BillableMiddleware::class);
64
+ $ result = $ this ->runMiddleware (BillableMiddleware::class, $ newRequest );
58
65
59
66
// Assert it was called
60
67
$ this ->assertTrue ($ result [0 ]);
61
68
}
62
69
63
70
public function testEnabledBillingWithGrandfatheredShop (): void
64
71
{
72
+ $ currentRequest = Request::instance ();
73
+ $ newRequest = $ currentRequest ->duplicate (['shop ' => 'mystore123.myshopify.com ' ]);
74
+
65
75
// Enable billing and set a shop
66
- $ shop = factory ($ this ->model )->states ('grandfathered ' )->create ();
67
- $ this ->auth ->login ($ shop );
68
76
$ this ->app ['config ' ]->set ('shopify-app.billing_enabled ' , true );
77
+ factory ($ this ->model )
78
+ ->states ('grandfathered ' )
79
+ ->create ([
80
+ 'name ' => 'mystore123.myshopify.com ' ,
81
+ ]);
69
82
70
83
// Run the middleware
71
- $ result = $ this ->runMiddleware (BillableMiddleware::class);
84
+ $ result = $ this ->runMiddleware (BillableMiddleware::class, $ newRequest );
72
85
73
86
// Assert it was called
74
87
$ this ->assertTrue ($ result [0 ]);
75
88
}
76
89
77
90
public function testEnabledBillingWithFreemiumShop (): void
78
91
{
92
+ $ currentRequest = Request::instance ();
93
+ $ newRequest = $ currentRequest ->duplicate (['shop ' => 'mystore123.myshopify.com ' ]);
94
+
79
95
// Enable billing and set a shop
80
- $ shop = factory ($ this ->model )->states ('freemium ' )->create ();
81
- $ this ->auth ->login ($ shop );
82
96
$ this ->app ['config ' ]->set ('shopify-app.billing_enabled ' , true );
97
+ factory ($ this ->model )
98
+ ->states ('freemium ' )
99
+ ->create ([
100
+ 'name ' => 'mystore123.myshopify.com ' ,
101
+ ]);
83
102
84
103
// Run the middleware
85
- $ result = $ this ->runMiddleware (BillableMiddleware::class);
104
+ $ result = $ this ->runMiddleware (BillableMiddleware::class, $ newRequest );
86
105
87
106
// Assert it was called
88
107
$ this ->assertTrue ($ result [0 ]);
@@ -91,9 +110,8 @@ public function testEnabledBillingWithFreemiumShop(): void
91
110
public function testDisabledBillingShouldPassOn (): void
92
111
{
93
112
// Ensure billing is disabled and set a shop
94
- $ shop = factory ($ this ->model )->create ();
95
- $ this ->auth ->login ($ shop );
96
113
$ this ->app ['config ' ]->set ('shopify-app.billing_enabled ' , false );
114
+ factory ($ this ->model )->create ();
97
115
98
116
// Run the middleware
99
117
$ result = $ this ->runMiddleware (BillableMiddleware::class);
0 commit comments