graphql-engine/server/lib/dc-api/test/Test/CapabilitiesSpec.hs
Lyndon Maydwell d54bb30d3b Structured Error Protocol for Data Connectors Agents - GDW-137
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6061
Co-authored-by: Vishnu Bharathi <4211715+scriptnull@users.noreply.github.com>
GitOrigin-RevId: 855d96378030f4e01b0c74b00e20e592e51e7a49
2022-10-11 00:26:24 +00:00

23 lines
1.2 KiB
Haskell

module Test.CapabilitiesSpec (spec) where
import Hasura.Backends.DataConnector.API (Capabilities, CapabilitiesResponse (..), Config, Routes (..), capabilitiesCase, validateConfigAgainstConfigSchema)
import Servant.API (NamedRoutes)
import Servant.Client (Client, (//))
import Test.Expectations (jsonShouldBe)
import Test.Hspec (Spec, describe, it)
import Prelude
spec :: Client IO (NamedRoutes Routes) -> Config -> Capabilities -> Spec
spec api config expectedCapabilities = describe "capabilities API" $ do
it "returns the expected capabilities" $ do
CapabilitiesResponse {..} <- capabilitiesGuard =<< (api // _capabilities)
_crCapabilities `jsonShouldBe` expectedCapabilities
it "returns a schema that can be used to validate the current config" $ do
CapabilitiesResponse {..} <- capabilitiesGuard =<< (api // _capabilities)
validateConfigAgainstConfigSchema _crConfigSchemaResponse config `jsonShouldBe` []
where
defaultAction = fail "Unexpected data connector capabilities response - Unexpected Type"
errorAction e = fail $ "Unexpected data connector capabilities error response: " <> show e
capabilitiesGuard = capabilitiesCase defaultAction (pure) errorAction