Skip to content

Commit

Permalink
Chore: nicer tests formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mindreframer committed Nov 10, 2023
1 parent 98cc41f commit f8eb07c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 39 deletions.
16 changes: 7 additions & 9 deletions lib/surrealdb/statements/continue_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ defmodule ContinueTest do
setup [:setup_surrealix]

test "for - update / continue", %{pid: pid} do
sql_setup = ~s|
create person:1 set age = 17;
create person:2 set age = 18;
create person:3 set age = 19;
create person:4 set age = 20;
|
sql = ~s|
create person:1 set age = 17;
create person:2 set age = 18;
create person:3 set age = 19;
create person:4 set age = 20;
FOR $person IN (SELECT id, age FROM person) {
IF ($person.age < 18) {
CONTINUE;
Expand All @@ -23,15 +24,12 @@ defmodule ContinueTest do
select * from person where can_vote = true;
|
{:ok, _} = Surrealix.query(pid, sql_setup)

parsed = Surrealix.query(pid, sql) |> extract_res_list()

auto_assert(
[
ok: [%{"age" => 17, "id" => "person:1"}],
ok: [%{"age" => 18, "id" => "person:2"}],
ok: [%{"age" => 19, "id" => "person:3"}],
ok: [%{"age" => 20, "id" => "person:4"}],
ok: nil,
ok: [
%{"age" => 18, "can_vote" => true, "id" => "person:2"},
Expand Down
14 changes: 7 additions & 7 deletions lib/surrealdb/statements/for_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ defmodule ForTest do
end

test "for - update", %{pid: pid} do
sql_setup = ~s|
create person:1 set age = 19;
create person:2 set age = 17;
create person:3 set age = 18;
|

sql = ~s|
create person:1 set age = 19;
create person:2 set age = 17;
create person:3 set age = 18;
FOR $person IN (SELECT VALUE id FROM person WHERE age >= 18) {
UPDATE $person SET can_vote = true;
};
select * from person where can_vote = true;
|

{:ok, _} = Surrealix.query(pid, sql_setup)
parsed = Surrealix.query(pid, sql) |> extract_res_list()

auto_assert(
[
ok: [%{"age" => 19, "id" => "person:1"}],
ok: [%{"age" => 17, "id" => "person:2"}],
ok: [%{"age" => 18, "id" => "person:3"}],
ok: nil,
ok: [
%{"age" => 19, "can_vote" => true, "id" => "person:1"},
Expand Down
30 changes: 7 additions & 23 deletions lib/surrealdb/statements/select_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -147,29 +147,13 @@ defmodule SelectTest do
create profile:3 set name = "Prof3";
RELATE profile:1->experience->org:1
SET time.started = time::now()
;
RELATE profile:1->experience->org:2
SET time.started = time::now()
;
RELATE profile:1->experience->org:3
SET time.started = time::now()
;
RELATE profile:1->experience->org:4
SET time.started = time::now()
;
RELATE profile:2->experience->org:1
SET time.started = time::now()
;
RELATE profile:2->experience->org:2
SET time.started = time::now()
;
RELATE profile:3->experience->org:1
SET time.started = time::now()
;
RELATE profile:1->experience->org:1 SET time.started = time::now();
RELATE profile:1->experience->org:2 SET time.started = time::now();
RELATE profile:1->experience->org:3 SET time.started = time::now();
RELATE profile:1->experience->org:4 SET time.started = time::now();
RELATE profile:2->experience->org:1 SET time.started = time::now();
RELATE profile:2->experience->org:2 SET time.started = time::now();
RELATE profile:3->experience->org:1 SET time.started = time::now();
|

sql = ~s|
Expand Down

0 comments on commit f8eb07c

Please sign in to comment.