Skip to content

Commit 0bceb14

Browse files
committed
Add refresh_token and refresh_token_expires_in to AccessTokenResponse
1 parent f1bd40b commit 0bceb14

File tree

2 files changed

+213
-1
lines changed

2 files changed

+213
-1
lines changed

lib/shopify_api/auth/oauth/access_token_response.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class AccessTokenResponse < T::Struct
1313
const :expires_in, T.nilable(Integer)
1414
const :associated_user, T.nilable(AssociatedUser)
1515
const :associated_user_scope, T.nilable(String)
16+
const :refresh_token, T.nilable(String)
17+
const :refresh_token_expires_in, T.nilable(Integer)
1618

1719
sig { returns(T::Boolean) }
1820
def online_token?
@@ -29,7 +31,9 @@ def ==(other)
2931
session == other.session &&
3032
expires_in == other.expires_in &&
3133
associated_user == other.associated_user &&
32-
associated_user_scope == other.associated_user_scope
34+
associated_user_scope == other.associated_user_scope &&
35+
refresh_token == other.refresh_token &&
36+
refresh_token_expires_in == other.refresh_token_expires_in
3337
end
3438
end
3539
end

test/auth/oauth/access_token_response_test.rb

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,214 @@ def test_online_token_is_true_when_associated_user_is_present
3737

3838
assert(token_response.online_token?)
3939
end
40+
41+
def test_equality_with_all_fields_matching
42+
access_token = "access_token"
43+
scope = "scope1, scope2"
44+
session = "session_id"
45+
expires_in = 3600
46+
associated_user = ShopifyAPI::Auth::AssociatedUser.new(
47+
id: 902541635,
48+
first_name: "first",
49+
last_name: "last",
50+
51+
email_verified: true,
52+
account_owner: true,
53+
locale: "en",
54+
collaborator: false,
55+
)
56+
associated_user_scope = "user_scope"
57+
refresh_token = "refresh_token_value"
58+
refresh_token_expires_in = 2000
59+
60+
token_response1 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
61+
access_token:,
62+
scope:,
63+
session:,
64+
expires_in:,
65+
associated_user:,
66+
associated_user_scope:,
67+
refresh_token:,
68+
refresh_token_expires_in:,
69+
)
70+
token_response2 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
71+
access_token:,
72+
scope:,
73+
session:,
74+
expires_in:,
75+
associated_user:,
76+
associated_user_scope:,
77+
refresh_token:,
78+
refresh_token_expires_in:,
79+
)
80+
81+
assert_equal(token_response1, token_response2)
82+
end
83+
84+
def test_inequality_with_different_access_token
85+
scope = "scope1, scope2"
86+
87+
token_response1 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
88+
access_token: "access_token_1",
89+
scope:,
90+
)
91+
token_response2 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
92+
access_token: "access_token_2",
93+
scope:,
94+
)
95+
96+
refute_equal(token_response1, token_response2)
97+
end
98+
99+
def test_inequality_with_different_scope
100+
access_token = "access_token"
101+
102+
token_response1 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
103+
access_token:,
104+
scope: "scope1, scope2",
105+
)
106+
token_response2 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
107+
access_token:,
108+
scope: "scope3, scope4",
109+
)
110+
111+
refute_equal(token_response1, token_response2)
112+
end
113+
114+
def test_inequality_with_different_session
115+
access_token = "access_token"
116+
scope = "scope1, scope2"
117+
118+
token_response1 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
119+
access_token:,
120+
scope:,
121+
session: "session_1",
122+
)
123+
token_response2 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
124+
access_token:,
125+
scope:,
126+
session: "session_2",
127+
)
128+
129+
refute_equal(token_response1, token_response2)
130+
end
131+
132+
def test_inequality_with_different_expires_in
133+
access_token = "access_token"
134+
scope = "scope1, scope2"
135+
136+
token_response1 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
137+
access_token:,
138+
scope:,
139+
expires_in: 3600,
140+
)
141+
token_response2 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
142+
access_token:,
143+
scope:,
144+
expires_in: 7200,
145+
)
146+
147+
refute_equal(token_response1, token_response2)
148+
end
149+
150+
def test_inequality_with_different_associated_user
151+
access_token = "access_token"
152+
scope = "scope1, scope2"
153+
associated_user1 = ShopifyAPI::Auth::AssociatedUser.new(
154+
id: 1,
155+
first_name: "first",
156+
last_name: "last",
157+
158+
email_verified: true,
159+
account_owner: true,
160+
locale: "en",
161+
collaborator: false,
162+
)
163+
associated_user2 = ShopifyAPI::Auth::AssociatedUser.new(
164+
id: 2,
165+
first_name: "other",
166+
last_name: "user",
167+
168+
email_verified: true,
169+
account_owner: false,
170+
locale: "en",
171+
collaborator: true,
172+
)
173+
174+
token_response1 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
175+
access_token:,
176+
scope:,
177+
associated_user: associated_user1,
178+
)
179+
token_response2 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
180+
access_token:,
181+
scope:,
182+
associated_user: associated_user2,
183+
)
184+
185+
refute_equal(token_response1, token_response2)
186+
end
187+
188+
def test_inequality_with_different_associated_user_scope
189+
access_token = "access_token"
190+
scope = "scope1, scope2"
191+
192+
token_response1 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
193+
access_token:,
194+
scope:,
195+
associated_user_scope: "user_scope_1",
196+
)
197+
token_response2 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
198+
access_token:,
199+
scope:,
200+
associated_user_scope: "user_scope_2",
201+
)
202+
203+
refute_equal(token_response1, token_response2)
204+
end
205+
206+
def test_refresh_token_can_be_set
207+
token_response = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
208+
access_token: "token",
209+
scope: "scope1, scope2",
210+
expires_in: 1000,
211+
refresh_token: "refresh_token_value",
212+
refresh_token_expires_in: 2000,
213+
)
214+
215+
assert_equal("refresh_token_value", token_response.refresh_token)
216+
assert_equal(2000, token_response.refresh_token_expires_in)
217+
end
218+
219+
def test_inequality_with_different_refresh_token
220+
access_token = "access_token"
221+
scope = "scope1, scope2"
222+
223+
token_response1 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(access_token:, scope:,
224+
refresh_token: "refresh_token_1")
225+
token_response2 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(access_token:, scope:,
226+
refresh_token: "refresh_token_2")
227+
228+
refute_equal(token_response1, token_response2)
229+
end
230+
231+
def test_inequality_with_different_refresh_token_expires_in
232+
access_token = "access_token"
233+
scope = "scope1, scope2"
234+
235+
token_response1 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
236+
access_token:,
237+
scope:,
238+
refresh_token_expires_in: 123,
239+
)
240+
token_response2 = ShopifyAPI::Auth::Oauth::AccessTokenResponse.new(
241+
access_token:,
242+
scope:,
243+
refresh_token_expires_in: 321,
244+
)
245+
246+
refute_equal(token_response1, token_response2)
247+
end
40248
end
41249
end
42250
end

0 commit comments

Comments
 (0)