cirandas.net

ref: master

test/unit/activity_notifications_test.rb


 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require_relative "../test_helper"

class ActivityNotificationsTest < ActiveSupport::TestCase

  def setup
    @follower = create_user.person
    @person = create_user.person
    @profile = fast_create(Community)

    @people_circle = fast_create(Circle, person_id: @follower.id, profile_type: 'Person', name: 'people')
    @profiles_circle = fast_create(Circle, person_id: @follower.id, profile_type: 'Community', name: 'profiles')
  end

  should 'create notifications for followers of the acitivty owner and display properly' do
    @follower.follow(@person, @people_circle)
    process_delayed_job_queue

    assert_difference '@follower.tracked_notifications.count' do
      Scrap.create(sender_id: @person.id, receiver_id: @profile.id, content: 'hello')
      process_delayed_job_queue
    end

    notification = @follower.tracked_notifications.last

    Person.any_instance.stubs(:wall_access).returns(AccessLevels::LEVELS[:users])
    refute ActivityPresenter.for(notification).hidden_for?(@follower.user)

    Person.any_instance.stubs(:wall_access).returns(AccessLevels::LEVELS[:related])
    assert ActivityPresenter.for(notification).hidden_for?(@follower.user)
  end

  should 'create notifications for followers of the activity target and display properly' do
    @follower.follow(@profile, @profiles_circle)
    process_delayed_job_queue

    assert_difference '@follower.tracked_notifications.count' do
      Scrap.create(sender_id: @person.id, receiver_id: @profile.id, content: 'hello')
      process_delayed_job_queue
    end

    notification = @follower.tracked_notifications.last

    Community.any_instance.stubs(:wall_access).returns(AccessLevels::LEVELS[:users])
    refute ActivityPresenter.for(notification).hidden_for?(@follower.user)

    Community.any_instance.stubs(:wall_access).returns(AccessLevels::LEVELS[:related])
    assert ActivityPresenter.for(notification).hidden_for?(@follower.user)
  end

  should 'create notifications and not display if the target disabled the followers feature' do
    @follower.follow(@person, @people_circle)
    process_delayed_job_queue

    Person.any_instance.stubs(:allow_followers?).returns(false)
    assert_difference '@follower.tracked_notifications.count' do
      Scrap.create(sender_id: @person.id, receiver_id: @profile.id, content: 'hello')
      process_delayed_job_queue
    end

    notification = @follower.tracked_notifications.last
    assert ActivityPresenter.for(notification).hidden_for?(@follower.user)
  end

  should 'notify community members just once' do
    @profile.add_member(@follower)
    process_delayed_job_queue

    assert_difference '@follower.tracked_notifications.count', 1 do
      Scrap.create(sender_id: @person.id, receiver_id: @profile.id, content: 'hello')
      process_delayed_job_queue
    end
  end
end