diff --git a/Gemfile b/Gemfile index defdb2ddbd969388a7bdc2b5710d8031513d3fd0..af35ca9ee18a7781c2eda6d9f702f5a027be0820 100644 --- a/Gemfile +++ b/Gemfile @@ -4,3 +4,4 @@ source 'https://rubygems.org' gemspec # gem 'ci_reporter_test_unit' +gem 'webmock' diff --git a/test/api_cs_protocol_test.rb b/test/api_cs_protocol_test.rb index 609e506fc54f88e6d39a820f1ac1c7a402f534f8..c7768910eab28062dd9e1d56368b67221d625a05 100644 --- a/test/api_cs_protocol_test.rb +++ b/test/api_cs_protocol_test.rb @@ -2,11 +2,7 @@ require 'test_helper' class ApiTest < Test::Unit::TestCase def setup - @http = mock - @http.stubs(:active?).returns(true) - @api = MatrixSdk::Api.new 'https://example.com', protocols: :CS, threadsafe: false - @api.instance_variable_set :@http, @http @api.stubs(:print_http) matrixsdk_add_api_stub @@ -20,19 +16,56 @@ class ApiTest < Test::Unit::TestCase response 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 - @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 end def test_api_unsable_features - @http.expects(:request).returns(mock_success('{"unstable_features":{"lazy_loading_members": true}}')) - assert_equal true, @api.client_api_unstable_features.has?(:lazy_loading_members) + stub_versions_request + assert_equal true, @api.client_api_unstable_features.has?(:"org.matrix.label_based_filtering") end 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_requested stub_get end def test_sync diff --git a/test/test_helper.rb b/test/test_helper.rb index 45ca41538d78f78750317616324acdc10dfcd7a9..486fd45804901ff3a87d7ffc9369020ea9906883 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -9,6 +9,7 @@ require 'matrix_sdk' require 'test/unit' require 'mocha/test_unit' +require 'webmock/test_unit' RUBY_MAJOR_MINOR_VERSION = RUBY_VERSION[0..2].freeze OLDER_RUBY = %w[2.5 2.6].include?(RUBY_MAJOR_MINOR_VERSION)