Fix get_source_tables integration data connector config transformation test

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7605
GitOrigin-RevId: 02b33784375888854c3f663c3cf0a84b049682a6
This commit is contained in:
Daniel Chambers 2023-01-23 12:05:34 +11:00 committed by hasura-bot
parent cc5ee8474a
commit 0b35798fa7
10 changed files with 134 additions and 127 deletions

View File

@ -7,7 +7,7 @@ module Test.DataConnector.MockAgent.AggregateQuerySpec (spec) where
import Data.Aeson qualified as Aeson
import Data.HashMap.Strict qualified as HashMap
import Data.List.NonEmpty qualified as NE
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentTest, mockQueryResponse)
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentGraphqlTest, mockQueryResponse)
import Harness.Backend.DataConnector.Mock qualified as Mock
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
@ -85,7 +85,7 @@ sourceMetadata =
tests :: Fixture.Options -> SpecWith (TestEnvironment, Mock.MockAgentEnvironment)
tests _opts = describe "Aggregate Query Tests" $ do
mockAgentTest "works with multiple nodes fields and through array relations" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "works with multiple nodes fields and through array relations" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -124,7 +124,7 @@ tests _opts = describe "Aggregate Query Tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
Artist_aggregate:
@ -194,7 +194,7 @@ tests _opts = describe "Aggregate Query Tests" $ do
}
)
mockAgentTest "works with multiple aggregate fields and through array relations" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "works with multiple aggregate fields and through array relations" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -248,7 +248,7 @@ tests _opts = describe "Aggregate Query Tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
Invoice_aggregate:

View File

