Skip to content

Commit

Permalink
Merge pull request #613 from prisma/postgres-types-test-unique
Browse files Browse the repository at this point in the history
Test unique fields as ID on postgres
  • Loading branch information
tomhoule committed Mar 25, 2020
2 parents 8cec25a + 6629005 commit dc6b03a
Showing 1 changed file with 36 additions and 34 deletions.
70 changes: 36 additions & 34 deletions query-engine/prisma/src/tests/type_mappings/postgres_types.rs
Expand Up @@ -185,7 +185,7 @@ fn create_one_types_response() -> serde_json::Value {
})
}

#[test_each_connector(tags("postgres"), log = "debug")]
#[test_each_connector(tags("postgres"))]
async fn postgres_types_roundtrip(api: &TestApi) -> TestResult {
api.execute_sql(CREATE_TYPES_TABLE).await?;

Expand Down Expand Up @@ -242,7 +242,7 @@ async fn postgres_types_roundtrip(api: &TestApi) -> TestResult {
Ok(())
}

#[test_each_connector(tags("postgres"), log = "debug")]
#[test_each_connector(tags("postgres"))]
async fn small_float_values_must_work(api: &TestApi) -> TestResult {
let schema = indoc! {
r#"
Expand Down Expand Up @@ -477,9 +477,9 @@ async fn postgres_array_types_roundtrip(api: &TestApi) -> TestResult {
Ok(())
}

#[test_each_connector(tags("postgres"))]
#[test_each_connector(tags("postgres"), log = "debug")]
async fn all_postgres_id_types_work(api: &TestApi) -> TestResult {
let pk_types = &[
let identifier_types = &[
("int2", "12"),
("int4", "78"),
("int8", "1293"),
Expand Down Expand Up @@ -510,37 +510,39 @@ async fn all_postgres_id_types_work(api: &TestApi) -> TestResult {

let drop_table = r#"DROP TABLE IF EXISTS "prisma-tests"."pk_test""#;

for (pk_type, pk_value) in pk_types {
let create_table = format!(
r#"CREATE TABLE "prisma-tests"."pk_test" (id {}, PRIMARY KEY (id))"#,
pk_type
);
api.execute_sql(drop_table).await?;
api.execute_sql(&create_table).await?;

let (_datamodel, engine) = api.introspect_and_start_query_engine().await?;

let query = format!(
r#"
mutation {{
createOnepk_test(
data: {{
id: {}
for (identifier_type, identifier_value) in identifier_types {
for index_type in &["PRIMARY KEY", "UNIQUE"] {
let create_table = format!(
r#"CREATE TABLE "prisma-tests"."pk_test" (id {} NOT NULL, {} (id))"#,
identifier_type, index_type,
);
api.execute_sql(drop_table).await?;
api.execute_sql(&create_table).await?;

let (_datamodel, engine) = api.introspect_and_start_query_engine().await?;

let query = format!(
r#"
mutation {{
createOnepk_test(
data: {{
id: {}
}}
) {{
id
}}
) {{
id
}}
}}
"#,
pk_value
);
"#,
identifier_value
);

let response = engine.request(query).await;
let response = engine.request(query).await;

assert_eq!(
response.to_string(),
format!(r#"{{"data":{{"createOnepk_test":{{"id":{}}}}}}}"#, pk_value)
);
assert_eq!(
response.to_string(),
format!(r#"{{"data":{{"createOnepk_test":{{"id":{}}}}}}}"#, identifier_value)
);
}
}

Ok(())
Expand Down Expand Up @@ -571,8 +573,8 @@ async fn all_postgres_types_work_as_filter(api: &TestApi) -> TestResult {
string_char: "yeet"
string_varchar: "yeet variable"
string_text: "to yeet or not to yeet"
# binary_bits: "0101110"
# binary_bits_varying: "0101110"
binary_bits: "0101110"
binary_bits_varying: "0101110"
binary_uuid: "111142ec-880b-4062-913d-8eac479ab957"
time_timestamp: "2020-03-02T08:00:00.000"
time_timestamptz: "2020-03-02T08:00:00.000"
Expand Down Expand Up @@ -778,7 +780,7 @@ const CREATE_TYPES_TABLE_WITH_ARRAY_DEFAULTS: &str = indoc! {
"##
};

#[test_each_connector(tags("postgres"), log = "debug")]
#[test_each_connector(tags("postgres"))]
async fn postgres_db_level_array_defaults_work(api: &TestApi) -> TestResult {
api.execute_sql(CREATE_TYPES_TABLE_WITH_ARRAY_DEFAULTS).await?;

Expand Down

0 comments on commit dc6b03a

Please sign in to comment.