Skip to content

Commit

Permalink
fix oneshot test
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetised committed Oct 31, 2024
1 parent f4847c0 commit c5fb512
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/elixir-client/test/electric/client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ defmodule Electric.ClientTest do
assert_receive {:stream, 2, up_to_date()}
end

test "live: false should halt once snapshot is complete", ctx do
test "oneshot: true should halt once snapshot is complete", ctx do
{:ok, id1} = insert_item(ctx)
{:ok, id2} = insert_item(ctx)
{:ok, id3} = insert_item(ctx)
Expand All @@ -186,7 +186,7 @@ defmodule Electric.ClientTest do
{:ok, id5} = insert_item(ctx)
{:ok, id6} = insert_item(ctx)

stream = stream(ctx, live: false)
stream = stream(ctx, oneshot: true)

events = stream |> Enum.into([])

Expand Down
20 changes: 7 additions & 13 deletions packages/elixir-client/test/support/db_setup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,21 @@ defmodule Support.DbSetup do
%{utility_pool: utility_pool, pool: pool, db_conn: pool, tablename: tablename}
end

def insert_item(%{db_conn: db, tablename: tablename}) do
insert_item(db, tablename)
def insert_item(%{db_conn: db, tablename: tablename}, opts \\ []) do
insert_item(db, tablename, opts)
end

def insert_item(db_conn, tablename) do
id = UUID.uuid4()
def insert_item(db_conn, tablename, opts) do
id = Keyword.get(opts, :id, UUID.uuid4())
value = Keyword.get(opts, :value, "Some title")

%Postgrex.Result{num_rows: 1} =
Postgrex.query!(
db_conn,
"""
INSERT INTO \"#{tablename}\" (
id,
title
)
VALUES (
$1,
'Some title'
);
INSERT INTO \"#{tablename}\" (id, title) VALUES ($1, $2);
""",
[UUID.string_to_binary!(id)]
[UUID.string_to_binary!(id), value]
)

{:ok, id}
Expand Down

0 comments on commit c5fb512

Please sign in to comment.