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 | |
parent | 89eeec72d3251b8e35fd501e6466ea7be0660db0 (diff) |
Create birthday notification and mailer
closes #7624
fixes #1649
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/notifications_controller_spec.rb | 1 | ||||
-rw-r--r-- | spec/mailers/notifier_spec.rb | 17 | ||||
-rw-r--r-- | spec/models/notifications/contacts_birthday_spec.rb | 23 | ||||
-rw-r--r-- | spec/workers/check_birthday_spec.rb | 56 | ||||
-rw-r--r-- | spec/workers/mail/contacts_birthday_spec.rb | 13 |
5 files changed, 110 insertions, 0 deletions
diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index 1788182a3..21b812885 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -81,6 +81,7 @@ describe NotificationsController, :type => :controller do expect(response_json["unread_count_by_type"]).to eq( "also_commented" => 1, "comment_on_post" => 0, + "contacts_birthday" => 0, "liked" => 0, "mentioned" => 0, "mentioned_in_comment" => 0, diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index ea8ad573e..002014b05 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -79,6 +79,23 @@ describe Notifier, type: :mailer do end end + describe ".contacts_birthday" do + let(:contact) { alice.contact_for(bob.person) } + let(:mail) { Notifier.send_notification("contacts_birthday", alice.id, nil, bob.person.id) } + + it "TO: goes to the right person" do + expect(mail.to).to eq([alice.email]) + end + + it "SUBJECT: has the name of birthday person in the subject" do + expect(mail.subject).to include(bob.person.name) + end + + it "has a link to the birthday profile in the body" do + expect(mail.body.encoded).to include(user_profile_url(bob.person.username)) + end + end + describe ".mentioned" do before do @user = alice diff --git a/spec/models/notifications/contacts_birthday_spec.rb b/spec/models/notifications/contacts_birthday_spec.rb new file mode 100644 index 000000000..8ca85266c --- /dev/null +++ b/spec/models/notifications/contacts_birthday_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +describe Notifications::ContactsBirthday, type: :model do + let(:contact) { alice.contact_for(bob.person) } + let(:recipient) { alice } + let(:actor) { bob.person } + let(:birthday_notification) { Notifications::ContactsBirthday.new(recipient: alice) } + + describe ".notify" do + it "calls create_notification with contact owner as a recipient" do + expect(Notifications::ContactsBirthday).to receive(:create_notification).with(recipient, actor, actor) + + Notifications::ContactsBirthday.notify(contact, []) + end + + it "sends an email to the contacts owner person" do + allow(Notifications::ContactsBirthday).to receive(:create_notification).and_return(birthday_notification) + expect(alice).to receive(:mail).with(Workers::Mail::ContactsBirthday, recipient.id, actor.id, actor.id) + + Notifications::ContactsBirthday.notify(contact, []) + end + end +end 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 |