From b8bbfc59b4fd8fa6b514bd9df72f67059e14a840 Mon Sep 17 00:00:00 2001
From: "Alexander \"Ace\" Olofsson" <ace@haxalot.com>
Date: Fri, 25 Aug 2023 09:15:42 +0200
Subject: [PATCH] Continue webmock conversion

---
 test/api_cs_protocol_test.rb | 33 ++++++++++++++++-----------------
 test/room_test.rb            | 12 ++++++------
 2 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/test/api_cs_protocol_test.rb b/test/api_cs_protocol_test.rb
index c776891..aa61fec 100644
--- a/test/api_cs_protocol_test.rb
+++ b/test/api_cs_protocol_test.rb
@@ -17,7 +17,7 @@ class ApiTest < Test::Unit::TestCase
   end
 
   def stub_versions_request
-    stub_request(:get, '/_matrix/client/versions').to_return_json(
+    stub_request(:get, 'https://example.com/_matrix/client/versions').to_return_json(
       body: {
         versions: [ "r0.0.1", "r0.1.0", "r0.2.0", "r0.3.0", "r0.4.0", "r0.5.0", "r0.6.0","r0.6.1", "v1.1", "v1.2", "v1.3", "v1.4","v1.5","v1.6" ],
         unstable_features: {
@@ -50,7 +50,7 @@ class ApiTest < Test::Unit::TestCase
 
   def test_api_versions
     stub_versions_request
-    assert_equal 'r0.4.0', @api.client_api_versions.latest
+    assert_equal 'v1.6', @api.client_api_versions.latest
   end
 
   def test_api_unsable_features
@@ -59,38 +59,37 @@ class ApiTest < Test::Unit::TestCase
   end
 
   def test_whoami
-    stub_get = stub_request(:get, '/_matrix/client/v3/account/whoami').to_return_json(
+    stub_request(:get, 'https://example.com/_matrix/client/r0/account/whoami').to_return_json(
       body: {
+        user_id: '@user:example.com',
+        device_id: 'SZXMMIIRVP',
+        is_guest: false
       }
     )
 
-    assert_equal @api.whoami?, user_id: '@user:example.com'
-    assert_requested stub_get
+    assert_equal '@user:example.com', @api.whoami?[:user_id]
   end
 
   def test_sync
-    @http.expects(:request).with do |req|
-      req.path == '/_matrix/client/r0/sync?timeout=30000'
-    end.returns(mock_success('{}'))
+    stub_request(:get, 'https://example.com/_matrix/client/r0/sync').with(query: { timeout: 30000 }).to_return_json(body: {})
     assert @api.sync
   end
 
   def test_sync_timeout
-    @http.expects(:request).with do |req|
-      req.path == '/_matrix/client/r0/sync?timeout=3000'
-    end.returns(mock_success('{}'))
-
+    stub_request(:get, 'https://example.com/_matrix/client/r0/sync').with(query: { timeout: 3000}).to_return_json(body: {})
     assert @api.sync(timeout: 3)
 
-    @http.expects(:request).with do |req|
-      req.path == '/_matrix/client/r0/sync'
-    end.returns(mock_success('{}'))
-
+    stub_request(:get, 'https://example.com/_matrix/client/r0/sync').with(query: nil).to_return_json(body: {})
     assert @api.sync(timeout: nil)
   end
 
   def test_send_message
-    @api.expects(:request).with(:put, :client_r0, '/rooms/%21room%3Aexample.com/send/m.room.message/42', body: { msgtype: 'm.text', body: 'this is a message' }, query: {}).returns({})
+    stub_request(:put, 'https://example.com/_matrix/client/r0/rooms/%21room%3Aexample.com/send/m.room.message/42').with(
+      body: {
+        msgtype: 'm.text',
+        body: 'this is a message'
+      }
+    ).to_return_json(body: {})
     assert @api.send_message('!room:example.com', 'this is a message', txn_id: 42)
   end
 
diff --git a/test/room_test.rb b/test/room_test.rb
index 29a4194..96a16f2 100644
--- a/test/room_test.rb
+++ b/test/room_test.rb
@@ -115,7 +115,7 @@ class RoomTest < Test::Unit::TestCase
     @api.expects(:send_message).with(@id, text)
     @room.send_text(text)
 
-    @api.expects(:send_message_event).with(@id, 'm.room.message', body: 'test', msgtype: 'm.text', formatted_body: text, format: 'org.matrix.custom.html')
+    @api.expects(:send_message_event).with(@id, 'm.room.message', { body: 'test', msgtype: 'm.text', formatted_body: text, format: 'org.matrix.custom.html'})
     @room.send_html(text)
 
     @api.expects(:send_emote).with(@id, text)
@@ -161,17 +161,17 @@ class RoomTest < Test::Unit::TestCase
     @api.expects(:get_room_account_data).with('@alice:example.com', @id, 'com.example.Test')
     @room.get_account_data('com.example.Test')
 
-    @api.expects(:set_room_account_data).with('@alice:example.com', @id, 'com.example.Test', data: true)
+    @api.expects(:set_room_account_data).with('@alice:example.com', @id, 'com.example.Test', { data: true })
     @room.set_account_data('com.example.Test', data: true)
 
     @api.expects(:get_membership).with(@id, '@alice:example.com').returns(membership: 'join')
-    @api.expects(:set_membership).with(@id, '@alice:example.com', 'join', 'Updating room profile information', membership: 'join', displayname: 'Alice', avatar_url: 'mxc://example.com/avatar')
+    @api.expects(:set_membership).with(@id, '@alice:example.com', 'join', 'Updating room profile information', { membership: 'join', displayname: 'Alice', avatar_url: 'mxc://example.com/avatar' })
     @room.set_user_profile display_name: 'Alice', avatar_url: 'mxc://example.com/avatar'
 
     @api.expects(:get_user_tags).with('@alice:example.com', @id).returns(tags: { 'example.tag': {} })
     tags = @room.tags
 
-    @api.expects(:add_user_tag).with('@alice:example.com', @id, :'test.tag', data: true)
+    @api.expects(:add_user_tag).with('@alice:example.com', @id, :'test.tag', { data: true })
     tags.add 'test.tag', data: true
 
     @api.expects(:remove_user_tag).with('@alice:example.com', @id, :'test.tag')
@@ -280,11 +280,11 @@ class RoomTest < Test::Unit::TestCase
   def test_modifies
     @api.expects(:get_room_state).with(@id, 'm.room.power_levels').returns users_default: 0, redact: 50
 
-    @api.expects(:set_room_state).with(@id, 'm.room.power_levels', users_default: 5, redact: 50, users: { '@alice:example.com': 100 })
+    @api.expects(:set_room_state).with(@id, 'm.room.power_levels', { users_default: 5, redact: 50, users: { '@alice:example.com': 100 }})
     @room.modify_user_power_levels({ '@alice:example.com': 100 }, 5)
 
     @api.expects(:get_room_state).with(@id, 'm.room.power_levels').returns users_default: 0, redact: 50
-    @api.expects(:set_room_state).with(@id, 'm.room.power_levels', users_default: 0, redact: 50, events: { 'm.room.message': 100 })
+    @api.expects(:set_room_state).with(@id, 'm.room.power_levels', { users_default: 0, redact: 50, events: { 'm.room.message': 100 }})
     @room.modify_required_power_levels 'm.room.message': 100
   end
 end
-- 
GitLab