aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/controller_test.rb
blob: 508e561244e7d553d1a849c6cdda948aa5d7d954 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require_relative '../test_helper'

class ActionMailbox::InboundEmailsControllerTest < ActionDispatch::IntegrationTest
  test "receiving a valid RFC 822 message" do
    assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do
      post_inbound_email "welcome.eml"
    end

    assert_response :created

    inbound_email = ActionMailbox::InboundEmail.last
    assert_equal file_fixture('../files/welcome.eml').read, inbound_email.raw_email.download
  end

  test "rejecting a message of an unsupported type" do
    assert_no_difference -> { ActionMailbox::InboundEmail.count } do
      post rails_inbound_emails_url, params: { message: fixture_file_upload('files/text.txt', 'text/plain') }
    end

    assert_response :unsupported_media_type
  end

  private
    def post_inbound_email(fixture_name)
      post rails_inbound_emails_url, params: { message: fixture_file_upload("files/#{fixture_name}", 'message/rfc822') }
    end
end