summaryrefslogtreecommitdiff
path: root/test/Servant/Auth/SwaggerSpec.hs
blob: d7fa53057529dcc36d658958a576a6bfac280803 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Servant.Auth.SwaggerSpec (spec) where

import Control.Lens
import Data.Proxy
import Servant.API
import Servant.Auth.Swagger
import Data.Swagger
import Servant.Swagger
import Test.Hspec

spec :: Spec
spec = describe "HasSwagger instance" $ do

  let swag = toSwagger (Proxy :: Proxy API)

  it "adds security definitions at the top level" $ do
    length (swag ^. securityDefinitions) `shouldSatisfy` (> 0)

  it "adds security at sub-apis" $ do
    swag ^. security `shouldBe` []
    show (swag ^. paths . at "/secure") `shouldContain` "JwtSecurity"
    show (swag ^. paths . at "/insecure") `shouldNotContain` "JwtSecurity"

-- * API

type API =   "secure" :> Auth '[JWT] Int :> SecureAPI
        :<|> "insecure" :> InsecureAPI

type SecureAPI = Get '[JSON] Int :<|> ReqBody '[JSON] Int :> Post '[JSON] Int

type InsecureAPI = SecureAPI