-
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.
Chore: first dummy test for projections
- Loading branch information
1 parent
4c403cb
commit 0440d85
Showing
1 changed file
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
defmodule Essig.Projections.RunnerTest do | ||
use Essig.DataCase | ||
|
||
defmodule TestProjection do | ||
use Essig.Projections.Projection | ||
use Essig.Repo | ||
require Logger | ||
|
||
@impl Essig.Projections.Projection | ||
def handle_event(multi, {map, seq}) do | ||
Ecto.Multi.run(multi, {:event, seq}, fn _repo, _changes -> | ||
IO.inspect(map.data, label: "seq-#{seq}") | ||
{:ok, 1} | ||
end) | ||
end | ||
|
||
@impl Essig.Projections.Projection | ||
def init_storage(data = %Data{}) do | ||
Logger.info("RUNNING INIT STORAGE for #{__MODULE__} with name #{inspect(data.name)}") | ||
Repo.query("create table if not exists #{table_name(data)} (id integer, data text)") | ||
:ok | ||
end | ||
|
||
def table_name(data) do | ||
"projection_#{inspect(data.module)}" | ||
end | ||
end | ||
|
||
describe "basic features" do | ||
test "works" do | ||
scope_uuid = Essig.UUID7.generate() | ||
Essig.Context.set_current_scope(scope_uuid) | ||
Essig.Server.start_scope(scope_uuid) | ||
Essig.Server.start_projections([TestProjection], pause_ms: 2) | ||
|
||
# this is required to make sure the projection is finished | ||
Process.sleep(5) | ||
|
||
# Essig.Projections.SeqChecker.await([TestProjection], 0, 10) | ||
# pid = Essig.Server.get_projection(TestProjection) | ||
# GenServer.stop(pid) | ||
end | ||
end | ||
end |