|
| 1 | +{-# LANGUAGE QuasiQuotes #-} |
| 2 | +{-# LANGUAGE RecordWildCards #-} |
| 3 | + |
| 4 | +-- | Tests around Postgres-specific database types |
| 5 | +module Test.PostgresTypesSpec (spec) where |
| 6 | + |
| 7 | +import Harness.Backend.Postgres as Postgres |
| 8 | +import Harness.GraphqlEngine qualified as GraphqlEngine |
| 9 | +import Harness.Quoter.Graphql |
| 10 | +import Harness.Quoter.Sql |
| 11 | +import Harness.Quoter.Yaml |
| 12 | +import Harness.Test.Context qualified as Context |
| 13 | +import Harness.TestEnvironment (TestEnvironment) |
| 14 | +import Test.Hspec |
| 15 | +import Prelude |
| 16 | + |
| 17 | +-------------------------------------------------------------------------------- |
| 18 | +-- Preamble |
| 19 | + |
| 20 | +spec :: SpecWith TestEnvironment |
| 21 | +spec = |
| 22 | + Context.run |
| 23 | + [ Context.Context |
| 24 | + { name = Context.Backend Context.Postgres, |
| 25 | + mkLocalTestEnvironment = Context.noLocalTestEnvironment, |
| 26 | + setup = postgresSetup, |
| 27 | + teardown = postgresTeardown, |
| 28 | + customOptions = Nothing |
| 29 | + } |
| 30 | + ] |
| 31 | + tests |
| 32 | + |
| 33 | +-------------------------------------------------------------------------------- |
| 34 | +-- Postgres |
| 35 | + |
| 36 | +postgresSetup :: (TestEnvironment, ()) -> IO () |
| 37 | +postgresSetup (testEnvironment, _) = do |
| 38 | + -- Clear and reconfigure the metadata |
| 39 | + GraphqlEngine.setSource testEnvironment Postgres.defaultSourceMetadata |
| 40 | + |
| 41 | + -- Setup tables |
| 42 | + Postgres.run_ |
| 43 | + [sql| |
| 44 | +create table timestamp_test ( |
| 45 | + id serial primary key, |
| 46 | + time timestamptz |
| 47 | +); |
| 48 | +|] |
| 49 | + |
| 50 | + -- Track the tables |
| 51 | + GraphqlEngine.post_ |
| 52 | + testEnvironment |
| 53 | + "/v1/metadata" |
| 54 | + [yaml| |
| 55 | +type: postgres_track_table |
| 56 | +args: |
| 57 | + source: postgres |
| 58 | + table: |
| 59 | + schema: hasura |
| 60 | + name: timestamp_test |
| 61 | +|] |
| 62 | + |
| 63 | +postgresTeardown :: (TestEnvironment, ()) -> IO () |
| 64 | +postgresTeardown _ = do |
| 65 | + Postgres.run_ |
| 66 | + [sql| |
| 67 | +DROP TABLE hasura.timestamp_test; |
| 68 | +|] |
| 69 | + |
| 70 | +-------------------------------------------------------------------------------- |
| 71 | +-- Tests |
| 72 | + |
| 73 | +tests :: Context.Options -> SpecWith TestEnvironment |
| 74 | +tests opts = do |
| 75 | + it "doesn't mess up timestamps on insertion" $ \testEnvironment -> |
| 76 | + shouldReturnYaml |
| 77 | + opts |
| 78 | + ( GraphqlEngine.postGraphql |
| 79 | + testEnvironment |
| 80 | + [graphql| |
| 81 | +mutation { |
| 82 | + insert_hasura_timestamp_test(objects:[{ |
| 83 | + time: "0001-01-01T00:00:57Z" |
| 84 | + }]) { |
| 85 | + returning { |
| 86 | + time |
| 87 | + } |
| 88 | + } |
| 89 | +} |
| 90 | +|] |
| 91 | + ) |
| 92 | + [yaml| |
| 93 | +data: |
| 94 | + insert_hasura_timestamp_test: |
| 95 | + returning: |
| 96 | + - time: "0001-01-01T00:00:57+00:00" |
| 97 | +|] |
0 commit comments