-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat handling on the test-groups page (#2288)
* fix: Improve error handling on the test-groups page * feat: Add ability to delete a test group * feat: Trim leading and trailing whitespace from test group names
- Loading branch information
1 parent
312ac9e
commit 082fee2
Showing
14 changed files
with
204 additions
and
33 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
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
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 |
---|---|---|
|
@@ -6,13 +6,44 @@ defmodule Skate.Settings.TestGroupTest do | |
|
||
describe "create/1" do | ||
test "creates the test group" do | ||
assert %TestGroup{name: "group name"} = TestGroup.create("group name") | ||
assert {:ok, %TestGroup{name: "group name"}} = TestGroup.create("group name") | ||
|
||
assert [%TestGroup{name: "group name"}] = TestGroup.get_all() | ||
end | ||
|
||
test "disallows blank group names" do | ||
assert {:error, changeset} = TestGroup.create("") | ||
|
||
assert %{errors: [name: {"can't be blank", _}]} = changeset | ||
assert Enum.empty?(TestGroup.get_all()) | ||
end | ||
|
||
test "returns an error if the test group has a duplicate name" do | ||
TestGroup.create("duplicate name") | ||
assert {:error, changeset} = TestGroup.create("duplicate name") | ||
|
||
assert %{errors: [name: {"has already been taken", _}]} = changeset | ||
assert Enum.count(TestGroup.get_all()) == 1 | ||
end | ||
|
||
test "strips leading and trailing spaces" do | ||
assert {:ok, %TestGroup{name: "lost in space"}} = TestGroup.create(" lost in space ") | ||
|
||
assert [%TestGroup{name: "lost in space"}] = TestGroup.get_all() | ||
end | ||
|
||
test "treats names as duplicates if they differ by leading and trailing spaces" do | ||
TestGroup.create("lost in space ") | ||
assert {:error, changeset} = TestGroup.create(" lost in space") | ||
|
||
assert %{errors: [name: {"has already been taken", _}]} = changeset | ||
assert Enum.count(TestGroup.get_all()) == 1 | ||
end | ||
end | ||
|
||
describe "get/1" do | ||
test "retrieves the test group" do | ||
test_group = TestGroup.create("group name") | ||
{:ok, test_group} = TestGroup.create("group name") | ||
assert %TestGroup{name: "group name"} = TestGroup.get(test_group.id) | ||
end | ||
|
||
|
@@ -23,8 +54,8 @@ defmodule Skate.Settings.TestGroupTest do | |
|
||
describe "get_all/1" do | ||
test "gets all test groups" do | ||
group1 = TestGroup.create("group 1") | ||
group2 = TestGroup.create("group 2") | ||
{:ok, group1} = TestGroup.create("group 1") | ||
{:ok, group2} = TestGroup.create("group 2") | ||
|
||
all_groups = TestGroup.get_all() | ||
|
||
|
@@ -37,15 +68,15 @@ defmodule Skate.Settings.TestGroupTest do | |
|
||
describe "update/1" do | ||
test "updates name" do | ||
test_group = TestGroup.create("name 1") | ||
{:ok, test_group} = TestGroup.create("name 1") | ||
|
||
new_test_group = TestGroup.update(%{test_group | name: "name 2"}) | ||
|
||
assert new_test_group.name == "name 2" | ||
end | ||
|
||
test "updates users" do | ||
test_group = TestGroup.create("name") | ||
{:ok, test_group} = TestGroup.create("name") | ||
user1 = User.upsert("user1", "[email protected]") | ||
user2 = User.upsert("user2", "[email protected]") | ||
user3 = User.upsert("user3", "[email protected]") | ||
|
@@ -67,4 +98,14 @@ defmodule Skate.Settings.TestGroupTest do | |
assert user3 in users_update_2 | ||
end | ||
end | ||
|
||
describe "delete/1" do | ||
test "deletes a test group" do | ||
{:ok, test_group} = TestGroup.create("group to delete") | ||
|
||
TestGroup.delete(test_group.id) | ||
|
||
assert Enum.empty?(TestGroup.get_all()) | ||
end | ||
end | ||
end |
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 |
---|---|---|
|
@@ -123,8 +123,8 @@ defmodule Skate.Settings.UserTest do | |
test "returns true only if given is in test group" do | ||
user_1 = User.upsert(@username, @email) | ||
user_2 = User.upsert("otheruser", "[email protected]") | ||
target_test_group = TestGroup.create("target_test_group") | ||
other_test_group = TestGroup.create("other_test_group") | ||
{:ok, target_test_group} = TestGroup.create("target_test_group") | ||
{:ok, other_test_group} = TestGroup.create("other_test_group") | ||
|
||
target_test_group = TestGroup.update(%{target_test_group | users: [user_1, user_2]}) | ||
other_test_group = TestGroup.update(%{other_test_group | users: [user_2]}) | ||
|
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
Oops, something went wrong.