Skip to content

Commit

Permalink
✅ fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Odonno committed Oct 11, 2023
1 parent 44ec48f commit 9d60b16
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 48 deletions.
25 changes: 22 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ surrealdb = { version = "1.0.0", features = ["protocol-http"] }
assert_cmd = "2.0.11"
assert_fs = "1.0.13"
dir-diff = "0.3.2"
predicates = "3.0.4"
pretty_assertions = "1.3.0"
serial_test = "2.0.0"
tokio-test = "0.4.2"
2 changes: 1 addition & 1 deletion templates/blog/schemas/user.surql
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ DEFINE SCOPE user_scope
SELECT *
FROM user
WHERE username = $username AND crypto::argon2::compare(password, $password)
);
);
40 changes: 20 additions & 20 deletions tests/cli/apply/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,15 @@ DEFINE TABLE comment SCHEMALESS
FOR create WHERE permission:create_comment IN $auth.permissions
FOR update, delete WHERE in = $auth.id;
DEFINE FIELD content ON comment TYPE string ASSERT $value != NONE;
DEFINE FIELD created_at ON comment TYPE datetime VALUE $before OR time::now();
DEFINE FIELD content ON comment TYPE string;
DEFINE FIELD created_at ON comment TYPE datetime DEFAULT time::now();
DEFINE TABLE permission SCHEMAFULL
PERMISSIONS
FOR select FULL
FOR create, update, delete NONE;
DEFINE FIELD name ON permission TYPE string;
DEFINE FIELD created_at ON permission TYPE datetime VALUE $before OR time::now();
DEFINE FIELD created_at ON permission TYPE datetime DEFAULT time::now();
DEFINE INDEX unique_name ON permission COLUMNS name UNIQUE;
DEFINE TABLE post SCHEMALESS
Expand All @@ -586,30 +586,30 @@ DEFINE TABLE post SCHEMALESS
DEFINE FIELD title ON post TYPE string;
DEFINE FIELD content ON post TYPE string;
DEFINE FIELD author ON post TYPE record (user) ASSERT $value != NONE;
DEFINE FIELD created_at ON post TYPE datetime VALUE $before OR time::now();
DEFINE FIELD status ON post TYPE string VALUE $value OR $before OR 'DRAFT' ASSERT $value == NONE OR $value INSIDE ['DRAFT', 'PUBLISHED'];
DEFINE FIELD author ON post TYPE record<user>;
DEFINE FIELD created_at ON post TYPE datetime DEFAULT time::now();
DEFINE FIELD status ON post TYPE string DEFAULT 'DRAFT' ASSERT $value IN ['DRAFT', 'PUBLISHED'];
DEFINE TABLE script_migration SCHEMAFULL
PERMISSIONS
FOR select FULL
FOR create, update, delete NONE;
DEFINE FIELD script_name ON script_migration TYPE string;
DEFINE FIELD executed_at ON script_migration TYPE datetime VALUE $before OR time::now();
DEFINE FIELD executed_at ON script_migration TYPE datetime DEFAULT time::now();
DEFINE TABLE user SCHEMAFULL
PERMISSIONS
FOR select FULL
FOR update WHERE id = $auth.id
FOR create, delete NONE;
DEFINE FIELD username ON user TYPE string ASSERT $value != NONE;
DEFINE FIELD email ON user TYPE string ASSERT is::email($value);
DEFINE FIELD password ON user TYPE string ASSERT $value != NONE;
DEFINE FIELD registered_at ON user TYPE datetime VALUE $before OR time::now();
DEFINE FIELD avatar ON user TYPE string;
DEFINE FIELD username ON user TYPE string;
DEFINE FIELD email ON user TYPE string ASSERT string::is::email($value);
DEFINE FIELD password ON user TYPE string;
DEFINE FIELD registered_at ON user TYPE datetime DEFAULT time::now();
DEFINE FIELD avatar ON user TYPE option<string>;
DEFINE FIELD permissions ON user TYPE array VALUE [permission:create_post, permission:create_comment];
DEFINE FIELD permissions.* ON user TYPE record (permission);
DEFINE FIELD permissions ON user TYPE array<record<permission>>
DEFAULT [permission:create_post, permission:create_comment];
DEFINE INDEX unique_username ON user COLUMNS username UNIQUE;
DEFINE INDEX unique_email ON user COLUMNS email UNIQUE;
Expand All @@ -635,8 +635,8 @@ const INITIAL_DEFINITION_EVENTS: &str = "DEFINE TABLE publish_post SCHEMALESS
FOR select, create FULL
FOR update, delete NONE;
DEFINE FIELD post_id ON publish_post TYPE record(post);
DEFINE FIELD created_at ON publish_post TYPE datetime VALUE $before OR time::now();
DEFINE FIELD post_id ON publish_post TYPE record<post>;
DEFINE FIELD created_at ON publish_post TYPE datetime DEFAULT time::now();
DEFINE EVENT publish_post ON TABLE publish_post WHEN $event == \"CREATE\" THEN (
UPDATE post SET status = \"PUBLISHED\" WHERE id = $after.post_id
Expand All @@ -646,8 +646,8 @@ DEFINE TABLE unpublish_post SCHEMALESS
FOR select, create FULL
FOR update, delete NONE;
DEFINE FIELD post_id ON unpublish_post TYPE record(post);
DEFINE FIELD created_at ON unpublish_post TYPE datetime VALUE $before OR time::now();
DEFINE FIELD post_id ON unpublish_post TYPE record<post>;
DEFINE FIELD created_at ON unpublish_post TYPE datetime DEFAULT time::now();
DEFINE EVENT unpublish_post ON TABLE unpublish_post WHEN $event == \"CREATE\" THEN (
UPDATE post SET status = \"DRAFT\" WHERE id = $after.post_id
Expand All @@ -659,7 +659,7 @@ const SECOND_MIGRATION_SCHEMAS: &str = "--- original
+DEFINE TABLE category SCHEMALESS;
+
+DEFINE FIELD name ON category TYPE string;
+DEFINE FIELD created_at ON category TYPE datetime VALUE $before OR time::now();
+DEFINE FIELD created_at ON category TYPE datetime DEFAULT time::now();
# in: user
# out: post, comment
DEFINE TABLE comment SCHEMALESS\n";
Expand All @@ -672,7 +672,7 @@ const THIRD_MIGRATION_SCHEMAS: &str = "--- original
+DEFINE FIELD name ON archive TYPE string;
+DEFINE FIELD from_date ON archive TYPE datetime;
+DEFINE FIELD to_date ON archive TYPE datetime;
+DEFINE FIELD created_at ON archive TYPE datetime VALUE $before OR time::now();
+DEFINE FIELD created_at ON archive TYPE datetime DEFAULT time::now();
DEFINE TABLE category SCHEMALESS;
DEFINE FIELD name ON category TYPE string;\n";
10 changes: 4 additions & 6 deletions tests/cli/apply/up.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{ensure, Result};
use assert_fs::TempDir;
use predicates::prelude::*;

