-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from azevedoguigo/development
v0.2.0
- Loading branch information
Showing
7 changed files
with
126 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule GeckoApi.Tasks.Delete do | ||
@moduledoc """ | ||
Provides a function call/1 to delete task by id. | ||
""" | ||
alias GeckoApi.Tasks | ||
alias GeckoApi.Repo | ||
|
||
def call(task_id) do | ||
case Tasks.get_task(task_id) do | ||
{:error, error_data} -> {:error, error_data} | ||
{:ok, task} -> Repo.delete(task) | ||
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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
defmodule GeckoApi.Tasks.DeleteTest do | ||
use GeckoApi.DataCase | ||
|
||
alias GeckoApi.Users | ||
alias GeckoApi.Tasks | ||
alias GeckoApi.Tasks.{Task, Delete} | ||
|
||
setup do | ||
user_params = %{ | ||
name: "Lewis Hamilton", | ||
email: "[email protected]", | ||
password: "lewisinferrari" | ||
} | ||
|
||
{:ok, user} = Users.create_user(user_params) | ||
|
||
{:ok, user: user} | ||
end | ||
|
||
describe "call/1" do | ||
test "Delete a task when the id is valid and belongs to an existing task.", %{user: user} do | ||
user_id = user.id | ||
task_params = %{ | ||
title: "Create geck api unit tests.", | ||
description: "Unit tests are useful to ensure scalability and security in API development.", | ||
user_id: user_id | ||
} | ||
{:ok, created_task} = Tasks.create_task(task_params) | ||
|
||
{:ok, task} = Delete.call(created_task.id) | ||
|
||
assert %Task{ | ||
title: "Create geck api unit tests.", | ||
description: "Unit tests are useful to ensure scalability and security in API development.", | ||
user_id: ^user_id | ||
} = task | ||
end | ||
|
||
test "Returns a tuple with :error and error data if the id is invalid." do | ||
{:error, error_data} = Delete.call("invalid_id") | ||
|
||
assert %{message: "Invalid task ID!", status_code: :bad_request} == error_data | ||
end | ||
|
||
test "Returns a tuple with :error and error data if the id does not belong to a task." do | ||
{:error, error_data} = Delete.call(Ecto.UUID.generate()) | ||
|
||
assert %{message: "Task does not exists!", status_code: :not_found} == error_data | ||
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