Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Virviil committed Jul 18, 2018
1 parent 6274d11 commit f3a3c10
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 184 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 3.0.0

### Changes

* Sugnificant remainings with bot structure and operation syncronisation.

### 2.0.2

[BUG] Change Bot's id from string to atom
Expand Down
Empty file removed extras/Provider.md
Empty file.
28 changes: 28 additions & 0 deletions extras/Providers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Providers

Provider is one of the main concepts of **Agala** framework. Different providers
*provide* different incoming event sources for your application.

All providers share same concepts of construction, but can have absolutely different
underline logic. One can create his own provider and plug it into Agala platform or share
between community. Or, you can use prepared provider in order to forget about
event source protocols and deal only with business logic of incoming events.

### Propvider structure

Basically, **provider package** can contain everything is needed to perform communication
with third-parties. It doesn't have any *upper border*, it is limited only by common sence.

At the same time, provider should follow some convention, and have some modules that implement
special behaviours:

* **Main module**: provider entry point. Should implement `Agala.Provider` behaviour.
* 1 to 3 retreiving modules:
* **Plug**, that follows `Agala.Bot.Plug` conventions
* **Poller**, that follows `Agala.Bot.Poller` conventions
* **Handler**. that follows `Agala.Bot.Handler` conventions
* Optional **Helper** or **API** modules, that provide mechanisms to send response back to provider.

### Provider implimentation

TODO
45 changes: 24 additions & 21 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
defmodule Agala.Mixfile do
defmodule Agala.MixProject do
use Mix.Project

def project do
[app: :agala,
version: "3.0.0",
elixir: "~> 1.6",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
description: description(),
elixirc_paths: elixirc_paths(Mix.env),
package: package(),
aliases: aliases(),
test_coverage: [tool: ExCoveralls],
preferred_cli_env: ["coveralls": :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test],
docs: docs(),
deps: deps()]
[
app: :agala,
version: "3.0.0",
elixir: "~> 1.6",
start_permanent: Mix.env() == :prod,
description: description(),
elixirc_paths: elixirc_paths(Mix.env()),
package: package(),
aliases: aliases(),
test_coverage: [tool: ExCoveralls],
preferred_cli_env: [
coveralls: :test,
"coveralls.detail": :test,
"coveralls.post": :test,
"coveralls.html": :test
],
docs: docs(),
deps: deps()
]
end

defp elixirc_paths(:test), do: ["lib", "test/support"]
Expand All @@ -35,15 +41,11 @@ defmodule Agala.Mixfile do

defp deps do
[
# Production dependencies
{:fastglobal, "~> 1.0"},
{:poolboy, "~> 1.5"},
{:plug, "~> 1.6"},
# Dev and test dependecies
{:ex_doc, "~> 0.18", only: :dev},
{:inch_ex,"~> 0.5", only: [:dev, :test, :docs]},
{:inch_ex, "~> 0.5", only: [:dev, :test, :docs]},
{:credo, "~> 0.8", only: [:dev, :test]},
{:excoveralls, "~> 0.8", only: :test}
{:excoveralls, "~> 0.9", only: :test}
]
end

