Skip to content
Snippets Groups Projects
Verified Commit 0bbbe869 authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Starting conversion to webmock

parent 6e6c8f0c
No related branches found
No related tags found
No related merge requests found
...@@ -4,3 +4,4 @@ source 'https://rubygems.org' ...@@ -4,3 +4,4 @@ source 'https://rubygems.org'
gemspec gemspec
# gem 'ci_reporter_test_unit' # gem 'ci_reporter_test_unit'
gem 'webmock'
...@@ -2,11 +2,7 @@ require 'test_helper' ...@@ -2,11 +2,7 @@ require 'test_helper'
class ApiTest < Test::Unit::TestCase class ApiTest < Test::Unit::TestCase
def setup def setup
@http = mock
@http.stubs(:active?).returns(true)
@api = MatrixSdk::Api.new 'https://example.com', protocols: :CS, threadsafe: false @api = MatrixSdk::Api.new 'https://example.com', protocols: :CS, threadsafe: false
@api.instance_variable_set :@http, @http
@api.stubs(:print_http) @api.stubs(:print_http)
matrixsdk_add_api_stub matrixsdk_add_api_stub
...@@ -20,19 +16,56 @@ class ApiTest < Test::Unit::TestCase ...@@ -20,19 +16,56 @@ class ApiTest < Test::Unit::TestCase
response response
end end
def stub_versions_request
stub_request(:get, '/_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: {
"org.matrix.label_based_filtering": true,
"org.matrix.e2e_cross_signing": true,
"org.matrix.msc2432": true,
"uk.half-shot.msc2666.query_mutual_rooms": true,
"io.element.e2ee_forced.public": false,
"io.element.e2ee_forced.private": false,
"io.element.e2ee_forced.trusted_private": false,
"org.matrix.msc3026.busy_presence": false,
"org.matrix.msc2285.stable": true,
"org.matrix.msc3827.stable": true,
"org.matrix.msc3440.stable": true,
"org.matrix.msc3771": true,
"org.matrix.msc3773": false,
"fi.mau.msc2815": false,
"fi.mau.msc2659.stable": true,
"org.matrix.msc3882": false,
"org.matrix.msc3881": false,
"org.matrix.msc3874": false,
"org.matrix.msc3886": false,
"org.matrix.msc3912": false,
"org.matrix.msc3981": false,
"org.matrix.msc3391": false
}
}
)
end
def test_api_versions def test_api_versions
@http.expects(:request).returns(mock_success('{"versions":["r0.3.0","r0.4.0"]}')) stub_versions_request
assert_equal 'r0.4.0', @api.client_api_versions.latest assert_equal 'r0.4.0', @api.client_api_versions.latest
end end
def test_api_unsable_features def test_api_unsable_features
@http.expects(:request).returns(mock_success('{"unstable_features":{"lazy_loading_members": true}}')) stub_versions_request
assert_equal true, @api.client_api_unstable_features.has?(:lazy_loading_members) assert_equal true, @api.client_api_unstable_features.has?(:"org.matrix.label_based_filtering")
end end
def test_whoami def test_whoami
@http.expects(:request).returns(mock_success('{"user_id":"@user:example.com"}')) stub_get = stub_request(:get, '/_matrix/client/v3/account/whoami').to_return_json(
body: {
}
)
assert_equal @api.whoami?, user_id: '@user:example.com' assert_equal @api.whoami?, user_id: '@user:example.com'
assert_requested stub_get
end end
def test_sync def test_sync
......
...@@ -9,6 +9,7 @@ require 'matrix_sdk' ...@@ -9,6 +9,7 @@ require 'matrix_sdk'
require 'test/unit' require 'test/unit'
require 'mocha/test_unit' require 'mocha/test_unit'
require 'webmock/test_unit'
RUBY_MAJOR_MINOR_VERSION = RUBY_VERSION[0..2].freeze RUBY_MAJOR_MINOR_VERSION = RUBY_VERSION[0..2].freeze
OLDER_RUBY = %w[2.5 2.6].include?(RUBY_MAJOR_MINOR_VERSION) OLDER_RUBY = %w[2.5 2.6].include?(RUBY_MAJOR_MINOR_VERSION)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment