64 lines
2.5 KiB
Haskell
64 lines
2.5 KiB
Haskell
module Feature.OpenApi.RootSpec where
|
|
|
|
import Network.HTTP.Types
|
|
|
|
import Test.Hspec hiding (pendingWith)
|
|
import Test.Hspec.Wai
|
|
import Test.Hspec.Wai.JSON
|
|
|
|
import PostgREST.Config (AppConfig (..))
|
|
import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (..))
|
|
import PostgREST.Version (prettyVersion)
|
|
|
|
import Protolude hiding (get)
|
|
import SpecHelper
|
|
|
|
spec :: SpecWithConfig
|
|
spec withConfig = withConfig (baseCfg
|
|
{ configDbRootSpec = Just $ QualifiedIdentifier mempty "root"
|
|
, configDbSchemas = "test" :| ["v1"]
|
|
, configOpenApiServerProxyUri = Just "https://example.com/base"
|
|
}) $
|
|
describe "root spec function" $ do
|
|
it "accepts application/openapi+json" $ do
|
|
request methodGet "/"
|
|
[("Accept","application/openapi+json")] "" `shouldRespondWith`
|
|
[json|{
|
|
"swagger": "2.0",
|
|
"info": {"title": "PostgREST API", "description": "This is a dynamic API generated by PostgREST"},
|
|
"pgrst_server_host": "localhost",
|
|
"pgrst_server_port": "3000",
|
|
"pgrst_openapi_server_proxy_uri": "https://example.com/base",
|
|
"pgrst_db_schemas": ["test", "v1"],
|
|
"pgrst_version": #{decodeUtf8 prettyVersion}
|
|
}|]
|
|
{ matchHeaders = ["Content-Type" <:> "application/openapi+json; charset=utf-8"] }
|
|
|
|
it "accepts application/json" $ do
|
|
request methodGet "/"
|
|
[("Accept","application/json")] "" `shouldRespondWith`
|
|
[json|{
|
|
"swagger": "2.0",
|
|
"info": {"title": "PostgREST API", "description": "This is a dynamic API generated by PostgREST"},
|
|
"pgrst_server_host": "localhost",
|
|
"pgrst_server_port": "3000",
|
|
"pgrst_openapi_server_proxy_uri": "https://example.com/base",
|
|
"pgrst_db_schemas": ["test", "v1"],
|
|
"pgrst_version": #{decodeUtf8 prettyVersion}
|
|
}|]
|
|
{ matchHeaders = ["Content-Type" <:> "application/json; charset=utf-8"] }
|
|
|
|
it "returns null GUCs on non-root paths" $ do
|
|
request methodGet "/rpc/root"
|
|
[("Accept","application/openapi+json")] "" `shouldRespondWith`
|
|
[json|{
|
|
"swagger": "2.0",
|
|
"info": {"title": "PostgREST API", "description": "This is a dynamic API generated by PostgREST"},
|
|
"pgrst_server_host": null,
|
|
"pgrst_server_port": null,
|
|
"pgrst_openapi_server_proxy_uri": null,
|
|
"pgrst_db_schemas": null,
|
|
"pgrst_version": null
|
|
}|]
|
|
{ matchHeaders = ["Content-Type" <:> "application/openapi+json; charset=utf-8"] }
|