Welcome to mirror list, hosted at ThFree Co, Russian Federation.

check_birthday_spec.rb « workers « spec - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f8573b79a4431cba4c806d57a1f784ae2fc2d78 (plain)
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
# frozen_string_literal: true

describe Workers::CheckBirthday do
  let(:birthday_profile) { bob.profile }
  let(:contact1) { alice.contact_for(bob.person) }
  let(:contact2) { eve.contact_for(bob.person) }

  before do
    birthday_profile.update(birthday: Time.zone.now)
    allow(Notifications::ContactsBirthday).to receive(:notify)
  end

  it "calls notify method for the birthday person's contacts" do
    Workers::CheckBirthday.new.perform
    expect(Notifications::ContactsBirthday).to have_received(:notify).with(contact1, [])
    expect(Notifications::ContactsBirthday).to have_received(:notify).with(contact2, [])
  end

  it "does nothing if the birthday does not exist" do
    birthday_profile.update(birthday: nil)
    Workers::CheckBirthday.new.perform
    expect(Notifications::ContactsBirthday).not_to have_received(:notify).with(contact1, [])
    expect(Notifications::ContactsBirthday).not_to have_received(:notify).with(contact2, [])
  end

  it "does nothing if the person's birthday is not today" do
    birthday_profile.update(birthday: Time.zone.now - 1.day)
    Workers::CheckBirthday.new.perform
    expect(Notifications::ContactsBirthday).not_to have_received(:notify).with(contact1, [])
    expect(Notifications::ContactsBirthday).not_to have_received(:notify).with(contact2, [])
  end

  it "does not call notify method if a person is not a contact of the birthday person" do
    contact2.destroy
    Workers::CheckBirthday.new.perform
    expect(Notifications::ContactsBirthday).to have_received(:notify).with(contact1, [])
    expect(Notifications::ContactsBirthday).not_to have_received(:notify).with(contact2, [])
  end

  it "does not call notify method if a contact user is not :receiving from the birthday person" do
    contact2.update(receiving: false)
    Workers::CheckBirthday.new.perform
    expect(Notifications::ContactsBirthday).to have_received(:notify).with(contact1, [])
    expect(Notifications::ContactsBirthday).not_to have_received(:notify).with(contact2, [])
  end

  it "does not call notify method if a birthday person is not :sharing with the contact user" do
    contact2.update(sharing: false)
    Workers::CheckBirthday.new.perform
    expect(Notifications::ContactsBirthday).to have_received(:notify).with(contact1, [])
    expect(Notifications::ContactsBirthday).not_to have_received(:notify).with(contact2, [])
  end
end