@ -10,7 +10,7 @@ import Data.Aeson qualified as Aeson
import Data.ByteString (ByteString)
import Data.HashMap.Strict qualified as HashMap
import Data.List.NonEmpty qualified as NE
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentTest, mockQueryResponse)
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentGraphqlTest, mockQueryResponse)
import Harness.Backend.DataConnector.Mock qualified as Mock
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
@ -106,7 +106,7 @@ sourceMetadata =
tests :: Fixture.Options -> SpecWith (TestEnvironment, Mock.MockAgentEnvironment)
tests _opts = describe "Basic Tests" $ do
mockAgentTest "works with simple object query" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "works with simple object query" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -127,7 +127,7 @@ tests _opts = describe "Basic Tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
albums:
@ -158,7 +158,7 @@ tests _opts = describe "Basic Tests" $ do
}
)
mockAgentTest "works with order_by id" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "works with order_by id" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -185,7 +185,7 @@ tests _opts = describe "Basic Tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
albums:
@ -220,7 +220,7 @@ tests _opts = describe "Basic Tests" $ do
}
)
mockAgentTest "works with an exists-based permissions filter" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "works with an exists-based permissions filter" $ \performGraphqlRequest -> do
let headers =
[ ("X-Hasura-Role", testRoleName),
("X-Hasura-EmployeeId", "1")
@ -246,7 +246,7 @@ tests _opts = describe "Basic Tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
Customer:

View File

@ -9,7 +9,7 @@ module Test.DataConnector.MockAgent.CustomScalarsSpec (spec) where
import Data.Aeson qualified as Aeson
import Data.HashMap.Strict qualified as HashMap
import Data.List.NonEmpty qualified as NE
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentTest, mockQueryResponse)
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentGraphqlTest, mockQueryResponse)
import Harness.Backend.DataConnector.Mock qualified as Mock
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
@ -52,7 +52,7 @@ sourceMetadata =
tests :: Fixture.Options -> SpecWith (TestEnvironment, Mock.MockAgentEnvironment)
tests _opts = describe "Custom scalar parsing tests" $ do
mockAgentTest "works with simple object query" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "works with simple object query" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -71,7 +71,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
MyCustomScalarsTable:
@ -110,7 +110,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
}
)
mockAgentTest "parses scalar literals in where queries" \performGraphqlRequest -> do
mockAgentGraphqlTest "parses scalar literals in where queries" \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -136,7 +136,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
MyCustomScalarsTable:
@ -202,7 +202,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
}
)
mockAgentTest "fails parsing float when expecting int" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "fails parsing float when expecting int" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -218,7 +218,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
errors:
- extensions:
@ -229,7 +229,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
_mrrRecordedRequest `shouldBe` Nothing
mockAgentTest "fails parsing string when expecting int" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "fails parsing string when expecting int" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -245,7 +245,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
errors:
- extensions:
@ -256,7 +256,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
_mrrRecordedRequest `shouldBe` Nothing
mockAgentTest "fails parsing boolean when expecting int" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "fails parsing boolean when expecting int" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -272,7 +272,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
errors:
- extensions:
@ -283,7 +283,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
_mrrRecordedRequest `shouldBe` Nothing
mockAgentTest "succeeds parsing int when expecting float" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "succeeds parsing int when expecting float" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -299,14 +299,14 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
MyCustomScalarsTable:
- MyIntColumn: 42
|]
mockAgentTest "fails parsing string when expecting float" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "fails parsing string when expecting float" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -322,7 +322,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
errors:
- extensions:
@ -333,7 +333,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
_mrrRecordedRequest `shouldBe` Nothing
mockAgentTest "fails parsing boolean when expecting float" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "fails parsing boolean when expecting float" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -349,7 +349,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
errors:
- extensions:
@ -360,7 +360,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
_mrrRecordedRequest `shouldBe` Nothing
mockAgentTest "fails parsing int when expecting string" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "fails parsing int when expecting string" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -376,7 +376,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
errors:
- extensions:
@ -387,7 +387,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
_mrrRecordedRequest `shouldBe` Nothing
mockAgentTest "fails parsing float when expecting string" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "fails parsing float when expecting string" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -403,7 +403,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
errors:
- extensions:
@ -414,7 +414,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
_mrrRecordedRequest `shouldBe` Nothing
mockAgentTest "fails parsing boolean when expecting string" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "fails parsing boolean when expecting string" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -430,7 +430,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
errors:
- extensions:
@ -441,7 +441,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
_mrrRecordedRequest `shouldBe` Nothing
mockAgentTest "fails parsing int when expecting boolean" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "fails parsing int when expecting boolean" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -457,7 +457,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
errors:
- extensions:
@ -468,7 +468,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
_mrrRecordedRequest `shouldBe` Nothing
mockAgentTest "fails parsing float when expecting boolean" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "fails parsing float when expecting boolean" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -484,7 +484,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
errors:
- extensions:
@ -495,7 +495,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
_mrrRecordedRequest `shouldBe` Nothing
mockAgentTest "fails parsing string when expecting boolean" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "fails parsing string when expecting boolean" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -511,7 +511,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
errors:
- extensions:
@ -522,7 +522,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
_mrrRecordedRequest `shouldBe` Nothing
mockAgentTest "succeeds parsing int when expecting ID" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "succeeds parsing int when expecting ID" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -538,14 +538,14 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
MyCustomScalarsTable:
- MyIntColumn: 42
|]
mockAgentTest "fails parsing float when expecting ID" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "fails parsing float when expecting ID" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -561,7 +561,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
errors:
- extensions:
@ -572,7 +572,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
_mrrRecordedRequest `shouldBe` Nothing
mockAgentTest "fails parsing boolean when expecting ID" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "fails parsing boolean when expecting ID" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -588,7 +588,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
errors:
- extensions:
@ -599,7 +599,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
_mrrRecordedRequest `shouldBe` Nothing
mockAgentTest "succeeds parsing int when expecting anything" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "succeeds parsing int when expecting anything" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -615,14 +615,14 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
MyCustomScalarsTable:
- MyIntColumn: 42
|]
mockAgentTest "succeeds parsing float when expecting anything" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "succeeds parsing float when expecting anything" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -638,14 +638,14 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
MyCustomScalarsTable:
- MyIntColumn: 42
|]
mockAgentTest "succeeds parsing string when expecting anything" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "succeeds parsing string when expecting anything" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -661,14 +661,14 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
MyCustomScalarsTable:
- MyIntColumn: 42
|]
mockAgentTest "succeeds parsing boolean when expecting anything" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "succeeds parsing boolean when expecting anything" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -684,14 +684,14 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
MyCustomScalarsTable:
- MyIntColumn: 42
|]
mockAgentTest "succeeds parsing array when expecting anything" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "succeeds parsing array when expecting anything" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -707,7 +707,7 @@ tests _opts = describe "Custom scalar parsing tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
MyCustomScalarsTable:

View File

