graphql-engine/server/tests-hspec/Test/SerializationSpec.hs
Samir Talwar c2d0d272ee server: Create the BigQuery test tables and data in one go.
This has a couple of advantages:

1.  One query is probably faster than many.
2.  Creating a table with data is valid on the BigQuery sandbox (free tier); `INSERT INTO` is not.
3.  We eat fewer resources by not running any DML, and so should hit usage caps less often.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4867
GitOrigin-RevId: 70537d5b306e5231beb8ae197a95bd8ea995e1e9
2022-06-28 08:40:33 +00:00

98 lines
2.5 KiB
Haskell

{-# 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
import Harness.Test.Schema (table)
import Harness.Test.Schema qualified as Schema
import Harness.TestEnvironment (TestEnvironment)
import Test.Hspec (SpecWith, describe, it)
import Prelude
--------------------------------------------------------------------------------
-- Preamble
spec :: SpecWith TestEnvironment
spec =
Context.run
[ Context.Context
{ name = Context.Backend Context.BigQuery,
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
setup = bigquerySetup,
teardown = Bigquery.teardown [author],
customOptions = Nothing
}
]
tests
author :: Schema.Table
author = table "author"
bigquerySetup :: (TestEnvironment, ()) -> IO ()
bigquerySetup (testEnvironment, _) = do
sourceMetadata <- Bigquery.defaultSourceMetadata
GraphqlEngine.postMetadata_ testEnvironment sourceMetadata
Bigquery.runSql_
[sql|
CREATE TABLE hasura.author (
id INT,
name STRING,
tax_id DECIMAL,
total_books BIGDECIMAL
) AS (SELECT * FROM UNNEST([
STRUCT(1 AS id, 'sibi' AS name, 5555555555555556666 AS tax_id, 5555555555555556666 AS total_books)
]));
|]
Bigquery.trackTable testEnvironment author
tests :: Context.Options -> SpecWith TestEnvironment
tests opts = describe "SerializationSpec" $ do
it "serde Decimal column" $ \testEnvironment ->
shouldReturnYaml
opts
( GraphqlEngine.postGraphql
testEnvironment
[graphql|
query MyQuery {
hasura_author(where: {tax_id: {_eq: 5555555555555556666}}) {
id
tax_id
}
}|]
)
[yaml|
data:
hasura_author:
- tax_id: "5555555555555556666"
id: "1"
|]
it "serde BigDecimal column" $ \testEnvironment ->
shouldReturnYaml
opts
( GraphqlEngine.postGraphql
testEnvironment
[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"
|]