]> git.openstreetmap.org Git - rails.git/commitdiff
Use resourceful routes for api messages in/outbox
authorAnton Khorev <tony29@yandex.ru>
Sun, 22 Dec 2024 03:57:39 +0000 (06:57 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sun, 22 Dec 2024 04:03:41 +0000 (07:03 +0300)
16 files changed:
.rubocop_todo.yml
app/abilities/api_ability.rb
app/controllers/api/messages/inboxes_controller.rb [new file with mode: 0644]
app/controllers/api/messages/mailboxes_controller.rb [new file with mode: 0644]
app/controllers/api/messages/outboxes_controller.rb [new file with mode: 0644]
app/controllers/api/messages_controller.rb
app/views/api/messages/inbox.json.jbuilder [deleted file]
app/views/api/messages/inbox.xml.builder [deleted file]
app/views/api/messages/mailboxes/show.json.jbuilder [new file with mode: 0644]
app/views/api/messages/mailboxes/show.xml.builder [new file with mode: 0644]
app/views/api/messages/outbox.json.jbuilder [deleted file]
app/views/api/messages/outbox.xml.builder [deleted file]
config/routes.rb
test/controllers/api/messages/inboxes_controller_test.rb [new file with mode: 0644]
test/controllers/api/messages/outboxes_controller_test.rb [new file with mode: 0644]
test/controllers/api/messages_controller_test.rb

index 0dd79ea2aefe33503668d07edb841ffc4a518e89..071abc44c37d72262c8765515e88725fb1618ffb 100644 (file)
@@ -20,7 +20,8 @@ require:
 FactoryBot/ExcessiveCreateList:
   Exclude:
     - 'test/controllers/api/changeset_comments_controller_test.rb'
-    - 'test/controllers/api/messages_controller_test.rb'
+    - 'test/controllers/api/messages/inboxes_controller_test.rb'
+    - 'test/controllers/api/messages/outboxes_controller_test.rb'
     - 'test/controllers/changesets_controller_test.rb'
     - 'test/controllers/diary_entries_controller_test.rb'
     - 'test/controllers/notes_controller_test.rb'
index 4ed9708b40340093f3a0baed7ecff96e2903a7de..3fe180eeb96fd323c63121e9ba34b5a027a32e87 100644 (file)
@@ -34,7 +34,7 @@ class ApiAbility
         can :read, UserPreference if scope?(token, :read_prefs)
         can [:update, :update_all, :destroy], UserPreference if scope?(token, :write_prefs)
 
-        can [:inbox, :outbox, :read, :update, :destroy], Message if scope?(token, :consume_messages)
+        can [:read, :update, :destroy], Message if scope?(token, :consume_messages)
         can :create, Message if scope?(token, :send_messages)
 
         if user.terms_agreed?
diff --git a/app/controllers/api/messages/inboxes_controller.rb b/app/controllers/api/messages/inboxes_controller.rb
new file mode 100644 (file)
index 0000000..d2d2af7
--- /dev/null
@@ -0,0 +1,12 @@
+module Api
+  module Messages
+    class InboxesController < MailboxesController
+      def show
+        @skip_body = true
+        @messages = Message.includes(:sender, :recipient).where(:to_user_id => current_user.id)
+
+        show_messages
+      end
+    end
+  end
+end
diff --git a/app/controllers/api/messages/mailboxes_controller.rb b/app/controllers/api/messages/mailboxes_controller.rb
new file mode 100644 (file)
index 0000000..1a8e143
--- /dev/null
@@ -0,0 +1,43 @@
+module Api
+  module Messages
+    class MailboxesController < ApiController
+      before_action :authorize
+
+      authorize_resource :message
+
+      before_action :set_request_formats
+
+      private
+
+      def show_messages
+        @messages = @messages.where(:muted => false)
+        if params[:order].nil? || params[:order] == "newest"
+          @messages = @messages.where(:id => ..params[:from_id]) unless params[:from_id].nil?
+          @messages = @messages.order(:id => :desc)
+        elsif params[:order] == "oldest"
+          @messages = @messages.where(:id => params[:from_id]..) unless params[:from_id].nil?
+          @messages = @messages.order(:id => :asc)
+        else
+          raise OSM::APIBadUserInput, "Invalid order specified"
+        end
+
+        limit = params[:limit]
+        if !limit
+          limit = Settings.default_message_query_limit
+        elsif !limit.to_i.positive? || limit.to_i > Settings.max_message_query_limit
+          raise OSM::APIBadUserInput, "Messages limit must be between 1 and #{Settings.max_message_query_limit}"
+        else
+          limit = limit.to_i
+        end
+
+        @messages = @messages.limit(limit)
+
+        # Render the result
+        respond_to do |format|
+          format.xml
+          format.json
+        end
+      end
+    end
+  end
+end
diff --git a/app/controllers/api/messages/outboxes_controller.rb b/app/controllers/api/messages/outboxes_controller.rb
new file mode 100644 (file)
index 0000000..d362648
--- /dev/null
@@ -0,0 +1,12 @@
+module Api
+  module Messages
+    class OutboxesController < MailboxesController
+      def show
+        @skip_body = true
+        @messages = Message.includes(:sender, :recipient).where(:from_user_id => current_user.id)
+
+        show_messages
+      end
+    end
+  end
+end
index 886922bff1f8918ad7d58b4f38b1b8246be372e8..cbbd8539cc76e7333437615341a8a2f9b45ba06f 100644 (file)
@@ -11,20 +11,6 @@ module Api
 
     before_action :set_request_formats
 
-    def inbox
-      @skip_body = true
-      @messages = Message.includes(:sender, :recipient).where(:to_user_id => current_user.id)
-
-      show_messages
-    end
-
-    def outbox
-      @skip_body = true
-      @messages = Message.includes(:sender, :recipient).where(:from_user_id => current_user.id)
-
-      show_messages
-    end
-
     # Dump the details on a message given in params[:id]
     def show
       @message = Message.includes(:sender, :recipient).find(params[:id])
@@ -111,37 +97,5 @@ module Api
         format.json { render :action => :show }
       end
     end
-
-    private
-
-    def show_messages
-      @messages = @messages.where(:muted => false)
-      if params[:order].nil? || params[:order] == "newest"
-        @messages = @messages.where(:id => ..params[:from_id]) unless params[:from_id].nil?
-        @messages = @messages.order(:id => :desc)
-      elsif params[:order] == "oldest"
-        @messages = @messages.where(:id => params[:from_id]..) unless params[:from_id].nil?
-        @messages = @messages.order(:id => :asc)
-      else
-        raise OSM::APIBadUserInput, "Invalid order specified"
-      end
-
-      limit = params[:limit]
-      if !limit
-        limit = Settings.default_message_query_limit
-      elsif !limit.to_i.positive? || limit.to_i > Settings.max_message_query_limit
-        raise OSM::APIBadUserInput, "Messages limit must be between 1 and #{Settings.max_message_query_limit}"
-      else
-        limit = limit.to_i
-      end
-
-      @messages = @messages.limit(limit)
-
-      # Render the result
-      respond_to do |format|
-        format.xml
-        format.json
-      end
-    end
   end
 end
diff --git a/app/views/api/messages/inbox.json.jbuilder b/app/views/api/messages/inbox.json.jbuilder
deleted file mode 100644 (file)
index 122a824..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-json.partial! "api/root_attributes"
-
-json.messages do
-  json.array! @messages, :partial => "message", :as => :message
-end
diff --git a/app/views/api/messages/inbox.xml.builder b/app/views/api/messages/inbox.xml.builder
deleted file mode 100644 (file)
index 0ef9003..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-xml.instruct!
-
-xml.osm(OSM::API.new.xml_root_attributes) do |osm|
-  xml.tag! "messages" do
-    osm << (render(@messages) || "")
-  end
-end
diff --git a/app/views/api/messages/mailboxes/show.json.jbuilder b/app/views/api/messages/mailboxes/show.json.jbuilder
new file mode 100644 (file)
index 0000000..c96e710
--- /dev/null
@@ -0,0 +1,5 @@
+json.partial! "api/root_attributes"
+
+json.messages do
+  json.array! @messages, :partial => "api/messages/message", :as => :message
+end
diff --git a/app/views/api/messages/mailboxes/show.xml.builder b/app/views/api/messages/mailboxes/show.xml.builder
new file mode 100644 (file)
index 0000000..94aa32f
--- /dev/null
@@ -0,0 +1,5 @@
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+  osm << (render(:partial => "api/messages/message", :collection => @messages) || "")
+end
diff --git a/app/views/api/messages/outbox.json.jbuilder b/app/views/api/messages/outbox.json.jbuilder
deleted file mode 100644 (file)
index 122a824..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-json.partial! "api/root_attributes"
-
-json.messages do
-  json.array! @messages, :partial => "message", :as => :message
-end
diff --git a/app/views/api/messages/outbox.xml.builder b/app/views/api/messages/outbox.xml.builder
deleted file mode 100644 (file)
index 440e342..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-xml.instruct!
-
-xml.osm(OSM::API.new.xml_root_attributes) do |osm|
-  osm << (render(@messages) || "")
-end
index aae32527a4426e14e49bdab46b7932d3f36f17b9..0e00da9e3b4f0555b28fd1c06b747b272bf0d5f9 100644 (file)
@@ -80,13 +80,12 @@ OpenStreetMap::Application.routes.draw do
       end
     end
 
-    resources :messages, :path => "user/messages", :constraints => { :id => /\d+/ }, :only => [:create, :show, :update, :destroy] do
-      collection do
-        get "inbox"
-        get "outbox"
-      end
+    resources :messages, :path => "user/messages", :constraints => { :id => /\d+/ }, :only => [:create, :show, :update, :destroy]
+    namespace :messages, :path => "user/messages" do
+      resource :inbox, :only => :show
+      resource :outbox, :only => :show
     end
-    post "/user/messages/:id" => "messages#update"
+    post "/user/messages/:id" => "messages#update", :as => nil
 
     resources :traces, :path => "gpx", :only => [:create, :show, :update, :destroy], :id => /\d+/ do
       scope :module => :traces do
diff --git a/test/controllers/api/messages/inboxes_controller_test.rb b/test/controllers/api/messages/inboxes_controller_test.rb
new file mode 100644 (file)
index 0000000..f863146
--- /dev/null
@@ -0,0 +1,170 @@
+require "test_helper"
+
+module Api
+  module Messages
+    class InboxesControllerTest < ActionDispatch::IntegrationTest
+      ##
+      # test all routes which lead to this controller
+      def test_routes
+        assert_routing(
+          { :path => "/api/0.6/user/messages/inbox", :method => :get },
+          { :controller => "api/messages/inboxes", :action => "show" }
+        )
+        assert_routing(
+          { :path => "/api/0.6/user/messages/inbox.xml", :method => :get },
+          { :controller => "api/messages/inboxes", :action => "show", :format => "xml" }
+        )
+        assert_routing(
+          { :path => "/api/0.6/user/messages/inbox.json", :method => :get },
+          { :controller => "api/messages/inboxes", :action => "show", :format => "json" }
+        )
+      end
+
+      def test_show
+        user1 = create(:user)
+        user1_auth = bearer_authorization_header(user1, :scopes => %w[send_messages consume_messages])
+
+        user2 = create(:user)
+        user2_auth = bearer_authorization_header(user2, :scopes => %w[send_messages consume_messages])
+
+        user3 = create(:user)
+        user3_auth = bearer_authorization_header(user3, :scopes => %w[send_messages consume_messages])
+
+        # create some messages between users
+        # user | inbox | outbox
+        #   1  |   0   |   3
+        #   2  |   2   |   1
+        #   3  |   2   |   0
+        create(:message, :unread, :sender => user1, :recipient => user2)
+        create(:message, :unread, :sender => user1, :recipient => user2)
+        create(:message, :unread, :sender => user1, :recipient => user3)
+        create(:message, :unread, :sender => user2, :recipient => user3)
+
+        # only authorized users
+        get api_messages_inbox_path
+        assert_response :unauthorized
+
+        # no messages in user1.inbox
+        get api_messages_inbox_path, :headers => user1_auth
+        assert_response :success
+        assert_equal "application/xml", response.media_type
+        assert_select "message", :count => 0
+
+        # 2 messages in user2.inbox
+        get api_messages_inbox_path, :headers => user2_auth
+        assert_response :success
+        assert_equal "application/xml", response.media_type
+        assert_select "message", :count => 2 do
+          assert_select "[from_user_id]"
+          assert_select "[from_display_name]"
+          assert_select "[to_user_id='#{user2.id}']"
+          assert_select "[to_display_name='#{user2.display_name}']"
+          assert_select "[sent_on]"
+          assert_select "[message_read='false']"
+          assert_select "[deleted='false']"
+          assert_select "[body_format]"
+          assert_select "body", false
+          assert_select "title"
+        end
+
+        # 2 messages in user3.inbox
+        get api_messages_inbox_path, :headers => user3_auth
+        assert_response :success
+        assert_equal "application/xml", response.media_type
+        assert_select "message", :count => 2 do
+          assert_select "[from_user_id]"
+          assert_select "[from_display_name]"
+          assert_select "[to_user_id='#{user3.id}']"
+          assert_select "[to_display_name='#{user3.display_name}']"
+          assert_select "[sent_on]"
+          assert_select "[message_read='false']"
+          assert_select "[deleted='false']"
+          assert_select "[body_format]"
+          assert_select "body", false
+          assert_select "title"
+        end
+      end
+
+      def test_show_paged_asc
+        recipient = create(:user)
+        recipient_auth = bearer_authorization_header(recipient, :scopes => %w[consume_messages])
+
+        sender = create(:user)
+
+        create_list(:message, 100, :unread, :sender => sender, :recipient => recipient)
+
+        msgs_read = {}
+        params = { :order => "oldest", :limit => 20 }
+        10.times do
+          get api_messages_inbox_path(:format => "json"),
+              :params => params,
+              :headers => recipient_auth
+          assert_response :success
+          assert_equal "application/json", response.media_type
+          js = ActiveSupport::JSON.decode(@response.body)
+          jsm = js["messages"]
+          assert_operator jsm.count, :<=, 20
+
+          break if jsm.nil? || jsm.count.zero?
+
+          assert_operator(jsm[0]["id"], :>=, params[:from_id]) unless params[:from_id].nil?
+          # ensure ascending order
+          (0..jsm.count - 1).each do |i|
+            assert_operator(jsm[i]["id"], :<, jsm[i + 1]["id"]) unless i == jsm.count - 1
+            msgs_read[jsm[i]["id"]] = jsm[i]
+          end
+          params[:from_id] = jsm[jsm.count - 1]["id"]
+        end
+        assert_equal 100, msgs_read.count
+      end
+
+      def test_show_paged_desc
+        recipient = create(:user)
+        recipient_auth = bearer_authorization_header(recipient, :scopes => %w[consume_messages])
+
+        sender = create(:user)
+
+        create_list(:message, 100, :unread, :sender => sender, :recipient => recipient)
+
+        real_max_id = -1
+        msgs_read = {}
+        params = { :order => "newest", :limit => 20 }
+        10.times do
+          get api_messages_inbox_path(:format => "json"),
+              :params => params,
+              :headers => recipient_auth
+          assert_response :success
+          assert_equal "application/json", response.media_type
+          js = ActiveSupport::JSON.decode(@response.body)
+          jsm = js["messages"]
+          assert_operator jsm.count, :<=, 20
+
+          break if jsm.nil? || jsm.count.zero?
+
+          if params[:from_id].nil?
+            real_max_id = jsm[0]["id"]
+          else
+            assert_operator jsm[0]["id"], :<=, params[:from_id]
+          end
+          # ensure descending order
+          (0..jsm.count - 1).each do |i|
+            assert_operator(jsm[i]["id"], :>, jsm[i + 1]["id"]) unless i == jsm.count - 1
+            msgs_read[jsm[i]["id"]] = jsm[i]
+          end
+          params[:from_id] = jsm[jsm.count - 1]["id"]
+        end
+        assert_equal 100, msgs_read.count
+        assert_not_equal(-1, real_max_id)
+
+        # invoke without min_id/max_id parameters, verify that we get the last batch
+        get api_messages_inbox_path(:format => "json"), :params => { :limit => 20 }, :headers => recipient_auth
+        assert_response :success
+        assert_equal "application/json", response.media_type
+        js = ActiveSupport::JSON.decode(@response.body)
+        jsm = js["messages"]
+        assert_not_nil jsm
+        assert_equal real_max_id, jsm[0]["id"]
+      end
+    end
+  end
+end
diff --git a/test/controllers/api/messages/outboxes_controller_test.rb b/test/controllers/api/messages/outboxes_controller_test.rb
new file mode 100644 (file)
index 0000000..bc3683b
--- /dev/null
@@ -0,0 +1,89 @@
+require "test_helper"
+
+module Api
+  module Messages
+    class OutboxesControllerTest < ActionDispatch::IntegrationTest
+      ##
+      # test all routes which lead to this controller
+      def test_routes
+        assert_routing(
+          { :path => "/api/0.6/user/messages/outbox", :method => :get },
+          { :controller => "api/messages/outboxes", :action => "show" }
+        )
+        assert_routing(
+          { :path => "/api/0.6/user/messages/outbox.xml", :method => :get },
+          { :controller => "api/messages/outboxes", :action => "show", :format => "xml" }
+        )
+        assert_routing(
+          { :path => "/api/0.6/user/messages/outbox.json", :method => :get },
+          { :controller => "api/messages/outboxes", :action => "show", :format => "json" }
+        )
+      end
+
+      def test_show
+        user1 = create(:user)
+        user1_auth = bearer_authorization_header(user1, :scopes => %w[send_messages consume_messages])
+
+        user2 = create(:user)
+        user2_auth = bearer_authorization_header(user2, :scopes => %w[send_messages consume_messages])
+
+        user3 = create(:user)
+        user3_auth = bearer_authorization_header(user3, :scopes => %w[send_messages consume_messages])
+
+        # create some messages between users
+        # user | inbox | outbox
+        #   1  |   0   |   3
+        #   2  |   2   |   1
+        #   3  |   2   |   0
+        create(:message, :unread, :sender => user1, :recipient => user2)
+        create(:message, :unread, :sender => user1, :recipient => user2)
+        create(:message, :unread, :sender => user1, :recipient => user3)
+        create(:message, :unread, :sender => user2, :recipient => user3)
+
+        # only authorized users
+        get api_messages_outbox_path
+        assert_response :unauthorized
+
+        # 3 messages in user1.outbox
+        get api_messages_outbox_path, :headers => user1_auth
+        assert_response :success
+        assert_equal "application/xml", response.media_type
+        assert_select "message", :count => 3 do
+          assert_select "[from_user_id='#{user1.id}']"
+          assert_select "[from_display_name='#{user1.display_name}']"
+          assert_select "[to_user_id]"
+          assert_select "[to_display_name]"
+          assert_select "[sent_on]"
+          assert_select "[message_read]", 0
+          assert_select "[deleted='false']"
+          assert_select "[body_format]"
+          assert_select "body", false
+          assert_select "title"
+        end
+
+        # 1 message in user2.outbox
+        get api_messages_outbox_path, :headers => user2_auth
+        assert_response :success
+        assert_equal "application/xml", response.media_type
+        assert_select "message", :count => 1 do
+          assert_select "[from_user_id='#{user2.id}']"
+          assert_select "[from_display_name='#{user2.display_name}']"
+          assert_select "[to_user_id]"
+          assert_select "[to_display_name]"
+          assert_select "[sent_on]"
+          assert_select "[deleted='false']"
+          assert_select "[message_read]", 0
+          assert_select "[body_format]"
+          assert_select "body", false
+          assert_select "title"
+        end
+
+        # 0 messages in user3.outbox
+        get api_messages_outbox_path, :headers => user3_auth
+        assert_response :success
+        assert_equal "application/xml", response.media_type
+        assert_select "message", :count => 0
+      end
+    end
+  end
+end
index 91dbd42de6fcd072b8e6bfb6ef2ff0e4375947d9..806a4a505ee75e9de39a840141f3d6239169cf9b 100644 (file)
@@ -5,30 +5,6 @@ module Api
     ##
     # test all routes which lead to this controller
     def test_routes
-      assert_routing(
-        { :path => "/api/0.6/user/messages/inbox", :method => :get },
-        { :controller => "api/messages", :action => "inbox" }
-      )
-      assert_routing(
-        { :path => "/api/0.6/user/messages/inbox.xml", :method => :get },
-        { :controller => "api/messages", :action => "inbox", :format => "xml" }
-      )
-      assert_routing(
-        { :path => "/api/0.6/user/messages/inbox.json", :method => :get },
-        { :controller => "api/messages", :action => "inbox", :format => "json" }
-      )
-      assert_routing(
-        { :path => "/api/0.6/user/messages/outbox", :method => :get },
-        { :controller => "api/messages", :action => "outbox" }
-      )
-      assert_routing(
-        { :path => "/api/0.6/user/messages/outbox.xml", :method => :get },
-        { :controller => "api/messages", :action => "outbox", :format => "xml" }
-      )
-      assert_routing(
-        { :path => "/api/0.6/user/messages/outbox.json", :method => :get },
-        { :controller => "api/messages", :action => "outbox", :format => "json" }
-      )
       assert_routing(
         { :path => "/api/0.6/user/messages/1", :method => :get },
         { :controller => "api/messages", :action => "show", :id => "1" }
@@ -375,193 +351,5 @@ module Api
       assert_equal "markdown", jsm["body_format"]
       assert_equal msg.body, jsm["body"]
     end
-
-    def test_list_messages
-      user1 = create(:user)
-      user1_auth = bearer_authorization_header(user1, :scopes => %w[send_messages consume_messages])
-
-      user2 = create(:user)
-      user2_auth = bearer_authorization_header(user2, :scopes => %w[send_messages consume_messages])
-
-      user3 = create(:user)
-      user3_auth = bearer_authorization_header(user3, :scopes => %w[send_messages consume_messages])
-
-      # create some messages between users
-      # user | inbox | outbox
-      #   1  |   0   |   3
-      #   2  |   2   |   1
-      #   3  |   2   |   0
-      create(:message, :unread, :sender => user1, :recipient => user2)
-      create(:message, :unread, :sender => user1, :recipient => user2)
-      create(:message, :unread, :sender => user1, :recipient => user3)
-      create(:message, :unread, :sender => user2, :recipient => user3)
-
-      # only authorized users
-      get inbox_api_messages_path
-      assert_response :unauthorized
-      get outbox_api_messages_path
-      assert_response :unauthorized
-
-      # no messages in user1.inbox
-      get inbox_api_messages_path, :headers => user1_auth
-      assert_response :success
-      assert_equal "application/xml", response.media_type
-      assert_select "message", :count => 0
-
-      # 3 messages in user1.outbox
-      get outbox_api_messages_path, :headers => user1_auth
-      assert_response :success
-      assert_equal "application/xml", response.media_type
-      assert_select "message", :count => 3 do
-        assert_select "[from_user_id='#{user1.id}']"
-        assert_select "[from_display_name='#{user1.display_name}']"
-        assert_select "[to_user_id]"
-        assert_select "[to_display_name]"
-        assert_select "[sent_on]"
-        assert_select "[message_read]", 0
-        assert_select "[deleted='false']"
-        assert_select "[body_format]"
-        assert_select "body", false
-        assert_select "title"
-      end
-
-      # 2 messages in user2.inbox
-      get inbox_api_messages_path, :headers => user2_auth
-      assert_response :success
-      assert_equal "application/xml", response.media_type
-      assert_select "message", :count => 2 do
-        assert_select "[from_user_id]"
-        assert_select "[from_display_name]"
-        assert_select "[to_user_id='#{user2.id}']"
-        assert_select "[to_display_name='#{user2.display_name}']"
-        assert_select "[sent_on]"
-        assert_select "[message_read='false']"
-        assert_select "[deleted='false']"
-        assert_select "[body_format]"
-        assert_select "body", false
-        assert_select "title"
-      end
-
-      # 1 message in user2.outbox
-      get outbox_api_messages_path, :headers => user2_auth
-      assert_response :success
-      assert_equal "application/xml", response.media_type
-      assert_select "message", :count => 1 do
-        assert_select "[from_user_id='#{user2.id}']"
-        assert_select "[from_display_name='#{user2.display_name}']"
-        assert_select "[to_user_id]"
-        assert_select "[to_display_name]"
-        assert_select "[sent_on]"
-        assert_select "[deleted='false']"
-        assert_select "[message_read]", 0
-        assert_select "[body_format]"
-        assert_select "body", false
-        assert_select "title"
-      end
-
-      # 2 messages in user3.inbox
-      get inbox_api_messages_path, :headers => user3_auth
-      assert_response :success
-      assert_equal "application/xml", response.media_type
-      assert_select "message", :count => 2 do
-        assert_select "[from_user_id]"
-        assert_select "[from_display_name]"
-        assert_select "[to_user_id='#{user3.id}']"
-        assert_select "[to_display_name='#{user3.display_name}']"
-        assert_select "[sent_on]"
-        assert_select "[message_read='false']"
-        assert_select "[deleted='false']"
-        assert_select "[body_format]"
-        assert_select "body", false
-        assert_select "title"
-      end
-
-      # 0 messages in user3.outbox
-      get outbox_api_messages_path, :headers => user3_auth
-      assert_response :success
-      assert_equal "application/xml", response.media_type
-      assert_select "message", :count => 0
-    end
-
-    def test_paged_list_messages_asc
-      recipient = create(:user)
-      recipient_auth = bearer_authorization_header(recipient, :scopes => %w[consume_messages])
-
-      sender = create(:user)
-
-      create_list(:message, 100, :unread, :sender => sender, :recipient => recipient)
-
-      msgs_read = {}
-      params = { :order => "oldest", :limit => 20 }
-      10.times do
-        get inbox_api_messages_path(:format => "json"),
-            :params => params,
-            :headers => recipient_auth
-        assert_response :success
-        assert_equal "application/json", response.media_type
-        js = ActiveSupport::JSON.decode(@response.body)
-        jsm = js["messages"]
-        assert_operator jsm.count, :<=, 20
-
-        break if jsm.nil? || jsm.count.zero?
-
-        assert_operator(jsm[0]["id"], :>=, params[:from_id]) unless params[:from_id].nil?
-        # ensure ascending order
-        (0..jsm.count - 1).each do |i|
-          assert_operator(jsm[i]["id"], :<, jsm[i + 1]["id"]) unless i == jsm.count - 1
-          msgs_read[jsm[i]["id"]] = jsm[i]
-        end
-        params[:from_id] = jsm[jsm.count - 1]["id"]
-      end
-      assert_equal 100, msgs_read.count
-    end
-
-    def test_paged_list_messages_desc
-      recipient = create(:user)
-      recipient_auth = bearer_authorization_header(recipient, :scopes => %w[consume_messages])
-
-      sender = create(:user)
-
-      create_list(:message, 100, :unread, :sender => sender, :recipient => recipient)
-
-      real_max_id = -1
-      msgs_read = {}
-      params = { :order => "newest", :limit => 20 }
-      10.times do
-        get inbox_api_messages_path(:format => "json"),
-            :params => params,
-            :headers => recipient_auth
-        assert_response :success
-        assert_equal "application/json", response.media_type
-        js = ActiveSupport::JSON.decode(@response.body)
-        jsm = js["messages"]
-        assert_operator jsm.count, :<=, 20
-
-        break if jsm.nil? || jsm.count.zero?
-
-        if params[:from_id].nil?
-          real_max_id = jsm[0]["id"]
-        else
-          assert_operator jsm[0]["id"], :<=, params[:from_id]
-        end
-        # ensure descending order
-        (0..jsm.count - 1).each do |i|
-          assert_operator(jsm[i]["id"], :>, jsm[i + 1]["id"]) unless i == jsm.count - 1
-          msgs_read[jsm[i]["id"]] = jsm[i]
-        end
-        params[:from_id] = jsm[jsm.count - 1]["id"]
-      end
-      assert_equal 100, msgs_read.count
-      assert_not_equal(-1, real_max_id)
-
-      # invoke without min_id/max_id parameters, verify that we get the last batch
-      get inbox_api_messages_path(:format => "json"), :params => { :limit => 20 }, :headers => recipient_auth
-      assert_response :success
-      assert_equal "application/json", response.media_type
-      js = ActiveSupport::JSON.decode(@response.body)
-      jsm = js["messages"]
-      assert_not_nil jsm
-      assert_equal real_max_id, jsm[0]["id"]
-    end
   end
 end