mirror of
https://github.com/edgurgel/httparrot
synced 2025-04-06 00:32:34 -04:00
fix, request store test and missing doc
This commit is contained in:
parent
1e3e3ffb76
commit
cabc426c67
7 changed files with 31 additions and 7 deletions
|
@ -3,11 +3,11 @@ notifications:
|
||||||
recipients:
|
recipients:
|
||||||
- eduardo@gurgel.me
|
- eduardo@gurgel.me
|
||||||
elixir:
|
elixir:
|
||||||
- 1.2.4
|
- 1.2.6
|
||||||
- 1.3.0
|
- 1.3.0
|
||||||
otp_release:
|
otp_release:
|
||||||
- 18.0
|
- 18.0
|
||||||
- 18.1
|
- 18.1
|
||||||
- 19.0
|
- 19.0
|
||||||
sudo: false
|
sudo: false
|
||||||
script: mix test --no-start
|
script: mix test
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
defmodule HTTParrot.RequestStore do
|
defmodule HTTParrot.RequestStore do
|
||||||
|
@moduledoc """
|
||||||
|
Used to store and retrived requests
|
||||||
|
"""
|
||||||
|
@doc """
|
||||||
|
Store the requests to the key
|
||||||
|
"""
|
||||||
def store(key, info) do
|
def store(key, info) do
|
||||||
map = retrieve(key) ++ [info]
|
map = retrieve(key) ++ [info]
|
||||||
ConCache.put(:requests_registry, key, map)
|
ConCache.put(:requests_registry, key, map)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Get the saved request using the key
|
||||||
|
"""
|
||||||
def retrieve(key) do
|
def retrieve(key) do
|
||||||
entry = ConCache.get(:requests_registry, key)
|
entry = ConCache.get(:requests_registry, key)
|
||||||
case entry do
|
case entry do
|
||||||
|
@ -14,6 +22,9 @@ defmodule HTTParrot.RequestStore do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Clear the saved data on the coresponding key
|
||||||
|
"""
|
||||||
def clear(key) do
|
def clear(key) do
|
||||||
ConCache.delete(:requests_registry, key)
|
ConCache.delete(:requests_registry, key)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
defmodule HTTParrot.RetrieveRequestHandler do
|
defmodule HTTParrot.RetrieveRequestHandler do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Returns GET data.
|
Retreive saved request and clear the conresponding :id
|
||||||
"""
|
"""
|
||||||
alias HTTParrot.GeneralRequestInfo
|
alias HTTParrot.GeneralRequestInfo
|
||||||
use HTTParrot.Cowboy, methods: ~w(GET POST PUT HEAD OPTIONS)
|
use HTTParrot.Cowboy, methods: ~w(GET POST PUT HEAD OPTIONS)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
defmodule HTTParrot.StoreRequestHandler do
|
defmodule HTTParrot.StoreRequestHandler do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Returns GET data.
|
Store the sended request with the :id
|
||||||
"""
|
"""
|
||||||
alias HTTParrot.GeneralRequestInfo
|
alias HTTParrot.GeneralRequestInfo
|
||||||
use HTTParrot.Cowboy, methods: ~w(GET POST PUT HEAD OPTIONS)
|
use HTTParrot.Cowboy, methods: ~w(GET POST PUT HEAD OPTIONS)
|
||||||
|
|
12
test/request_store_test.exs
Normal file
12
test/request_store_test.exs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
defmodule HTTParrot.RequestStoreTest do
|
||||||
|
alias HTTParrot.RequestStore
|
||||||
|
use ExUnit.Case
|
||||||
|
test "save, retrieve, clear" do
|
||||||
|
request = %{req: 1}
|
||||||
|
RequestStore.clear(:test)
|
||||||
|
RequestStore.store(:test, request)
|
||||||
|
assert RequestStore.retrieve(:test) == [request]
|
||||||
|
RequestStore.clear(:test)
|
||||||
|
assert RequestStore.retrieve(:test) == []
|
||||||
|
end
|
||||||
|
end
|
|
@ -5,13 +5,13 @@ defmodule HTTParrot.RetrieveRequestHandlerTests do
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
HTTParrot.RequestStore.clear(:test)
|
HTTParrot.RequestStore.clear(:test)
|
||||||
|
on_exit fn -> unload end
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns saved requests" do
|
test "returns saved requests" do
|
||||||
expect(JSX, :encode!, [{[:req1], :json}])
|
|
||||||
expect(:cowboy_req, :binding, [:key, :req1], {:test, :req1})
|
expect(:cowboy_req, :binding, [:key, :req1], {:test, :req1})
|
||||||
HTTParrot.RequestStore.store(:test, :req1)
|
HTTParrot.RequestStore.store(:test, :req1)
|
||||||
assert retrieve_stored(:req1, :state) == {:json, :req1, :state}
|
assert retrieve_stored(:req1, :state) == {"[\"req1\"]", :req1, :state}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,7 @@ defmodule HTTParrot.StoreRequestHandlerTests do
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
HTTParrot.RequestStore.clear(:test)
|
HTTParrot.RequestStore.clear(:test)
|
||||||
|
on_exit fn -> unload end
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue