2022-06-03 11:06:31 +03:00
|
|
|
module Test.CapabilitiesSpec (spec) where
|
|
|
|
|
2022-10-11 03:25:07 +03:00
|
|
|
import Hasura.Backends.DataConnector.API (Capabilities, CapabilitiesResponse (..), Config, Routes (..), capabilitiesCase, validateConfigAgainstConfigSchema)
|
2022-06-03 11:06:31 +03:00
|
|
|
import Servant.API (NamedRoutes)
|
|
|
|
import Servant.Client (Client, (//))
|
2022-08-04 04:00:48 +03:00
|
|
|
import Test.Expectations (jsonShouldBe)
|
2022-06-03 11:06:31 +03:00
|
|
|
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
|
2022-10-11 03:25:07 +03:00
|
|
|
CapabilitiesResponse {..} <- capabilitiesGuard =<< (api // _capabilities)
|
|
|
|
_crCapabilities `jsonShouldBe` expectedCapabilities
|
2022-06-03 11:06:31 +03:00
|
|
|
|
|
|
|
it "returns a schema that can be used to validate the current config" $ do
|
2022-10-11 03:25:07 +03:00
|
|
|
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
|