Skip to content

Commit f1bd40b

Browse files
committed
Add new configuation to Context
1 parent 8522bbd commit f1bd40b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/shopify_api/context.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Context
2525
@rest_disabled = T.let(false, T.nilable(T::Boolean))
2626

2727
@rest_resource_loader = T.let(nil, T.nilable(Zeitwerk::Loader))
28+
@expiring_offline_access_tokens = T.let(false, T::Boolean)
2829

2930
class << self
3031
extend T::Sig
@@ -47,6 +48,7 @@ class << self
4748
api_host: T.nilable(String),
4849
response_as_struct: T.nilable(T::Boolean),
4950
rest_disabled: T.nilable(T::Boolean),
51+
expiring_offline_access_tokens: T.nilable(T::Boolean),
5052
).void
5153
end
5254
def setup(
@@ -65,7 +67,8 @@ def setup(
6567
old_api_secret_key: nil,
6668
api_host: nil,
6769
response_as_struct: false,
68-
rest_disabled: false
70+
rest_disabled: false,
71+
expiring_offline_access_tokens: false
6972
)
7073
unless ShopifyAPI::AdminVersions::SUPPORTED_ADMIN_VERSIONS.include?(api_version)
7174
raise Errors::UnsupportedVersionError,
@@ -86,6 +89,7 @@ def setup(
8689
@old_api_secret_key = old_api_secret_key
8790
@response_as_struct = response_as_struct
8891
@rest_disabled = rest_disabled
92+
@expiring_offline_access_tokens = T.must(expiring_offline_access_tokens)
8993
@log_level = if valid_log_level?(log_level)
9094
log_level.to_sym
9195
else
@@ -148,6 +152,9 @@ def private?
148152
sig { returns(T.nilable(String)) }
149153
attr_reader :private_shop, :user_agent_prefix, :old_api_secret_key, :host, :api_host
150154

155+
sig { returns(T::Boolean) }
156+
attr_reader :expiring_offline_access_tokens
157+
151158
sig { returns(T::Boolean) }
152159
def embedded?
153160
@is_embedded

test/context_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,29 @@ def test_rest_disabled_can_be_set_in_setup
201201
assert(ShopifyAPI::Context.rest_disabled)
202202
end
203203

204+
def test_expiring_offline_access_tokens_defaults_to_false
205+
ShopifyAPI::Context.setup(
206+
api_key: "test-key",
207+
api_secret_key: "test-secret-key",
208+
api_version: "2023-01",
209+
is_private: true,
210+
is_embedded: false,
211+
)
212+
refute(ShopifyAPI::Context.expiring_offline_access_tokens)
213+
end
214+
215+
def test_expiring_offline_access_tokens_can_be_configured
216+
ShopifyAPI::Context.setup(
217+
api_key: "test-key",
218+
api_secret_key: "test-secret-key",
219+
api_version: "2023-01",
220+
is_private: true,
221+
is_embedded: false,
222+
expiring_offline_access_tokens: true,
223+
)
224+
assert(ShopifyAPI::Context.expiring_offline_access_tokens)
225+
end
226+
204227
def teardown
205228
ShopifyAPI::Context.deactivate_session
206229
end

0 commit comments

Comments
 (0)