@@ -143,9 +143,63 @@ def test_from_with_online_access_token_response
143143 assert_equal ( expected_session , session )
144144 end
145145
146+ def test_copy_attributes_from
147+ session_to = ShopifyAPI ::Auth ::Session . new (
148+ id : "session-id" ,
149+ shop : "shop" ,
150+ state : "some-state" ,
151+ access_token : "to-token" ,
152+ scope : "read_products,read_themes" ,
153+ associated_user_scope : "read_products" ,
154+ expires : Time . now - 3600 ,
155+ associated_user : build_user ,
156+ is_online : true ,
157+ shopify_session_id : "123" ,
158+ )
159+
160+ session_from = ShopifyAPI ::Auth ::Session . new (
161+ id : "session-id" ,
162+ shop : "shop" ,
163+ state : nil ,
164+ access_token : "from-token" ,
165+ scope : "write_products,read_themes" ,
166+ associated_user_scope : "write_products" ,
167+ expires : Time . now + 24 * 3600 ,
168+ associated_user : build_user ,
169+ is_online : true ,
170+ shopify_session_id : "456" ,
171+ )
172+
173+ assert_equal ( session_to , session_to . copy_attributes_from ( session_from ) )
174+
175+ assert_equal ( session_from . shop , session_to . shop )
176+ assert_nil ( session_to . state )
177+ assert_equal ( session_from . access_token , session_to . access_token )
178+ assert_equal ( session_from . scope , session_to . scope )
179+ assert_equal ( session_from . associated_user_scope , session_to . associated_user_scope )
180+ assert_equal ( session_from . expires , session_to . expires )
181+ assert_equal ( session_from . associated_user , session_to . associated_user )
182+ assert_equal ( session_from . shopify_session_id , session_to . shopify_session_id )
183+ end
184+
146185 def teardown
147186 ShopifyAPI ::Context . deactivate_session
148187 end
188+
189+ private
190+
191+ def build_user
192+ ShopifyAPI ::Auth ::AssociatedUser . new (
193+ id : 1 ,
194+ first_name : "Hello #{ Time . now } " ,
195+ last_name : "World" ,
196+ email : "Email" ,
197+ email_verified : true ,
198+ account_owner : true ,
199+ locale : "en" ,
200+ collaborator : false ,
201+ )
202+ end
149203 end
150204 end
151205end
0 commit comments