Skip to content

Commit

Permalink
Add a test for json (#319)
Browse files Browse the repository at this point in the history
Inspired by #316
  • Loading branch information
aljazerzen authored Apr 18, 2024
1 parent 00001fb commit a014074
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
36 changes: 35 additions & 1 deletion edgedb-tokio/tests/func/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use std::str::FromStr;
use edgedb_protocol::model::Uuid;
use edgedb_protocol::named_args;
use edgedb_protocol::value::{EnumValue, Value};
use edgedb_tokio::Client;
use edgedb_tokio::{Client, Queryable};
use edgedb_errors::NoDataError;
use futures_util::stream::{self, StreamExt};
use serde::{Deserialize, Serialize};

use crate::server::SERVER;

Expand Down Expand Up @@ -124,6 +125,39 @@ async fn parallel_queries() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
async fn json() -> anyhow::Result<()> {
let client = Client::new(&SERVER.config);
client.ensure_connected().await?;

client.execute::<_>(
"insert test::OtpPhoneRequest {
phone := '0123456789',
sent_at := datetime_of_statement(),
otp := 98271
}",
&()
)
.await
.unwrap();

#[derive(Clone, Debug, Serialize, Deserialize, Queryable)]
#[edgedb(json)]
pub struct OtpPhoneRequest {
pub phone: String,
pub otp: i32,
}

let res = client.query::<OtpPhoneRequest, _>(
"select <json>(select test::OtpPhoneRequest { phone, otp } filter .phone = '0123456789')",
&()
)
.await?;
let res = res.into_iter().next().unwrap();
assert_eq!(res.phone, "0123456789");
assert_eq!(res.otp, 98271);
}

#[tokio::test]
async fn big_num() -> anyhow::Result<()> {
let client = Client::new(&SERVER.config);
Expand Down
7 changes: 7 additions & 0 deletions edgedb-tokio/tests/func/dbschema/test.esdl
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ module test {

global str_val -> str;
global int_val -> int32;

type OtpPhoneRequest {
required phone: str;
required otp: int32;
required sent_at: datetime;
confirmed_at: datetime;
}
}
4 changes: 1 addition & 3 deletions edgedb-tokio/tests/func/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ fn wait_for_server_status(status_read: i32) -> Result<ServerInfo, anyhow::Error>

/// Writes a stream to a log file
fn write_log_into_file(stream: impl std::io::Read) {
let target_tmp_dir = std::env::var("CARGO_TARGET_TMPDIR").unwrap();
let mut log_dir = std::path::PathBuf::from_str(&target_tmp_dir).unwrap();
log_dir.push("server-logs");
let log_dir = std::path::PathBuf::from_str("../target/server-logs").unwrap();

let time_the_epoch = std::time::SystemTime::now()
.duration_since(std::time::SystemTime::UNIX_EPOCH)
Expand Down

0 comments on commit a014074

Please sign in to comment.