This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 376
/
AuthorizeShopTest.php
108 lines (86 loc) · 2.87 KB
/
AuthorizeShopTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Osiset\ShopifyApp\Test\Actions;
use Osiset\ShopifyApp\Actions\AuthorizeShop;
use Osiset\ShopifyApp\Objects\Values\ShopDomain;
use Osiset\ShopifyApp\Test\Stubs\Api as ApiStub;
use Osiset\ShopifyApp\Test\TestCase;
class AuthorizeShopTest extends TestCase
{
/**
* @var \Osiset\ShopifyApp\Actions\AuthorizeShop
*/
protected $action;
public function setUp(): void
{
parent::setUp();
$this->action = $this->app->make(AuthorizeShop::class);
}
public function testNoShopShouldBeMade(): void
{
$result = call_user_func(
$this->action,
ShopDomain::fromNative('non-existant.myshopify.com'),
null
);
$this->assertStringContainsString(
'/admin/oauth/authorize?client_id='.env('SHOPIFY_API_KEY').'&scope=read_products%2Cwrite_products&redirect_uri=https%3A%2F%2Flocalhost%2Fauthenticate',
$result->url
);
$this->assertFalse($result->completed);
}
public function testWithoutCode(): void
{
// Create the shop
$shop = factory($this->model)->create();
$result = call_user_func(
$this->action,
$shop->getDomain(),
null
);
$this->assertStringContainsString(
'/admin/oauth/authorize?client_id='.env('SHOPIFY_API_KEY').'&scope=read_products%2Cwrite_products&redirect_uri=https%3A%2F%2Flocalhost%2Fauthenticate',
$result->url
);
$this->assertFalse($result->completed);
}
public function testWithCode(): void
{
// Create the shop
$shop = factory($this->model)->create();
// Get the current access token
$currentToken = $shop->getToken();
// Setup API stub
$this->setApiStub();
ApiStub::stubResponses(['access_token']);
$result = call_user_func(
$this->action,
$shop->getDomain(),
'12345678'
);
// Refresh to see changes
$shop->refresh();
$this->assertTrue($result->completed);
$this->assertNotSame($currentToken->toNative(), $shop->getToken()->toNative());
}
public function testWithCodeSoftDeletedShop(): void
{
// Create the shop
$shop = factory($this->model)->create([
'deleted_at' => $this->now->getTimestamp(),
]);
// Get the current access token
$currentToken = $shop->getToken();
// Setup API stub
$this->setApiStub();
ApiStub::stubResponses(['access_token']);
$result = call_user_func(
$this->action,
$shop->getDomain(),
'12345678'
);
// Refresh to see changes
$shop->refresh();
$this->assertTrue($result->completed);
$this->assertNotSame($currentToken->toNative(), $shop->getToken()->toNative());
}
}