Expand All @@ -60,9 +62,10 @@ defmodule Agala.Mixfile do
extras: [
"extras/Getting Started.md",
"extras/Bots.md",
"extras/Providers.md",
"extras/Usage.md",
"extras/Handlers.md",
"extras/General Configuration.md",
"extras/General Configuration.md"
]
]
end
Expand Down
24 changes: 5 additions & 19 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
%{
"amqp": {:hex, :amqp, "1.0.3", "06a6d909abc71d82b7c3133ca491899ca18fce857d0697dd060c29de1ef498d8", [:mix], [{:amqp_client, "~> 3.7.3", [hex: :amqp_client, repo: "hexpm", optional: false]}, {:goldrush, "~> 0.1.0", [hex: :goldrush, repo: "hexpm", optional: false]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: false]}, {:lager, "~> 3.5", [hex: :lager, repo: "hexpm", optional: false]}, {:rabbit_common, "~> 3.7.3", [hex: :rabbit_common, repo: "hexpm", optional: false]}, {:ranch, "~> 1.4", [hex: :ranch, repo: "hexpm", optional: false]}, {:ranch_proxy_protocol, "~> 1.4", [hex: :ranch_proxy_protocol, repo: "hexpm", optional: false]}, {:recon, "~> 2.3.2", [hex: :recon, repo: "hexpm", optional: false]}], "hexpm"},
"amqp_client": {:hex, :amqp_client, "3.7.6", "e85a5688edf75d2f786ea66303f5b0f2b196bc4c5f82495f738ce19570cf8748", [:make, :rebar3], [{:rabbit_common, "3.7.6", [hex: :rabbit_common, repo: "hexpm", optional: false]}], "hexpm"},
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"certifi": {:hex, :certifi, "2.3.1", "d0f424232390bf47d82da8478022301c561cf6445b5b5fb6a84d49a9e76d2639", [:rebar3], [{:parse_trans, "3.2.0", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"credo": {:hex, :credo, "0.9.3", "76fa3e9e497ab282e0cf64b98a624aa11da702854c52c82db1bf24e54ab7c97a", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.2.5", "4d21980d5d2862a2e13ec3c49ad9ad783ffc7ca5769cf6ff891a4553fbaae761", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.9.0", "dd597ccf119aa0be0c1c6681215df588596397833b8dd010fe3d1a48090f3119", [:mix], [{:hackney, ">= 0.12.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"},
"fastglobal": {:hex, :fastglobal, "1.0.0", "f3133a0cda8e9408aac7281ec579c4b4a8386ce0e99ca55f746b9f58192f455b", [:mix], [], "hexpm"},
"goldrush": {:hex, :goldrush, "0.1.9", "f06e5d5f1277da5c413e84d5a2924174182fb108dabb39d5ec548b27424cd106", [:rebar3], [], "hexpm"},
"hackney": {:hex, :hackney, "1.12.1", "8bf2d0e11e722e533903fe126e14d6e7e94d9b7983ced595b75f532e04b7fdc7", [:rebar3], [{:certifi, "2.3.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.1", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "5.1.1", "cbc3b2fa1645113267cc59c760bafa64b2ea0334635ef06dbac8801e42f7279c", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.18.4", "4406b8891cecf1352f49975c6d554e62e4341ceb41b9338949077b0d4a97b949", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.9.1", "14fd20fac51ab98d8e79615814cc9811888d2d7b28e85aa90ff2e30dcf3191d6", [:mix], [{:hackney, ">= 0.12.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"hackney": {:hex, :hackney, "1.13.0", "24edc8cd2b28e1c652593833862435c80661834f6c9344e84b6a2255e7aeef03", [:rebar3], [{:certifi, "2.3.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.2", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "5.1.2", "e21cb58a09f0228a9e0b95eaa1217f1bcfc31a1aaa6e1fdf2f53a33f7dbd9494", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"inch_ex": {:hex, :inch_ex, "0.5.6", "418357418a553baa6d04eccd1b44171936817db61f4c0840112b420b8e378e67", [:mix], [{:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"jason": {:hex, :jason, "1.0.0", "0f7cfa9bdb23fed721ec05419bcee2b2c21a77e926bce0deda029b5adc716fe2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [:mix, :rebar3], [], "hexpm"},
"lager": {:hex, :lager, "3.5.1", "63897a61af646c59bb928fee9756ce8bdd02d5a1a2f3551d4a5e38386c2cc071", [:rebar3], [{:goldrush, "0.1.9", [hex: :goldrush, repo: "hexpm", optional: false]}], "hexpm"},
"jason": {:hex, :jason, "1.1.1", "d3ccb840dfb06f2f90a6d335b536dd074db748b3e7f5b11ab61d239506585eb2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
"mime": {:hex, :mime, "1.3.0", "5e8d45a39e95c650900d03f897fbf99ae04f60ab1daa4a34c7a20a5151b7a5fe", [:mix], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"},
"parse_trans": {:hex, :parse_trans, "3.2.0", "2adfa4daf80c14dc36f522cf190eb5c4ee3e28008fc6394397c16f62a26258c2", [:rebar3], [], "hexpm"},
"plug": {:hex, :plug, "1.6.0", "90d338a44c8cd762c32d3ea324f6728445c6145b51895403854b77f1536f1617", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},
"rabbit_common": {:hex, :rabbit_common, "3.7.6", "fe6b34db6a98ceef40852e55dd782e944a63c7e855794ab58d3c3845091a6db0", [:make, :rebar3], [{:jsx, "2.8.2", [hex: :jsx, repo: "hexpm", optional: false]}, {:lager, "3.5.1", [hex: :lager, repo: "hexpm", optional: false]}, {:ranch, "1.5.0", [hex: :ranch, repo: "hexpm", optional: false]}, {:ranch_proxy_protocol, "1.5.0", [hex: :ranch_proxy_protocol, repo: "hexpm", optional: false]}, {:recon, "2.3.2", [hex: :recon, repo: "hexpm", optional: false]}], "hexpm"},
"ranch": {:hex, :ranch, "1.5.0", "f04166f456790fee2ac1aa05a02745cc75783c2bfb26d39faf6aefc9a3d3a58a", [:rebar3], [], "hexpm"},
"ranch_proxy_protocol": {:hex, :ranch_proxy_protocol, "1.5.0", "e698aaeb590ad504b649dc0d3055abee6caf0b49d3caee1a080ae83b5b499f30", [:rebar3], [{:ranch, "1.5.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
"recon": {:hex, :recon, "2.3.2", "4444c879be323b1b133eec5241cb84bd3821ea194c740d75617e106be4744318", [:rebar3], [], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"},
}
9 changes: 0 additions & 9 deletions test/support/provider/dummy/dummy.ex

This file was deleted.

10 changes: 0 additions & 10 deletions test/support/random/reciever.ex

This file was deleted.

13 changes: 0 additions & 13 deletions test/unit/bot/bot_test.exs

This file was deleted.

35 changes: 0 additions & 35 deletions test/unit/bot/storage_test.exs

This file was deleted.

4 changes: 2 additions & 2 deletions test/unit/chain/loopback_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ defmodule Chain.LoopbackTest do
end

test ": call" do
assert %Agala.Conn{responser_name: "test"} =
Loopback.call(%Agala.Conn{request_bot_params: %{name: "test"}}, [])
assert %Agala.Conn{responser: Test} =
Loopback.call(%Agala.Conn{request_bot_params: %{bot: Test}}, [])
end
end
end
10 changes: 5 additions & 5 deletions test/unit/conn/bot_params_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ defmodule Agala.BotParamsTest do
setup do
%{bot_params: %Agala.BotParams{
private: %{},
name: "test",
bot: Test,
provider: FooProvider,
handler: FooHandler,
chain: FooHandler,
provider_params: nil
}}
end
Expand All @@ -17,12 +17,12 @@ defmodule Agala.BotParamsTest do
assert {:ok, FooProvider} = Access.fetch(bot_params, :provider)
assert {:ok, nil} = Access.fetch(bot_params, :provider_params)

assert FooHandler = Access.get(bot_params, :handler)
assert FooHandler = Access.get(bot_params, :chain)
assert nil == Access.get(bot_params, :foo)

assert {"test", %{name: "shmest"}} = Access.get_and_update(bot_params, :name, fn _ -> {"test", "shmest"} end)
assert {Test, %{bot: Shmest}} = Access.get_and_update(bot_params, :bot, fn _ -> {Test, Shmest} end)

assert {"test", %{name: "test"}} = Access.pop(bot_params, :name)
assert {Test, %{bot: Test}} = Access.pop(bot_params, :bot)
end
end
end
12 changes: 2 additions & 10 deletions test/unit/conn/conn_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Agala.ConnTest do
response: nil,
halted: false,
request_bot_params: %Agala.BotParams{},
responser_name: "test"
responser: Test
}}
end

Expand All @@ -32,15 +32,7 @@ defmodule Agala.ConnTest do
end

test ": send_to is working properly", %{conn: conn} do
assert %{responser_name: "foo"} = Conn.send_to(conn, "foo")
end

test ": with_fallback is working properly", %{conn: conn} do
fun = fn conn -> conn.responser_name end

%{fallback: fun_from_conn} = Conn.with_fallback(conn, fun)

assert "test" = fun_from_conn.(conn)
assert %{responser: Foo} = Conn.send_to(conn, Foo)
end

test ": assigns is working properly", %{conn: conn} do
Expand Down
52 changes: 0 additions & 52 deletions test/unit/conn/multi_test.exs

This file was deleted.

22 changes: 14 additions & 8 deletions test/unit/provider/behaviour_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,28 @@ defmodule Agala.Provider.Test do
defmodule Bar do
use Agala.Provider

def get_receiver() do
Foo
def get_bot(:poller) do
Poller
end

def get_responser() do
Bazz
def get_bot(:handler) do
Handler
end

def get_bot(:plug) do
Plug
end
end

test "Using without override" do
assert Agala.Provider.Test.Foo.Receiver = Foo.get_receiver
assert Agala.Provider.Test.Foo.Responser = Foo.get_responser
assert Agala.Provider.Test.Foo.Poller = Foo.get_bot(:poller)
assert Agala.Provider.Test.Foo.Handler = Foo.get_bot(:handler)
assert Agala.Provider.Test.Foo.Plug = Foo.get_bot(:plug)
end

test "Using with override" do
assert Foo = Bar.get_receiver
assert Bazz = Bar.get_responser
assert Poller = Bar.get_bot(:poller)
assert Handler = Bar.get_bot(:handler)
assert Plug = Bar.get_bot(:plug)
end
end

0 comments on commit f3a3c10

Please sign in to comment.