2023-03-30 18:52:20 +03:00
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
|
|
|
|
module Hasura.SQL.BackendMapSpec (spec) where
|
|
|
|
|
|
|
|
import Autodocodec (parseJSONViaCodec, toJSONViaCodec)
|
|
|
|
import Data.Aeson.QQ (aesonQQ)
|
|
|
|
import Data.Aeson.Types (parseEither)
|
|
|
|
import Data.Either.Combinators (fromRight')
|
|
|
|
import Data.Map.Strict qualified as Map
|
|
|
|
import Data.Maybe (fromJust)
|
|
|
|
import Hasura.Backends.DataConnector.Adapter.Types (DataConnectorOptions (..), mkDataConnectorName)
|
|
|
|
import Hasura.Prelude
|
2023-04-24 21:35:48 +03:00
|
|
|
import Hasura.RQL.Types.BackendType (BackendType (..))
|
2023-03-30 18:52:20 +03:00
|
|
|
import Hasura.RQL.Types.Metadata.Common (BackendConfigWrapper (BackendConfigWrapper))
|
|
|
|
import Hasura.SQL.BackendMap (BackendMap)
|
|
|
|
import Hasura.SQL.BackendMap qualified as BM
|
|
|
|
import Language.GraphQL.Draft.Syntax qualified as GQL
|
|
|
|
import Servant.Client qualified as S
|
|
|
|
import Test.Hspec
|
|
|
|
import Test.Hspec.Expectations.Json (shouldBeJson)
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = describe "BackendMap" do
|
|
|
|
it "serializes via Autodocodec" do
|
|
|
|
let mysqlConfig = BM.singleton @'MySQL @BackendConfigWrapper (BackendConfigWrapper ())
|
|
|
|
let dataconnectorConfig =
|
|
|
|
BM.singleton @'DataConnector @BackendConfigWrapper
|
|
|
|
( BackendConfigWrapper $
|
|
|
|
Map.singleton
|
|
|
|
(fromRight' $ mkDataConnectorName $ fromJust $ GQL.mkName "MyConnector")
|
|
|
|
( DataConnectorOptions
|
|
|
|
{ _dcoUri = fromRight' $ S.parseBaseUrl "https://somehost.org/",
|
|
|
|
_dcoDisplayName = Just "My Connector"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
let configs = mysqlConfig <> dataconnectorConfig
|
|
|
|
|
|
|
|
let expected =
|
|
|
|
[aesonQQ|
|
|
|
|
{
|
|
|
|
"mysql": [],
|
|
|
|
"dataconnector": {
|
|
|
|
"MyConnector": {
|
|
|
|
"uri": "https://somehost.org",
|
|
|
|
"display_name": "My Connector"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|]
|
|
|
|
let json = toJSONViaCodec configs
|
|
|
|
json `shouldBeJson` expected
|
|
|
|
|
|
|
|
let decoded = parseEither (parseJSONViaCodec @(BackendMap BackendConfigWrapper)) json
|
|
|
|
decoded `shouldBe` Right configs
|