use crate::helpers::*;

Expand Down Expand Up @@ -37,12 +38,9 @@ fn cannot_apply_if_surreal_instance_not_running() -> Result<()> {

cmd.arg("apply");

cmd.assert().failure().stderr(
"Error: There was an error processing a remote WS request
Caused by:
There was an error processing a remote WS request\n",
);
cmd.assert().failure().stderr(predicate::str::contains(
"Error: There was an error processing a remote WS request",
));

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/branch/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn diff_with_changes() -> Result<()> {
## category ##
DEFINE TABLE category SCHEMALESS
DEFINE FIELD created_at ON category TYPE datetime VALUE $before OR time::now()
DEFINE FIELD created_at ON category TYPE datetime DEFAULT time::now()
DEFINE FIELD name ON category TYPE string\n",
)
})?;
Expand Down
28 changes: 14 additions & 14 deletions tests/cli/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ DEFINE TABLE comment SCHEMALESS
FOR create WHERE permission:create_comment IN $auth.permissions
FOR update, delete WHERE in = $auth.id;
DEFINE FIELD content ON comment TYPE string ASSERT $value != NONE;
DEFINE FIELD created_at ON comment TYPE datetime VALUE $before OR time::now();
DEFINE FIELD content ON comment TYPE string;
DEFINE FIELD created_at ON comment TYPE datetime DEFAULT time::now();
DEFINE TABLE permission SCHEMAFULL
PERMISSIONS
FOR select FULL
FOR create, update, delete NONE;
DEFINE FIELD name ON permission TYPE string;
DEFINE FIELD created_at ON permission TYPE datetime VALUE $before OR time::now();
DEFINE FIELD created_at ON permission TYPE datetime DEFAULT time::now();
DEFINE INDEX unique_name ON permission COLUMNS name UNIQUE;
DEFINE TABLE post SCHEMALESS
Expand All @@ -178,30 +178,30 @@ DEFINE TABLE post SCHEMALESS
DEFINE FIELD title ON post TYPE string;
DEFINE FIELD content ON post TYPE string;
DEFINE FIELD author ON post TYPE record (user) ASSERT $value != NONE;
DEFINE FIELD created_at ON post TYPE datetime VALUE $before OR time::now();
DEFINE FIELD status ON post TYPE string VALUE $value OR $before OR 'DRAFT' ASSERT $value == NONE OR $value INSIDE ['DRAFT', 'PUBLISHED'];
DEFINE FIELD author ON post TYPE record<user>;
DEFINE FIELD created_at ON post TYPE datetime DEFAULT time::now();
DEFINE FIELD status ON post TYPE string DEFAULT 'DRAFT' ASSERT $value IN ['DRAFT', 'PUBLISHED'];
DEFINE TABLE script_migration SCHEMAFULL
PERMISSIONS
FOR select FULL
FOR create, update, delete NONE;
DEFINE FIELD script_name ON script_migration TYPE string;
DEFINE FIELD executed_at ON script_migration TYPE datetime VALUE $before OR time::now();
DEFINE FIELD executed_at ON script_migration TYPE datetime DEFAULT time::now();
DEFINE TABLE user SCHEMAFULL
PERMISSIONS
FOR select FULL
FOR update WHERE id = $auth.id
FOR create, delete NONE;
DEFINE FIELD username ON user TYPE string ASSERT $value != NONE;
DEFINE FIELD email ON user TYPE string ASSERT is::email($value);
DEFINE FIELD password ON user TYPE string ASSERT $value != NONE;
DEFINE FIELD registered_at ON user TYPE datetime VALUE $before OR time::now();
DEFINE FIELD avatar ON user TYPE string;
DEFINE FIELD username ON user TYPE string;
DEFINE FIELD email ON user TYPE string ASSERT string::is::email($value);
DEFINE FIELD password ON user TYPE string;
DEFINE FIELD registered_at ON user TYPE datetime DEFAULT time::now();
DEFINE FIELD avatar ON user TYPE option<string>;
DEFINE FIELD permissions ON user TYPE array VALUE [permission:create_post, permission:create_comment];
DEFINE FIELD permissions.* ON user TYPE record (permission);
DEFINE FIELD permissions ON user TYPE array<record<permission>>
DEFAULT [permission:create_post, permission:create_comment];
DEFINE INDEX unique_username ON user COLUMNS username UNIQUE;
DEFINE INDEX unique_email ON user COLUMNS email UNIQUE;
Expand Down
6 changes: 3 additions & 3 deletions tests/helpers/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub fn add_category_schema_file(path: &Path) -> Result<()> {
const CONTENT: &str = "DEFINE TABLE category SCHEMALESS;
DEFINE FIELD name ON category TYPE string;
DEFINE FIELD created_at ON category TYPE datetime VALUE $before OR time::now();";
DEFINE FIELD created_at ON category TYPE datetime DEFAULT time::now();";

fs::write(schema_file, CONTENT)?;
}
Expand Down Expand Up @@ -252,7 +252,7 @@ pub fn add_archive_schema_file(path: &Path) -> Result<()> {
DEFINE FIELD name ON archive TYPE string;
DEFINE FIELD from_date ON archive TYPE datetime;
DEFINE FIELD to_date ON archive TYPE datetime;
DEFINE FIELD created_at ON archive TYPE datetime VALUE $before OR time::now();";
DEFINE FIELD created_at ON archive TYPE datetime DEFAULT time::now();";

fs::write(schema_file, CONTENT)?;
}
Expand All @@ -262,7 +262,7 @@ DEFINE FIELD created_at ON archive TYPE datetime VALUE $before OR time::now();";

pub fn add_archive_migration_file(path: &Path) -> Result<()> {
let content =
"CREATE archive SET name = '2022', from_date = '2022-01-01', to_date = '2022-12-31';";
"CREATE archive SET name = '2022', from_date = '2022-01-01T00:00:00Z', to_date = '2022-12-31T00:00:00Z';";

let mut cmd = create_cmd(path)?;
cmd.arg("create")
Expand Down

0 comments on commit 9d60b16

Please sign in to comment.