2022-04-26 16:47:30 +03:00
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
|
2022-08-08 15:20:08 +03:00
|
|
|
-- |
|
|
|
|
-- Tests around inserting non-ASCII characters in @VARCHAR@ column type.
|
2022-04-26 16:47:30 +03:00
|
|
|
module Test.SQLServer.InsertVarcharColumnSpec (spec) where
|
|
|
|
|
2022-08-08 15:20:08 +03:00
|
|
|
import Data.Aeson (Value)
|
2022-04-26 16:47:30 +03:00
|
|
|
import Harness.Backend.Sqlserver qualified as Sqlserver
|
2022-08-08 15:20:08 +03:00
|
|
|
import Harness.GraphqlEngine (postGraphql)
|
2022-04-26 16:47:30 +03:00
|
|
|
import Harness.Quoter.Graphql (graphql)
|
2022-08-05 12:34:25 +03:00
|
|
|
import Harness.Quoter.Yaml (yaml)
|
2022-08-08 15:20:08 +03:00
|
|
|
import Harness.Test.Fixture qualified as Fixture
|
|
|
|
import Harness.Test.Schema (Table (..), table)
|
|
|
|
import Harness.Test.Schema qualified as Schema
|
2022-04-26 16:47:30 +03:00
|
|
|
import Harness.TestEnvironment (TestEnvironment)
|
2022-08-05 12:34:25 +03:00
|
|
|
import Harness.Yaml (shouldReturnYaml)
|
2022-08-03 17:18:43 +03:00
|
|
|
import Hasura.Prelude
|
2022-08-08 15:20:08 +03:00
|
|
|
import Test.Hspec (SpecWith, describe, it)
|
2022-04-26 16:47:30 +03:00
|
|
|
|
|
|
|
spec :: SpecWith TestEnvironment
|
2022-08-08 15:20:08 +03:00
|
|
|
spec = do
|
|
|
|
Fixture.run
|
|
|
|
[ (Fixture.fixture $ Fixture.Backend Fixture.SQLServer)
|
|
|
|
{ Fixture.setupTeardown = \(testEnv, _) ->
|
|
|
|
[ Sqlserver.setupTablesAction schema testEnv
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2022-04-26 16:47:30 +03:00
|
|
|
tests
|
|
|
|
|
2022-08-08 15:20:08 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Schema
|
|
|
|
|
|
|
|
schema :: [Schema.Table]
|
|
|
|
schema =
|
|
|
|
[ (table "test")
|
|
|
|
{ tableColumns =
|
|
|
|
[ Schema.column "id" Schema.TInt,
|
|
|
|
Schema.column "test" do
|
|
|
|
Schema.TCustomType
|
|
|
|
Schema.defaultBackendScalarType
|
|
|
|
{ Schema.bstMssql = Just "varchar(MAX)"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
tablePrimaryKey = ["id"]
|
|
|
|
},
|
|
|
|
(table "test_bin")
|
|
|
|
{ tableColumns =
|
|
|
|
[ Schema.column "id" Schema.TInt,
|
|
|
|
Schema.column "test" do
|
|
|
|
Schema.TCustomType
|
|
|
|
Schema.defaultBackendScalarType
|
|
|
|
{ Schema.bstMssql = Just "varchar(MAX) collate SQL_Latin1_General_CP437_BIN"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
tablePrimaryKey = ["id"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Tests
|
|
|
|
|
|
|
|
tests :: Fixture.Options -> SpecWith TestEnvironment
|
2022-04-26 16:47:30 +03:00
|
|
|
tests opts = do
|
2022-08-08 15:20:08 +03:00
|
|
|
let shouldBe :: IO Value -> Value -> IO ()
|
|
|
|
shouldBe = shouldReturnYaml opts
|
|
|
|
|
|
|
|
describe "Inserting into varchar columns" do
|
|
|
|
it "Insert into varchar column with non ASCII value" $ \testEnvironment -> do
|
|
|
|
let expected :: Value
|
|
|
|
expected =
|
|
|
|
[yaml|
|
|
|
|
data:
|
|
|
|
insert_hasura_test:
|
|
|
|
returning:
|
|
|
|
- id: 1
|
|
|
|
test: "££££"
|
|
|
|
affected_rows: 1
|
|
|
|
|
|
|
|
|]
|
|
|
|
|
|
|
|
actual :: IO Value
|
|
|
|
actual =
|
|
|
|
postGraphql
|
|
|
|
testEnvironment
|
|
|
|
[graphql|
|
|
|
|
mutation {
|
|
|
|
insert_hasura_test(objects:
|
|
|
|
[ { id: 1, test: "££££" }
|
|
|
|
]
|
|
|
|
) {
|
|
|
|
affected_rows
|
|
|
|
returning {
|
|
|
|
id
|
|
|
|
test
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|]
|
|
|
|
|
|
|
|
actual `shouldBe` expected
|
|
|
|
|
|
|
|
it "Insert into collated varchar column with non ASCII value" \testEnvironment -> do
|
|
|
|
let expected :: Value
|
|
|
|
expected =
|
|
|
|
[yaml|
|
|
|
|
data:
|
|
|
|
insert_hasura_test_bin:
|
|
|
|
returning:
|
|
|
|
- id: 1
|
|
|
|
test: "££££"
|
|
|
|
affected_rows: 1
|
|
|
|
|]
|
|
|
|
|
|
|
|
actual :: IO Value
|
|
|
|
actual =
|
|
|
|
postGraphql
|
|
|
|
testEnvironment
|
|
|
|
[graphql|
|
|
|
|
mutation {
|
|
|
|
insert_hasura_test_bin(objects:
|
|
|
|
[ { id: 1, test: "££££" }
|
|
|
|
]
|
|
|
|
) {
|
|
|
|
affected_rows
|
|
|
|
returning {
|
|
|
|
id
|
|
|
|
test
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|]
|
|
|
|
|
|
|
|
actual `shouldBe` expected
|