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: 1f026ab61b10f8b88a6581d3495490d94f3d96b7 (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
54
55
56
# 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
    Timecop.freeze(Time.zone.local(1999, 9, 9))
    birthday_profile.update(birthday: "1990-09-09")
    allow(Notifications::ContactsBirthday).to receive(:notify)
  end

  after do
    Timecop.return
  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)
  end

  it "does nothing if the person's birthday is not today" do
    birthday_profile.update(birthday: "1988-04-15")
    Workers::CheckBirthday.new.perform
    expect(Notifications::ContactsBirthday).not_to have_received(:notify)
  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