aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailbox/test/unit/inbound_email/incineration_test.rb
blob: 54488349fda0a85fc7fd48588d9016f9f0374848 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true

require_relative "../../test_helper"

class ActionMailbox::InboundEmail::IncinerationTest < ActiveSupport::TestCase
  test "incinerating 30 days after delivery" do
    freeze_time

    assert_enqueued_with job: ActionMailbox::IncinerationJob, at: 30.days.from_now do
      create_inbound_email_from_fixture("welcome.eml").delivered!
    end

    travel 30.days

    assert_difference -> { ActionMailbox::InboundEmail.count }, -1 do
      perform_enqueued_jobs only: ActionMailbox::IncinerationJob
    end
  end

  test "incinerating 30 days after bounce" do
    freeze_time

    assert_enqueued_with job: ActionMailbox::IncinerationJob, at: 30.days.from_now do
      create_inbound_email_from_fixture("welcome.eml").bounced!
    end

    travel 30.days

    assert_difference -> { ActionMailbox::InboundEmail.count }, -1 do
      perform_enqueued_jobs only: ActionMailbox::IncinerationJob
    end
  end

  test "incinerating 30 days after failure" do
    freeze_time

    assert_enqueued_with job: ActionMailbox::IncinerationJob, at: 30.days.from_now do
      create_inbound_email_from_fixture("welcome.eml").failed!
    end

    travel 30.days

    assert_difference -> { ActionMailbox::InboundEmail.count }, -1 do
      perform_enqueued_jobs only: ActionMailbox::IncinerationJob
    end
  end

  test "skipping incineration" do
    original, ActionMailbox.incinerate = ActionMailbox.incinerate, false

    assert_no_enqueued_jobs only: ActionMailbox::IncinerationJob do
      create_inbound_email_from_fixture("welcome.eml").delivered!
    end
  ensure
    ActionMailbox.incinerate = original
  end
end