@ -9,7 +9,7 @@ module Test.DataConnector.MockAgent.ErrorSpec (spec) where
import Data.Aeson qualified as Aeson
import Data.HashMap.Strict qualified as HashMap
import Data.List.NonEmpty qualified as NE
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentTest)
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentGraphqlTest)
import Harness.Backend.DataConnector.Mock qualified as Mock
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
@ -61,7 +61,7 @@ sourceMetadata =
tests :: Fixture.Options -> SpecWith (TestEnvironment, Mock.MockAgentEnvironment)
tests _opts = describe "Error Protocol Tests" $ do
mockAgentTest "handles returned errors correctly" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "handles returned errors correctly" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -77,7 +77,7 @@ tests _opts = describe "Error Protocol Tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
errors:
-

View File

@ -7,7 +7,7 @@ import Data.Aeson qualified as Aeson
import Data.ByteString (ByteString)
import Data.HashMap.Strict qualified as HashMap
import Data.List.NonEmpty qualified as NE
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentTest, mockMutationResponse)
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentGraphqlTest, mockMutationResponse)
import Harness.Backend.DataConnector.Mock qualified as Mock
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
@ -89,7 +89,7 @@ sourceMetadata =
tests :: Fixture.Options -> SpecWith (TestEnvironment, Mock.MockAgentEnvironment)
tests _opts = do
mockAgentTest "insert multiple rows with insert permissions" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "insert multiple rows with insert permissions" $ \performGraphqlRequest -> do
let headers = [("X-Hasura-ArtistId", "2"), ("X-Hasura-Role", testRoleName)]
let graphqlRequest =
[graphql|
@ -147,7 +147,7 @@ tests _opts = do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
insert_Album:

View File

@ -8,20 +8,18 @@ module Test.DataConnector.MockAgent.MetadataApiSpec where
--------------------------------------------------------------------------------
import Data.Aeson qualified as Aeson
import Data.Aeson.KeyMap qualified as KM
import Data.IORef qualified as IORef
import Data.Aeson.Lens (_Array)
import Data.List.NonEmpty qualified as NE
import Data.Vector qualified as Vector
import Harness.Backend.DataConnector.Mock (MockRequestResults (..), mockAgentMetadataTest)
import Harness.Backend.DataConnector.Mock qualified as Mock
import Harness.GraphqlEngine qualified as GraphqlEngine
import Harness.Quoter.Yaml (yaml)
import Harness.Test.BackendType qualified as BackendType
import Harness.Test.Fixture qualified as Fixture
import Harness.TestEnvironment (GlobalTestEnvironment, TestEnvironment, getBackendTypeConfig)
import Harness.Yaml (shouldReturnYamlF)
import Hasura.Backends.DataConnector.API.V0.ConfigSchema (Config (..))
import Hasura.Prelude
import Test.Hspec (SpecWith, describe, it, pendingWith, shouldBe)
import Test.HUnit (assertFailure)
import Test.Hspec (SpecWith, describe, shouldBe)
--------------------------------------------------------------------------------
@ -57,33 +55,33 @@ sourceMetadata =
--------------------------------------------------------------------------------
tests :: Fixture.Options -> SpecWith (TestEnvironment, Mock.MockAgentEnvironment)
tests opts = do
tests _opts = do
describe "MetadataAPI Mock Tests" $ do
it "Should peform a template transform when calling _get_source_tables" $ \(testEnvironment, Mock.MockAgentEnvironment {maeRecordedRequestConfig}) -> do
let sortYamlArray :: Aeson.Value -> IO Aeson.Value
sortYamlArray (Aeson.Array a) = pure $ Aeson.Array (Vector.fromList (sort (Vector.toList a)))
sortYamlArray _ = fail "Should return Array"
mockAgentMetadataTest "Should perform a template transform when calling get_source_tables" $ \testEnvironment performMetadataRequest -> do
sourceString <-
BackendType.backendSourceName
<$> getBackendTypeConfig testEnvironment
`onNothing` assertFailure "Backend source name not found in test environment"
case BackendType.backendSourceName <$> getBackendTypeConfig testEnvironment of
Nothing -> pendingWith "Backend not found for testEnvironment"
Just sourceString -> do
queryConfig <- IORef.readIORef maeRecordedRequestConfig
IORef.writeIORef maeRecordedRequestConfig Nothing
queryConfig `shouldBe` Just (Config $ KM.fromList [("DEBUG", Aeson.Object (KM.fromList [("test", Aeson.String "data")]))])
shouldReturnYamlF
sortYamlArray
opts
( GraphqlEngine.postMetadata
testEnvironment
let request =
[yaml|
type: get_source_tables
args:
source: *sourceString
|]
)
[yaml|
MockRequestResults {..} <- performMetadataRequest Mock.chinookMock request
Aeson.toJSON _mrrRecordedRequestConfig
`shouldBe` [yaml|
DEBUG:
test: data
|]
-- The order of the results can be arbitrary, so we sort to produce a consistent view
let sortedResponse = _mrrResponse & _Array %~ (Vector.fromList . sort . Vector.toList)
sortedResponse
`shouldBe` [yaml|
- - Album
- - Artist
- - Customer

View File

@ -9,7 +9,7 @@ import Data.Aeson qualified as Aeson
import Data.ByteString (ByteString)
import Data.HashMap.Strict qualified as HashMap
import Data.List.NonEmpty qualified as NE
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentTest, mockQueryResponse)
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentGraphqlTest, mockQueryResponse)
import Harness.Backend.DataConnector.Mock qualified as Mock
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
@ -128,7 +128,7 @@ sourceMetadata =
tests :: Fixture.Options -> SpecWith (TestEnvironment, Mock.MockAgentEnvironment)
tests _opts = describe "Object Relationships Tests" $ do
mockAgentTest "works with multiple object relationships" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "works with multiple object relationships" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -165,7 +165,7 @@ tests _opts = describe "Object Relationships Tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
Track:
@ -257,7 +257,7 @@ tests _opts = describe "Object Relationships Tests" $ do
}
)
mockAgentTest "works with an order by that navigates relationships" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "works with an order by that navigates relationships" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -292,7 +292,7 @@ tests _opts = describe "Object Relationships Tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
Track:
@ -408,7 +408,7 @@ tests _opts = describe "Object Relationships Tests" $ do
}
)
mockAgentTest "works with an order by that navigates a relationship with table permissions" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "works with an order by that navigates a relationship with table permissions" $ \performGraphqlRequest -> do
let headers = [("X-Hasura-Role", testRoleName)]
let graphqlRequest =
[graphql|
@ -427,7 +427,7 @@ tests _opts = describe "Object Relationships Tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
Employee:

View File

@ -8,7 +8,7 @@ module Test.DataConnector.MockAgent.TransformedConfigurationSpec (spec) where
import Data.Aeson qualified as Aeson
import Data.HashMap.Strict qualified as HashMap
import Data.List.NonEmpty qualified as NE
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentTest, mockQueryResponse)
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentGraphqlTest, mockQueryResponse)
import Harness.Backend.DataConnector.Mock qualified as Mock
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
@ -101,7 +101,7 @@ sourceMetadata =
tests :: Fixture.Options -> SpecWith (TestEnvironment, Mock.MockAgentEnvironment)
tests _opts = describe "Transformed Configuration Tests" $ do
mockAgentTest "works with configuration transformation Kriti template" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "works with configuration transformation Kriti template" $ \performGraphqlRequest -> do
let headers = []
let graphqlRequest =
[graphql|
@ -122,7 +122,7 @@ tests _opts = describe "Transformed Configuration Tests" $ do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
albums:

View File

@ -7,7 +7,7 @@ import Data.Aeson qualified as Aeson
import Data.ByteString (ByteString)
import Data.HashMap.Strict qualified as HashMap
import Data.List.NonEmpty qualified as NE
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentTest, mockMutationResponse)
import Harness.Backend.DataConnector.Mock (AgentRequest (..), MockRequestResults (..), mockAgentGraphqlTest, mockMutationResponse)
import Harness.Backend.DataConnector.Mock qualified as Mock
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
@ -104,7 +104,7 @@ sourceMetadata =
tests :: Fixture.Options -> SpecWith (TestEnvironment, Mock.MockAgentEnvironment)
tests _opts = do
mockAgentTest "update rows with update permissions" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "update rows with update permissions" $ \performGraphqlRequest -> do
let headers = [("X-Hasura-AlbumId", "3"), ("X-Hasura-Role", testRoleName)]
let graphqlRequest =
[graphql|
@ -167,7 +167,7 @@ tests _opts = do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
update_Track:
@ -275,7 +275,7 @@ tests _opts = do
}
_mrrRecordedRequest `shouldBe` Just (Mutation expectedRequest)
mockAgentTest "update_many rows with update permissions" $ \performGraphqlRequest -> do
mockAgentGraphqlTest "update_many rows with update permissions" $ \performGraphqlRequest -> do
let headers = [("X-Hasura-AlbumId", "3"), ("X-Hasura-Role", testRoleName)]
let graphqlRequest =
[graphql|
@ -347,7 +347,7 @@ tests _opts = do
MockRequestResults {..} <- performGraphqlRequest mockConfig headers graphqlRequest
_mrrGraphqlResponse
_mrrResponse
`shouldBeYaml` [yaml|
data:
update_Track_many:

View File

@ -19,7 +19,8 @@ module Harness.Backend.DataConnector.Mock
MockRequestResults (..),
mockQueryResponse,
mockMutationResponse,
mockAgentTest,
mockAgentGraphqlTest,
mockAgentMetadataTest,
)
where
@ -145,7 +146,7 @@ mkLocalTestEnvironment _ = mkTestResource do
}
data MockRequestResults = MockRequestResults
{ _mrrGraphqlResponse :: Aeson.Value,
{ _mrrResponse :: Aeson.Value,
_mrrRecordedRequest :: Maybe AgentRequest,
_mrrRecordedRequestConfig :: Maybe API.Config
}
@ -158,12 +159,20 @@ mockMutationResponse :: API.MutationResponse -> MockConfig -> MockConfig
mockMutationResponse mutationResponse mockConfig =
mockConfig {_mutationResponse = \_ -> Right mutationResponse}
mockAgentTest :: HasCallStack => String -> ((MockConfig -> RequestHeaders -> Aeson.Value -> IO MockRequestResults) -> Expectation) -> SpecWith (Arg ((TestEnvironment, MockAgentEnvironment) -> Expectation))
mockAgentTest name testBody =
it name $ \env -> testBody (postMockAgentGraphqlWithHeaders env)
mockAgentGraphqlTest :: HasCallStack => String -> ((MockConfig -> RequestHeaders -> Aeson.Value -> IO MockRequestResults) -> Expectation) -> SpecWith (Arg ((TestEnvironment, MockAgentEnvironment) -> Expectation))
mockAgentGraphqlTest name testBody =
it name $ \(env, agentEnv) ->
let performGraphqlRequest mockConfig requestHeaders graphqlRequest = performRecordedRequest agentEnv mockConfig (GraphqlEngine.postGraphqlWithHeaders env requestHeaders graphqlRequest)
in testBody performGraphqlRequest
postMockAgentGraphqlWithHeaders :: HasCallStack => (TestEnvironment, MockAgentEnvironment) -> MockConfig -> RequestHeaders -> Aeson.Value -> IO MockRequestResults
postMockAgentGraphqlWithHeaders (testEnvironment, MockAgentEnvironment {..}) mockConfig requestHeaders graphqlRequest = do
mockAgentMetadataTest :: HasCallStack => String -> (TestEnvironment -> (MockConfig -> Aeson.Value -> IO MockRequestResults) -> Expectation) -> SpecWith (Arg ((TestEnvironment, MockAgentEnvironment) -> Expectation))
mockAgentMetadataTest name testBody =
it name $ \(env, agentEnv) ->
let performMetadataRequest mockConfig metadataRequest = performRecordedRequest agentEnv mockConfig (GraphqlEngine.postMetadata env metadataRequest)
in testBody env performMetadataRequest
performRecordedRequest :: HasCallStack => MockAgentEnvironment -> MockConfig -> IO Aeson.Value -> IO MockRequestResults
performRecordedRequest MockAgentEnvironment {..} mockConfig performRequest = do
-- Set the Agent with the 'MockConfig'
I.writeIORef maeConfig mockConfig
@ -172,10 +181,10 @@ postMockAgentGraphqlWithHeaders (testEnvironment, MockAgentEnvironment {..}) moc
I.writeIORef maeRecordedRequestConfig Nothing
-- Perform GraphQL request
graphqlResponse <- GraphqlEngine.postGraphqlWithHeaders testEnvironment requestHeaders graphqlRequest
response <- performRequest
-- Capture recordings
recordedRequest <- I.readIORef maeRecordedRequest
recordedRequestConfig <- I.readIORef maeRecordedRequestConfig
pure $ MockRequestResults graphqlResponse recordedRequest recordedRequestConfig
pure $ MockRequestResults response recordedRequest recordedRequestConfig