2022-04-13 20:08:46 +03:00
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
|
|
|
|
-- | Serialization test for specific data types
|
|
|
|
module Test.SerializationSpec (spec) where
|
|
|
|
|
|
|
|
import Harness.Backend.BigQuery qualified as Bigquery
|
|
|
|
import Harness.GraphqlEngine qualified as GraphqlEngine
|
|
|
|
import Harness.Quoter.Graphql (graphql)
|
|
|
|
import Harness.Quoter.Sql
|
|
|
|
import Harness.Quoter.Yaml (shouldReturnYaml, yaml)
|
|
|
|
import Harness.Test.Context qualified as Context
|
2022-06-17 11:44:04 +03:00
|
|
|
import Harness.Test.Schema (table)
|
2022-04-13 20:08:46 +03:00
|
|
|
import Harness.Test.Schema qualified as Schema
|
2022-04-20 20:15:42 +03:00
|
|
|
import Harness.TestEnvironment (TestEnvironment)
|
2022-04-13 20:08:46 +03:00
|
|
|
import Test.Hspec (SpecWith, describe, it)
|
|
|
|
import Prelude
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Preamble
|
|
|
|
|
2022-04-20 20:15:42 +03:00
|
|
|
spec :: SpecWith TestEnvironment
|
2022-04-13 20:08:46 +03:00
|
|
|
spec =
|
|
|
|
Context.run
|
|
|
|
[ Context.Context
|
|
|
|
{ name = Context.Backend Context.BigQuery,
|
2022-04-20 20:15:42 +03:00
|
|
|
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
2022-05-24 20:07:55 +03:00
|
|
|
setup = bigquerySetup,
|
|
|
|
teardown = Bigquery.teardown [author],
|
2022-04-19 14:36:48 +03:00
|
|
|
customOptions = Nothing
|
2022-04-13 20:08:46 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
tests
|
|
|
|
|
2022-05-24 20:07:55 +03:00
|
|
|
author :: Schema.Table
|
2022-06-17 11:44:04 +03:00
|
|
|
author = table "author"
|
2022-04-13 20:08:46 +03:00
|
|
|
|
2022-05-24 20:07:55 +03:00
|
|
|
bigquerySetup :: (TestEnvironment, ()) -> IO ()
|
|
|
|
bigquerySetup (testEnvironment, _) = do
|
2022-04-13 20:08:46 +03:00
|
|
|
sourceMetadata <- Bigquery.defaultSourceMetadata
|
2022-04-20 20:15:42 +03:00
|
|
|
GraphqlEngine.postMetadata_ testEnvironment sourceMetadata
|
2022-04-13 20:08:46 +03:00
|
|
|
|
|
|
|
Bigquery.runSql_
|
|
|
|
[sql|
|
|
|
|
CREATE TABLE hasura.author (
|
|
|
|
id INT,
|
|
|
|
name STRING,
|
|
|
|
tax_id DECIMAL,
|
2022-04-19 14:36:48 +03:00
|
|
|
total_books BIGDECIMAL
|
2022-06-28 11:39:24 +03:00
|
|
|
) AS (SELECT * FROM UNNEST([
|
|
|
|
STRUCT(1 AS id, 'sibi' AS name, 5555555555555556666 AS tax_id, 5555555555555556666 AS total_books)
|
|
|
|
]));
|
2022-04-13 20:08:46 +03:00
|
|
|
|]
|
|
|
|
|
2022-05-24 20:07:55 +03:00
|
|
|
Bigquery.trackTable testEnvironment author
|
2022-04-13 20:08:46 +03:00
|
|
|
|
2022-04-20 20:15:42 +03:00
|
|
|
tests :: Context.Options -> SpecWith TestEnvironment
|
2022-04-13 20:08:46 +03:00
|
|
|
tests opts = describe "SerializationSpec" $ do
|
2022-04-20 20:15:42 +03:00
|
|
|
it "serde Decimal column" $ \testEnvironment ->
|
2022-04-13 20:08:46 +03:00
|
|
|
shouldReturnYaml
|
|
|
|
opts
|
|
|
|
( GraphqlEngine.postGraphql
|
2022-04-20 20:15:42 +03:00
|
|
|
testEnvironment
|
2022-04-13 20:08:46 +03:00
|
|
|
[graphql|
|
|
|
|
query MyQuery {
|
|
|
|
hasura_author(where: {tax_id: {_eq: 5555555555555556666}}) {
|
|
|
|
id
|
|
|
|
tax_id
|
|
|
|
}
|
|
|
|
}|]
|
|
|
|
)
|
|
|
|
[yaml|
|
|
|
|
data:
|
|
|
|
hasura_author:
|
|
|
|
- tax_id: "5555555555555556666"
|
2022-04-19 14:36:48 +03:00
|
|
|
id: "1"
|
|
|
|
|]
|
2022-04-20 20:15:42 +03:00
|
|
|
it "serde BigDecimal column" $ \testEnvironment ->
|
2022-04-19 14:36:48 +03:00
|
|
|
shouldReturnYaml
|
|
|
|
opts
|
|
|
|
( GraphqlEngine.postGraphql
|
2022-04-20 20:15:42 +03:00
|
|
|
testEnvironment
|
2022-04-19 14:36:48 +03:00
|
|
|
[graphql|
|
|
|
|
query MyQuery {
|
|
|
|
hasura_author(where: {total_books: {_eq: 5555555555555556666}}) {
|
|
|
|
id
|
|
|
|
tax_id
|
|
|
|
total_books
|
|
|
|
}
|
|
|
|
}|]
|
|
|
|
)
|
|
|
|
[yaml|
|
|
|
|
data:
|
|
|
|
hasura_author:
|
|
|
|
- tax_id: "5555555555555556666"
|
|
|
|
total_books: "5555555555555556666"
|
|
|
|
id: "1"
|
2022-04-13 20:08:46 +03:00
|
|
|
|]
|