-
Notifications
You must be signed in to change notification settings - Fork 19
Chore: Increase Test Coverage #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
491c2e6
add coveralls config
adamzaninovich eb4f677
Update alice_test.exs
adamzaninovich 5e8dfa4
update router tests to use the new testing tools
adamzaninovich ad67509
update help handler tests
adamzaninovich be4f9a7
make deplayed_reply work with tests
adamzaninovich bcf33b3
Rewrite ConnTest to use new testing tools
adamzaninovich e8b0608
updates fake_conn to be able to take a state
adamzaninovich 31c092c
adds tests to utils test
adamzaninovich 992bf34
test delayed_reply in the helpers test
adamzaninovich 6f86f48
update earmuffs test with new testing tools
adamzaninovich f8bd368
adds complete test for HandlersCase
adamzaninovich abaede2
removes some whitespace
adamzaninovich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "skip_files": [ | ||
| "lib/alice.ex", | ||
| "lib/alice/state_backends/redix_pool.ex" | ||
| ], | ||
| "coverage_options": { | ||
| "minimum_coverage": 77, | ||
| "treat_no_relevant_lines_as_covered": true | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -11,14 +11,17 @@ defmodule Alice.Handlers.Help do | |
|
|
||
| @doc "`help` - lists all known handlers" | ||
| def general_help(conn) do | ||
| [ | ||
| "_Here are all the handlers I know about…_", | ||
| handler_list(), | ||
| "_Get info about a specific handler with_ `@alice help <handler name>`", | ||
| "_Get info about all handlers with_ `@alice help all`", | ||
| "_Feedback on Alice is appreciated. Please submit an issue at https://github.com/alice-bot/alice/issues _" | ||
| ] | ||
| |> Enum.join("\n\n") | ||
| """ | ||
| _Here are all the handlers I know about…_ | ||
|
|
||
| #{handler_list()} | ||
|
|
||
| _Get info about a specific handler with_ `@alice help <handler name>` | ||
|
|
||
| _Get info about all handlers with_ `@alice help all` | ||
|
|
||
| _Feedback on Alice is appreciated. Please submit an issue at https://github.com/alice-bot/alice/issues _ | ||
| """ | ||
| |> reply(conn) | ||
| end | ||
|
|
||
|
|
@@ -139,10 +142,6 @@ defmodule Alice.Handlers.Help do | |
| {title, name, :hidden} | ||
| end | ||
|
|
||
| defp parse_function_doc({_function, _anno, _sig, _doc_content, _meta}, title) do | ||
| {title, nil, :hidden} | ||
| end | ||
|
|
||
|
Comment on lines
-142
to
-145
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure we don't need this fall-through version of the function |
||
| defp format_route({_, _, :hidden}), do: nil | ||
|
|
||
| defp format_route({title, name, text}) do | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,87 +1,86 @@ | ||
| defmodule Alice.EarmuffsTest do | ||
| use ExUnit.Case, async: true | ||
| use Alice.HandlersCase, handlers: Alice.Earmuffs | ||
|
|
||
| alias Alice.Conn | ||
| alias Alice.Earmuffs | ||
|
|
||
| @user_id "some user id" | ||
| @channel_id "some channel id" | ||
| @namespace {Earmuffs, :earmuffs} | ||
|
|
||
| def conn_with_state(state \\ %{}) do | ||
| Conn.make(%{user: @user_id, channel: @channel_id}, %{}, state) | ||
| end | ||
|
|
||
| test "block adds the user and channel to the blocklist" do | ||
| %Conn{state: state} = %{} |> conn_with_state |> Earmuffs.block() | ||
| assert %{{Earmuffs, :earmuffs} => %{@user_id => [@channel_id]}} = state | ||
| end | ||
|
|
||
| test "block block user and channel when user already has a channel" do | ||
| test "it responds to earmuffs command and sets the block" do | ||
| conn = | ||
| %{{Earmuffs, :earmuffs} => %{@user_id => ["another"]}} | ||
| |> conn_with_state | ||
| Conn.make( | ||
| %{text: "<@alice> earmuffs", channel: @channel_id, user: @user_id}, | ||
| %{users: %{@user_id => %{id: @user_id, name: "fake_user"}}, me: %{id: :alice}} | ||
| ) | ||
|
|
||
| conn = send_message(conn) | ||
|
|
||
| assert first_reply() == "<@#{@user_id}> :mute:" | ||
| assert Earmuffs.blocked?(conn) | ||
| end | ||
|
|
||
| test "block adds the user and channel to the blocklist" do | ||
| conn = conn_with_state(%{}) | ||
| %Conn{state: state} = Earmuffs.block(conn) | ||
|
|
||
| %{{Earmuffs, :earmuffs} => %{@user_id => [@channel_id, "another"]}} = | ||
| state | ||
| |> assert | ||
| assert %{@namespace => %{@user_id => [@channel_id]}} = state | ||
| end | ||
|
|
||
| test "block block user and channel when another user has a channel" do | ||
| conn = | ||
| %{{Earmuffs, :earmuffs} => %{"user" => ["channel"]}} | ||
| |> conn_with_state | ||
| test "block still blocks a user and channel when user already has a channel" do | ||
| conn = conn_with_state(%{@namespace => %{@user_id => ["another"]}}) | ||
| %Conn{state: state} = Earmuffs.block(conn) | ||
|
|
||
| assert %{@namespace => %{@user_id => [@channel_id, "another"]}} = state | ||
| end | ||
|
|
||
| test "block still blocks a user and channel when another user has a channel" do | ||
| conn = conn_with_state(%{@namespace => %{"user" => ["channel"]}}) | ||
| %Conn{state: state} = Earmuffs.block(conn) | ||
|
|
||
| %{{Earmuffs, :earmuffs} => %{"user" => ["channel"], @user_id => [@channel_id]}} = | ||
| state | ||
| |> assert | ||
| assert %{@namespace => %{"user" => ["channel"], @user_id => [@channel_id]}} = state | ||
| end | ||
|
|
||
| test "blocked? is false when nothing is blocked" do | ||
| %{} | ||
| |> conn_with_state | ||
| |> Earmuffs.blocked?() | ||
| |> refute | ||
| conn = conn_with_state(%{}) | ||
|
|
||
| refute Earmuffs.blocked?(conn) | ||
| end | ||
|
|
||
| test "blocked? is true when the conn is blocked for this channel and user" do | ||
| %{{Earmuffs, :earmuffs} => %{@user_id => ["another channel", @channel_id]}} | ||
| |> conn_with_state | ||
| |> Earmuffs.blocked?() | ||
| |> assert | ||
| conn = conn_with_state(%{@namespace => %{@user_id => ["another channel", @channel_id]}}) | ||
|
|
||
| assert Earmuffs.blocked?(conn) | ||
| end | ||
|
|
||
| test "blocked? is false when channel is blocked but not user" do | ||
| %{{Earmuffs, :earmuffs} => %{"another user" => [@channel_id]}} | ||
| |> conn_with_state | ||
| |> Earmuffs.blocked?() | ||
| |> refute | ||
| conn = conn_with_state(%{@namespace => %{"another user" => [@channel_id]}}) | ||
|
|
||
| refute Earmuffs.blocked?(conn) | ||
| end | ||
|
|
||
| test "blocked? is false when user is blocked but not channel" do | ||
| %{{Earmuffs, :earmuffs} => %{@user_id => ["another channel"]}} | ||
| |> conn_with_state | ||
| |> Earmuffs.blocked?() | ||
| |> refute | ||
| conn = conn_with_state(%{@namespace => %{@user_id => ["another channel"]}}) | ||
|
|
||
| refute Earmuffs.blocked?(conn) | ||
| end | ||
|
|
||
| test "unblock adds an empty channel list for the user when state is empty" do | ||
| unblocked_conn = | ||
| %{} | ||
| |> conn_with_state | ||
| |> Earmuffs.unblock() | ||
| conn = conn_with_state(%{}) | ||
| conn = Earmuffs.unblock(conn) | ||
|
|
||
| assert unblocked_conn.state == %{{Earmuffs, :earmuffs} => %{@user_id => []}} | ||
| assert conn.state == %{@namespace => %{@user_id => []}} | ||
| end | ||
|
|
||
| test "unblock removes a block for a user and channel" do | ||
| conn = | ||
| %{{Earmuffs, :earmuffs} => %{@user_id => [@channel_id, "other"]}} | ||
| |> conn_with_state | ||
| |> Earmuffs.unblock() | ||
| conn = conn_with_state(%{@namespace => %{@user_id => [@channel_id, "other"]}}) | ||
| conn = Earmuffs.unblock(conn) | ||
|
|
||
| assert conn.state == %{{Earmuffs, :earmuffs} => %{@user_id => ["other"]}} | ||
| assert conn.state == %{@namespace => %{@user_id => ["other"]}} | ||
| end | ||
| end |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These files are both Supervisors. There is actually a test file for
lib/alice.exthat tests the one function that isn't part of the Supervisor spec.