Skip to content

Commit

Permalink
test: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Mar 17, 2019
1 parent c81d370 commit 525537d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
20 changes: 10 additions & 10 deletions apps/cf/lib/actions/action_creator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ defmodule CF.Actions.ActionCreator do
video_id: statement.video_id,
statement_id: statement.id,
changes: %{
text: statement.text,
time: statement.time,
speaker_id: statement.speaker_id
"text" => statement.text,
"time" => statement.time,
"speaker_id" => statement.speaker_id
}
)
end
Expand All @@ -35,8 +35,8 @@ defmodule CF.Actions.ActionCreator do
:create,
speaker_id: speaker.id,
changes: %{
full_name: speaker.full_name,
title: speaker.title
"full_name" => speaker.full_name,
"title" => speaker.title
}
)
end
Expand All @@ -50,10 +50,10 @@ defmodule CF.Actions.ActionCreator do
statement_id: comment.statement_id,
comment_id: comment.id,
changes: %{
text: comment.text,
source: source_url,
statement_id: comment.statement_id,
reply_to_id: comment.reply_to_id
"text" => comment.text,
"source" => source_url,
"statement_id" => comment.statement_id,
"reply_to_id" => comment.reply_to_id
}
)
end
Expand All @@ -77,7 +77,7 @@ defmodule CF.Actions.ActionCreator do
:add,
video_id: video.id,
changes: %{
url: Video.build_url(video)
"url" => Video.build_url(video)
}
)
end
Expand Down
6 changes: 3 additions & 3 deletions apps/cf/lib/notifications/notification_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ defmodule CF.Notifications.NotificationBuilder do
## Examples
iex> action = %UserAction{id: 42, type: :create, entity: :comment}
iex> subscription = %Subscription{user_id: 100, reason: :is_author}
iex> action = %UserAction{id: 42, type: :create, entity: :statement}
iex> subscription = %Subscription{user_id: 100}
iex> NotificationBuilder.for_subscribed_action(action, subscription)
%{action_id: 42, type: :reply_to_comment, user_id: 100}
%{action_id: 42, type: :new_statement, user_id: 100}
"""
@spec for_subscribed_action(UserAction.t(), Subscription.t()) :: Notification.t()
def for_subscribed_action(action, subscription) when not is_nil(subscription) do
Expand Down
2 changes: 1 addition & 1 deletion apps/cf/lib/notifications/subscriptions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule CF.Notifications.Subscriptions do
nil ->
false

%{is_subscribed: is_subscribed} = a ->
%{is_subscribed: is_subscribed} ->
is_subscribed
end
end
Expand Down
12 changes: 6 additions & 6 deletions apps/cf/test/notifications/subscribtions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ defmodule CF.Notifications.SubscriptionsTest do
end

describe "unsubscribe" do
test "removes existing subscription on video" do
test "set subscription is_subscribe to false on video" do
video = insert(:video)
subscription = insert(:subscription, scope: :video, video: video)
Subscriptions.unsubscribe(subscription.user, subscription.video)
refute Repo.get(DB.Schema.Subscription, subscription.id)
refute Repo.get(DB.Schema.Subscription, subscription.id).is_subscribed
end

test "removes existing subscription on statement" do
test "set subscription is_subscribe to false on statement" do
statement = insert(:statement)

subscription =
insert(:subscription, scope: :statement, video: statement.video, statement: statement)

Subscriptions.unsubscribe(subscription.user, subscription.statement)
refute Repo.get(DB.Schema.Subscription, subscription.id)
refute Repo.get(DB.Schema.Subscription, subscription.id).is_subscribed
end

test "removes existing subscription on comment" do
test "set subscription is_subscribe to false on comment" do
comment = insert(:comment)

subscription =
Expand All @@ -65,7 +65,7 @@ defmodule CF.Notifications.SubscriptionsTest do
)

Subscriptions.unsubscribe(subscription.user, subscription.comment)
refute Repo.get(DB.Schema.Subscription, subscription.id)
refute Repo.get(DB.Schema.Subscription, subscription.id).is_subscribed
end
end

Expand Down
12 changes: 4 additions & 8 deletions apps/cf/test/notifications/subscriptions_matcher_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ defmodule CF.Notifications.SubscriptionsMatcherTest do
end

test "for new comment reply", %{entities: entities, subscriptions: subscriptions} do
reply = insert(:comment, reply_to: entities[:comment])
reply = insert(:comment, reply_to: entities[:comment], statement: entities[:statement])

# They should all be notified for new comment reply
action =
Expand All @@ -66,29 +66,25 @@ defmodule CF.Notifications.SubscriptionsMatcherTest do
user = insert(:user)
statement = insert(:statement, video: entities[:video])
action = Repo.insert!(ActionCreator.action_create(user.id, statement))
expected_subscriptions = Keyword.take(subscriptions, [:video, :statement])
expected_subscriptions = Keyword.take(subscriptions, [:video])

returned_subscriptions = SubscriptionsMatcher.match_action(action)
compare_subscriptions_ids(expected_subscriptions, returned_subscriptions)
end

test "for updated statement", %{entities: entities, subscriptions: subscriptions} do
user = insert(:user)
statement = insert(:statement, video: entities[:video])
changeset = Ecto.Changeset.change(statement, text: "Changed")
changeset = Ecto.Changeset.change(entities[:statement], text: "Changed")
action = Repo.insert!(ActionCreator.action_update(user.id, changeset))
expected_subscriptions = Keyword.take(subscriptions, [:video, :statement])

returned_subscriptions = SubscriptionsMatcher.match_action(action)
compare_subscriptions_ids(expected_subscriptions, returned_subscriptions)
end

test "for removed statement", %{entities: entities, subscriptions: subscriptions} do
user = insert(:user)
statement = insert(:statement, video: entities[:video])
action = Repo.insert!(ActionCreator.action_remove(user.id, statement))
action = Repo.insert!(ActionCreator.action_remove(user.id, entities[:statement]))
expected_subscriptions = Keyword.take(subscriptions, [:video, :statement])

returned_subscriptions = SubscriptionsMatcher.match_action(action)
compare_subscriptions_ids(expected_subscriptions, returned_subscriptions)
end
Expand Down

0 comments on commit 525537d

Please sign in to comment.