Skip to content

Commit

Permalink
test: update snapshots after #3337 got merged
Browse files Browse the repository at this point in the history
  • Loading branch information
jkomyno committed Oct 27, 2022
1 parent ade5723 commit ac2c1c4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 347 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,10 @@ mod at_at_map {
use indoc::indoc;
use introspection_engine_tests::test_api::*;

// referentialIntegrity = "prisma" with @@map loses track of the relation policy ("prisma") but preserves relations.
// referentialIntegrity="prisma" is renamed as relationMode="prisma", and @relations are preserved.
#[test_connector(tags(Mssql))]
async fn referential_integrity_prisma_at_map_map(api: &TestApi) -> TestResult {
let init = formatdoc! {r#"
let init = indoc! {r#"
CREATE TABLE [dbo].[foo_table] (
[id] INT NOT NULL,
[bar_id] INT NOT NULL,
Expand Down Expand Up @@ -356,8 +356,9 @@ mod at_at_map {
}
datasource db {
provider = "sqlserver"
url = env("TEST_DATABASE_URL")
provider = "sqlserver"
url = env("TEST_DATABASE_URL")
relationMode = "prisma"
}
model Foo {
Expand All @@ -382,10 +383,10 @@ mod at_at_map {
Ok(())
}

// referentialIntegrity = "foreignKeys" with @@map loses track of the relation policy ("foreignKeys"), but preserves @relations, which are moved to the bottom.
// referentialIntegrity="foreignKeys" is renamed as relationMode="foreignKeys", and @relations are preserved.
#[test_connector(tags(Mssql))]
async fn referential_integrity_foreign_keys_at_map_map(api: &TestApi) -> TestResult {
let init = formatdoc! {r#"
let init = indoc! {r#"
CREATE TABLE [dbo].[foo_table] (
[id] INT NOT NULL,
[bar_id] INT NOT NULL,
Expand Down Expand Up @@ -438,8 +439,9 @@ mod at_at_map {
}
datasource db {
provider = "sqlserver"
url = env("TEST_DATABASE_URL")
provider = "sqlserver"
url = env("TEST_DATABASE_URL")
relationMode = "foreignKeys"
}
model Foo {
Expand All @@ -464,10 +466,10 @@ mod at_at_map {
Ok(())
}

// relationMode = "prisma" with @@map preserves the relation policy ("prisma"), but loses track of @relations.
// relationMode="prisma" preserves the relation policy ("prisma") as well as @relations.
#[test_connector(tags(Mssql))]
async fn relation_mode_prisma_at_map_map(api: &TestApi) -> TestResult {
let init = formatdoc! {r#"
let init = indoc! {r#"
CREATE TABLE [dbo].[foo_table] (
[id] INT NOT NULL,
[bar_id] INT NOT NULL,
Expand Down Expand Up @@ -513,29 +515,29 @@ mod at_at_map {

let expected = expect![[r#"
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
}
datasource db {
provider = "sqlserver"
url = env("TEST_DATABASE_URL")
relationMode = "prisma"
provider = "sqlserver"
url = env("TEST_DATABASE_URL")
relationMode = "prisma"
}
model Foo {
id Int @id
bar Bar @relation(fields: [bar_id], references: [id])
bar_id Int @unique
id Int @id
bar Bar @relation(fields: [bar_id], references: [id])
bar_id Int @unique
@@map("foo_table")
@@map("foo_table")
}
model Bar {
id Int @id
foo Foo?
id Int @id
foo Foo?
@@map("bar_table")
@@map("bar_table")
}
"#]];

Expand All @@ -545,10 +547,10 @@ mod at_at_map {
Ok(())
}

// relationMode = "foreignKeys" with @@map preserves the relation policy ("foreignKeys") and @relations, which are moved to the bottom.
// relationMode="foreignKeys" preserves the relation policy ("foreignKeys") as well as @relations., which are moved to the bottom.
#[test_connector(tags(Mssql))]
async fn relation_mode_foreign_keys_at_map_map(api: &TestApi) -> TestResult {
let init = formatdoc! {r#"
let init = indoc! {r#"
CREATE TABLE [dbo].[foo_table] (
[id] INT NOT NULL,
[bar_id] INT NOT NULL,
Expand Down Expand Up @@ -627,75 +629,4 @@ mod at_at_map {

Ok(())
}

// @relations are moved to the bottom of the model even when no referentialIntegrity/relationMode is used and @@map is used.
#[test_connector(tags(Mssql))]
async fn no_relation_at_map_map(api: &TestApi) -> TestResult {
let init = formatdoc! {r#"
CREATE TABLE [dbo].[foo_table] (
[id] INT NOT NULL,
[bar_id] INT NOT NULL,
CONSTRAINT [foo_table_pkey] PRIMARY KEY CLUSTERED ([id]),
CONSTRAINT [foo_table_bar_id_key] UNIQUE NONCLUSTERED ([bar_id])
);
CREATE TABLE [dbo].[bar_table] (
[id] INT NOT NULL,
CONSTRAINT [bar_table_pkey] PRIMARY KEY CLUSTERED ([id])
);
ALTER TABLE [dbo].[foo_table] ADD CONSTRAINT [foo_table_bar_id_fkey] FOREIGN KEY ([bar_id]) REFERENCES [dbo].[bar_table]([id]) ON DELETE NO ACTION ON UPDATE CASCADE;
"#};

api.raw_cmd(&init).await;

let input = indoc! {r#"
datasource db {
provider = "sqlserver"
url = env("TEST_DATABASE_URL")
}
model Foo {
id Int @id
bar Bar @relation(fields: [bar_id], references: [id])
bar_id Int @unique
@@map("foo_table")
}
model Bar {
id Int @id
foo Foo?
@@map("bar_table")
}
"#};

let expected = expect![[r#"
datasource db {
provider = "sqlserver"
url = env("TEST_DATABASE_URL")
}
model Foo {
id Int @id
bar_id Int @unique
bar Bar @relation(fields: [bar_id], references: [id])
@@map("foo_table")
}
model Bar {
id Int @id
foo Foo?
@@map("bar_table")
}
"#]];

let result = api.re_introspect_config(input).await?;
expected.assert_eq(&result);

Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ mod at_at_map {
use indoc::indoc;
use introspection_engine_tests::test_api::*;

// referentialIntegrity = "prisma" with @@map loses track of the relation policy ("prisma") and of @relations.
// referentialIntegrity="prisma" is renamed as relationMode="prisma", and @relations are preserved.
#[test_connector(tags(Mysql), exclude(Vitess))]
async fn referential_integrity_prisma_at_map_map(api: &TestApi) -> TestResult {
let init = formatdoc! {r#"
let init = indoc! {r#"
CREATE TABLE `foo_table` (
`id` INTEGER NOT NULL,
`bar_id` INTEGER NOT NULL,
Expand Down Expand Up @@ -366,8 +366,9 @@ mod at_at_map {
}
datasource db {
provider = "mysql"
url = env("TEST_DATABASE_URL")
provider = "mysql"
url = env("TEST_DATABASE_URL")
relationMode = "prisma"
}
model Foo {
Expand All @@ -392,10 +393,10 @@ mod at_at_map {
Ok(())
}

// referentialIntegrity = "foreignKeys" with @@map loses track of the relation policy ("foreignKeys"), but preserves @relations, which are moved to the bottom.
// referentialIntegrity="foreignKeys" is renamed as relationMode="foreignKeys", and @relations are preserved.
#[test_connector(tags(Mysql), exclude(Vitess))]
async fn referential_integrity_foreign_keys_at_map_map(api: &TestApi) -> TestResult {
let init = formatdoc! {r#"
let init = indoc! {r#"
CREATE TABLE `foo_table` (
`id` INTEGER NOT NULL,
`bar_id` INTEGER NOT NULL,
Expand Down Expand Up @@ -450,8 +451,9 @@ mod at_at_map {
}
datasource db {
provider = "mysql"
url = env("TEST_DATABASE_URL")
provider = "mysql"
url = env("TEST_DATABASE_URL")
relationMode = "foreignKeys"
}
model Foo {
Expand All @@ -476,10 +478,10 @@ mod at_at_map {
Ok(())
}

// relationMode = "prisma" with @@map preserves the relation policy ("prisma"), but loses track of @relations.
// relationMode="prisma" preserves the relation policy ("prisma") as well as @relations.
#[test_connector(tags(Mysql), exclude(Vitess))]
async fn relation_mode_prisma_at_map_map(api: &TestApi) -> TestResult {
let init = formatdoc! {r#"
let init = indoc! {r#"
CREATE TABLE `foo_table` (
`id` INTEGER NOT NULL,
`bar_id` INTEGER NOT NULL,
Expand Down Expand Up @@ -559,10 +561,10 @@ mod at_at_map {
Ok(())
}

// relationMode = "foreignKeys" with @@map preserves the relation policy ("foreignKeys") and @relations, which are moved to the bottom.
// relationMode="foreignKeys" preserves the relation policy ("foreignKeys") as well as @relations., which are moved to the bottom.
#[test_connector(tags(Mysql), exclude(Vitess))]
async fn relation_mode_foreign_keys_at_map_map(api: &TestApi) -> TestResult {
let init = formatdoc! {r#"
let init = indoc! {r#"
CREATE TABLE `foo_table` (
`id` INTEGER NOT NULL,
`bar_id` INTEGER NOT NULL,
Expand Down Expand Up @@ -643,77 +645,4 @@ mod at_at_map {

Ok(())
}

// @relations are moved to the bottom of the model even when no referentialIntegrity/relationMode is used and @@map is used.
#[test_connector(tags(Mysql), exclude(Vitess))]
async fn no_relation_at_map_map(api: &TestApi) -> TestResult {
let init = formatdoc! {r#"
CREATE TABLE `foo_table` (
`id` INTEGER NOT NULL,
`bar_id` INTEGER NOT NULL,
UNIQUE INDEX `foo_table_bar_id_key`(`bar_id`),
PRIMARY KEY (`id`)
);
CREATE TABLE `bar_table` (
`id` INTEGER NOT NULL,
PRIMARY KEY (`id`)
);
ALTER TABLE `foo_table` ADD CONSTRAINT `foo_table_bar_id_fkey` FOREIGN KEY (`bar_id`) REFERENCES `bar_table`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
"#};

api.raw_cmd(&init).await;

let input = indoc! {r#"
datasource db {
provider = "mysql"
url = env("TEST_DATABASE_URL")
}
model Foo {
id Int @id
bar Bar @relation(fields: [bar_id], references: [id])
bar_id Int @unique
@@map("foo_table")
}
model Bar {
id Int @id
foo Foo?
@@map("bar_table")
}
"#};

let expected = expect![[r#"
datasource db {
provider = "mysql"
url = env("TEST_DATABASE_URL")
}
model Foo {
id Int @id
bar_id Int @unique
bar Bar @relation(fields: [bar_id], references: [id])
@@map("foo_table")
}
model Bar {
id Int @id
foo Foo?
@@map("bar_table")
}
"#]];

let result = api.re_introspect_config(input).await?;
expected.assert_eq(&result);

Ok(())
}
}

0 comments on commit ac2c1c4

Please sign in to comment.