Skip to content

Commit

Permalink
Update status.text from "done" to :done (String -> Atom) #4 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Jul 9, 2022
1 parent b3c5950 commit fed171e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
1 change: 0 additions & 1 deletion lib/status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ defmodule Status do
"""
@type t :: %Status{code: integer(), desc: String.t(), text: atom()}
@enforce_keys [:code, :desc, :text]
@derive Jason.Encoder

defstruct [:code, :desc, :text]
end
35 changes: 25 additions & 10 deletions lib/statuses.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ defmodule Statuses do
desc: "An App, Item or Person can be active; this is the default state for an App",
text: :active
},
%Status{code: 4, desc: "Items marked as done are complete", text: "done"},
%Status{
code: 4,
desc: "Items marked as done are complete",
text: :done
},
%Status{
code: 5,
desc: "A flagged App, Item or Person requires admin attention",
Expand All @@ -48,7 +52,11 @@ defmodule Statuses do
desc: "An email that has been sent but not yet opened",
text: :sent
},
%Status{code: 9, desc: "When an email is opened by the recipient", text: :opened},
%Status{
code: 9,
desc: "When an email is opened by the recipient",
text: :opened
},
%Status{
code: 10,
desc: "Temporary email bounce e.g. because inbox is full",
Expand All @@ -59,7 +67,11 @@ defmodule Statuses do
desc: "Permanent email bounce e.g. when inbox doesn't exist",
text: :bounce_permanent
},
%Status{code: 200, desc: "successful HTTP request", text: :ok},
%Status{
code: 200,
desc: "successful HTTP request",
text: :ok
},
%Status{
code: 307,
desc: "the request should be repeated with another URI",
Expand All @@ -80,8 +92,16 @@ defmodule Statuses do
desc: "when authentication is required and has failed",
text: :unauthorized
},
%Status{code: 403, desc: "request forbidden", text: :forbidden},
%Status{code: 404, desc: "requested resource could not be found", text: :not_found},
%Status{
code: 403,
desc: "request forbidden",
text: :forbidden
},
%Status{
code: 404,
desc: "requested resource could not be found",
text: :not_found
},
%Status{
code: 429,
desc: "has sent too many requests in a given amount of time",
Expand All @@ -94,9 +114,4 @@ defmodule Statuses do
}
]
end

@doc """
Returns the list of statuses as json
"""
def statuses_to_json(), do: Jason.encode!(get_statuses())
end
3 changes: 0 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ defmodule Statuses.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
# Parse JSON file: github.com/michalmuskala/jason
{:jason, "~> 1.1"},

# Create docs for publishing Hex.docs: github.com/elixir-lang/ex_doc
{:ex_doc, "~> 0.28", only: :dev, runtime: false},

Expand Down
8 changes: 0 additions & 8 deletions test/statuses_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,4 @@ defmodule StatusesTest do

assert Enum.member?(list, sample)
end

test "status_to_json returns the list of statuses as json" do
json = Statuses.statuses_to_json()
json_statuses = Jason.decode!(json)
statuses = Statuses.get_statuses()

assert length(json_statuses) == length(statuses)
end
end

0 comments on commit fed171e

Please sign in to comment.