Skip to content

Commit

Permalink
move test cases into test directory
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin67 committed Nov 5, 2023
1 parent 5610f37 commit 4119019
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
Dotenv.load()

# Start server
Inngest.Dev.Router.start_server()
Inngest.Test.PlugRouter.start_server()
|> Task.await(:infinity)
File renamed without changes.
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ defmodule Inngest.MixProject do
]
end

defp elixirc_paths(:dev), do: ["lib", "dev"]
defp elixirc_paths(:dev), do: ["lib", "test/support"]
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]

Expand Down
1 change: 1 addition & 0 deletions test/inngest/router/helper_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ defmodule Inngest.Router.HelperTest do
@dev_mods [Inngest.Dev.EventFn, Inngest.Dev.CronFn]
@test_mods [Inngest.TestEventFn, Inngest.TestCronFn]

@tag :skip
test "should compile all modules in the provided path" do
assert %{funcs: funcs} = Helper.load_functions_from_path(%{path: @path})
assert Enum.count(funcs) == Enum.count(@test_mods)
Expand Down
14 changes: 14 additions & 0 deletions test/support/cases/no_step_fn.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Inngest.Test.Case.NoStepFn do
@moduledoc false

use Inngest.Function
alias Inngest.{FnOpts, Trigger}

@func %FnOpts{id: "no-step-fn", name: "No Step Function"}
@trigger %Trigger{event: "test/no-step"}

@impl true
def exec(_, _args) do
{:ok, "hello world"}
end
end
21 changes: 21 additions & 0 deletions test/support/cases/step_fn.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Inngest.Test.Case.StepFn do
@moduledoc false

use Inngest.Function
alias Inngest.{FnOpts, Trigger}

@func %FnOpts{id: "step-fn", name: "Step Function"}
@trigger %Trigger{event: "test/step"}

@count 0

@impl true
def exec(ctx, %{step: step} = _args) do
step1 = step.run(ctx, "step1", fn -> @count + 1 end)
tmp = step1 + 1
step2 = step.run(ctx, "step2", fn -> tmp + 1 end)
tmp2 = step2 + 1

{:ok, tmp2 + 1}
end
end
11 changes: 6 additions & 5 deletions dev/router.ex → test/support/router/plug.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
defmodule Inngest.Dev.Router do
defmodule Inngest.Test.PlugRouter do

Check warning on line 1 in test/support/router/plug.ex

View workflow job for this annotation

GitHub Actions / Linter

Modules should have a @moduledoc tag.
use Plug.Router
use Inngest.Router, :plug
alias Inngest.Dev.{EventFn, CronFn}

require Logger
Logger.configure(level: System.get_env("DEV_LOG_LEVEL", :debug))
Logger.configure(level: System.get_env("DEV_LOG_LEVEL", "debug"))

plug(Plug.Logger, log: :debug)

Expand All @@ -26,15 +25,17 @@ defmodule Inngest.Dev.Router do
|> send_resp(200, data)
end

inngest("/api/inngest", path: System.get_env("INNGEST_FN_PATH", "dev/**"))
inngest("/api/inngest", path: "test/support/cases/*")

match _ do
send_resp(conn, 404, "oops\n")
end

def start_server() do
Task.async(fn ->
webserver = {Plug.Cowboy, plug: Inngest.Dev.Router, scheme: :http, options: [port: 4000]}
webserver =
{Plug.Cowboy, plug: Inngest.Test.PlugRouter, scheme: :http, options: [port: 4000]}

{:ok, _} = Supervisor.start_link([webserver], strategy: :one_for_one)
Logger.info("Server listening on 127.0.0.1:4000")

Expand Down

0 comments on commit 4119019

Please sign in to comment.