From f8eb07c608bf22e51c43cc7dd78e06198f4b41f6 Mon Sep 17 00:00:00 2001 From: Roman Heinrich Date: Sat, 11 Nov 2023 00:17:10 +0100 Subject: [PATCH] Chore: nicer tests formatting --- lib/surrealdb/statements/continue_test.exs | 16 +++++------- lib/surrealdb/statements/for_test.exs | 14 +++++----- lib/surrealdb/statements/select_test.exs | 30 +++++----------------- 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/lib/surrealdb/statements/continue_test.exs b/lib/surrealdb/statements/continue_test.exs index 3d1e79c..c30f94d 100644 --- a/lib/surrealdb/statements/continue_test.exs +++ b/lib/surrealdb/statements/continue_test.exs @@ -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; @@ -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"}, diff --git a/lib/surrealdb/statements/for_test.exs b/lib/surrealdb/statements/for_test.exs index 125567f..7ce49f8 100644 --- a/lib/surrealdb/statements/for_test.exs +++ b/lib/surrealdb/statements/for_test.exs @@ -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"}, diff --git a/lib/surrealdb/statements/select_test.exs b/lib/surrealdb/statements/select_test.exs index 6ef4d7c..8521af7 100644 --- a/lib/surrealdb/statements/select_test.exs +++ b/lib/surrealdb/statements/select_test.exs @@ -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|