Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API: Don't return notifications target unless it's a post
- Loading branch information
Showing
4 changed files
with
39 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
describe NotificationPresenter do | ||
before do | ||
@post = FactoryGirl.create(:status_message) | ||
@notification = FactoryGirl.create(:notification, recipient: alice, target: @post) | ||
end | ||
|
||
it "makes json with target when requested" do | ||
json = NotificationPresenter.new(@notification).as_api_json(true) | ||
expect(json[:guid]).to eq(@notification.guid) | ||
it "makes json with target" do | ||
post = FactoryGirl.create(:status_message) | ||
notification = FactoryGirl.create(:notification, recipient: alice, target: post) | ||
json = NotificationPresenter.new(notification).as_api_json | ||
expect(json[:guid]).to eq(notification.guid) | ||
expect(json[:type]).to eq("also_commented") | ||
expect(json[:read]).to be_falsey | ||
expect(json[:created_at]).to eq(@notification.created_at) | ||
expect(json[:target][:guid]).to eq(@post.guid) | ||
expect(json[:created_at]).to eq(notification.created_at) | ||
expect(json[:target][:guid]).to eq(post.guid) | ||
expect(json[:event_creators].length).to eq(1) | ||
end | ||
|
||
it "makes json with without target" do | ||
json = NotificationPresenter.new(@notification).as_api_json(false) | ||
expect(json.has_key?(:target)).to be_falsey | ||
end | ||
|
||
it "Makes target on mentioned" do | ||
it "returns target on mentioned" do | ||
mentioned_post = FactoryGirl.create(:status_message_in_aspect, author: alice.person, text: text_mentioning(bob)) | ||
Notifications::MentionedInPost.notify(mentioned_post, [bob.id]) | ||
notification = Notifications::MentionedInPost.last | ||
json = NotificationPresenter.new(notification).as_api_json(true) | ||
json = NotificationPresenter.new(notification).as_api_json | ||
expect(json[:target][:guid]).to eq(mentioned_post.guid) | ||
end | ||
|
||
it "returns target on also_commented" do | ||
post = FactoryGirl.create(:status_message) | ||
bob.comment!(post, "cool") | ||
comment2 = FactoryGirl.create(:comment, post: post) | ||
Notifications::AlsoCommented.notify(comment2, []) | ||
notification = Notifications::AlsoCommented.last | ||
json = NotificationPresenter.new(notification).as_api_json | ||
expect(json[:target][:guid]).to eq(post.guid) | ||
end | ||
|
||
it "returns no target on started_sharing" do | ||
contact = FactoryGirl.create(:contact) | ||
Notifications::StartedSharing.notify(contact, [bob.id]) | ||
notification = Notifications::StartedSharing.last | ||
json = NotificationPresenter.new(notification).as_api_json | ||
expect(json[:target]).to be_nil | ||
end | ||
|
||
it "returns no target on contacts_birthday" do | ||
contact = FactoryGirl.create(:contact) | ||
Notifications::ContactsBirthday.notify(contact, [bob.id]) | ||
notification = Notifications::ContactsBirthday.last | ||
json = NotificationPresenter.new(notification).as_api_json | ||
expect(json[:target]).to be_nil | ||
end | ||
end |