diff options
author | Rete2 <rete@posteo.de> | 2017-09-05 17:44:40 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2017-12-18 06:34:35 +0300 |
commit | fc33a2ac5dd494c8d1f59aa18baea1549b6a4d3d (patch) | |
tree | 030bacfaa0162bd29c5deae7475be9f6722cef0d /spec/workers | |
parent | 89eeec72d3251b8e35fd501e6466ea7be0660db0 (diff) |
Create birthday notification and mailer
closes #7624
fixes #1649
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/check_birthday_spec.rb | 56 | ||||
-rw-r--r-- | spec/workers/mail/contacts_birthday_spec.rb | 13 |
2 files changed, 69 insertions, 0 deletions
diff --git a/spec/workers/check_birthday_spec.rb b/spec/workers/check_birthday_spec.rb new file mode 100644 index 000000000..594be68f0 --- /dev/null +++ b/spec/workers/check_birthday_spec.rb @@ -0,0 +1,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_attributes(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_attributes(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_attributes(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_attributes(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_attributes(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 diff --git a/spec/workers/mail/contacts_birthday_spec.rb b/spec/workers/mail/contacts_birthday_spec.rb new file mode 100644 index 000000000..83867eb42 --- /dev/null +++ b/spec/workers/mail/contacts_birthday_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +describe Workers::Mail::ContactsBirthday do + describe "#perform" do + it "should call .deliver on the notifier object" do + mail_double = double + expect(mail_double).to receive(:deliver_now) + expect(Notifier).to receive(:send_notification) + .with("contacts_birthday", alice.id).and_return(mail_double) + Workers::Mail::ContactsBirthday.new.perform(alice.id) + end + end +end |