git.iko.soy/typeable/openapi3
on master help sign in
Add Contact and License tests, simplify spec
fc398d5Nickolay Kudasov
test/Data/SwaggerSpec.hs+55−15
@@ -9,19 +9,35 @@ import Data.Swagger
9import Test.Hspec
9import Test.Hspec
10import Test.Hspec.HUnit
10import Test.Hspec.HUnit
11
11
12+(<=>) :: (Eq a, Show a, ToJSON a, FromJSON a) => a -> Value -> Spec
13+x <=> json = do
14+ it "encodes correctly" $ do
15+ toJSON x `shouldBe` json
16+ it "decodes correctly" $ do
17+ fromJSON json `shouldBe` Success x
18+
19+spec :: Spec
20+spec = do
21+ describe "License Object" $ licenseExample <=> licenseExampleJSON
22+ describe "Contact Object" $ contactExample <=> contactExampleJSON
23+ describe "Info Object" $ infoExample <=> infoExampleJSON
24+
25+main :: IO ()
26+main = hspec spec
27+
28+-- =======================================================================
29+-- Info object
30+-- =======================================================================
31+
12infoExample :: SwaggerInfo
32infoExample :: SwaggerInfo
13infoExample = SwaggerInfo
33infoExample = SwaggerInfo
14 { swaggerInfoTitle = "Swagger Sample App"
34 { swaggerInfoTitle = "Swagger Sample App"
15 , swaggerInfoDescription = Just "This is a sample server Petstore server."
35 , swaggerInfoDescription = Just "This is a sample server Petstore server."
16 , swaggerInfoTermsOfService = Just "http://swagger.io/terms/"
36 , swaggerInfoTermsOfService = Just "http://swagger.io/terms/"
17− , swaggerInfoContact = Just contact
37+ , swaggerInfoContact = Just contactExample
18− , swaggerInfoLicense = Just license
38+ , swaggerInfoLicense = Just licenseExample
19 , swaggerInfoVersion = "1.0.1" }
39 , swaggerInfoVersion = "1.0.1" }
20 where
40 where
21− contact = SwaggerContact
22− { swaggerContactName = Just "API Support"
23− , swaggerContactUrl = Just (URL "http://www.swagger.io/support")
24− , swaggerContactEmail = Just "support@swagger.io" }
25 license = SwaggerLicense
41 license = SwaggerLicense
26 { swaggerLicenseName = "Apache 2.0"
42 { swaggerLicenseName = "Apache 2.0"
27 , swaggerLicenseUrl = Just (URL "http://www.apache.org/licenses/LICENSE-2.0.html") }
43 , swaggerLicenseUrl = Just (URL "http://www.apache.org/licenses/LICENSE-2.0.html") }
@@ -45,14 +61,38 @@ infoExampleJSON = [aesonQQ|
45}
61}
46|]
62|]
47
63
48−spec :: Spec
64+-- =======================================================================
49−spec = do
65+-- Contact object
50− describe "Info Object" $ do
66+-- =======================================================================
51− it "encodes correctly" $ do
52− toJSON infoExample `shouldBe` infoExampleJSON
53− it "decodes correctly" $ do
54− fromJSON infoExampleJSON `shouldBe` Success infoExample
55
67
56−main :: IO ()
68+contactExample :: SwaggerContact
57−main = hspec spec
69+contactExample = SwaggerContact
70+ { swaggerContactName = Just "API Support"
71+ , swaggerContactUrl = Just (URL "http://www.swagger.io/support")
72+ , swaggerContactEmail = Just "support@swagger.io" }
73+
74+contactExampleJSON :: Value
75+contactExampleJSON = [aesonQQ|
76+{
77+ "name": "API Support",
78+ "url": "http://www.swagger.io/support",
79+ "email": "support@swagger.io"
80+}
81+|]
58
82
83+-- =======================================================================
84+-- License object
85+-- =======================================================================
86+
87+licenseExample :: SwaggerLicense
88+licenseExample = SwaggerLicense
89+ { swaggerLicenseName = "Apache 2.0"
90+ , swaggerLicenseUrl = Just (URL "http://www.apache.org/licenses/LICENSE-2.0.html") }
91+
92+licenseExampleJSON :: Value
93+licenseExampleJSON = [aesonQQ|
94+{
95+ "name": "Apache 2.0",
96+ "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
97+}
98+|]