git.iko.soy/typeable/swagger2
on master help sign in
Add Contact and License tests, simplify spec
commitfc398d525bd7b2f346249ce896d83cd91a6d3495 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateSat 7 Nov 2015, 19:07 (11 years ago) parent8e165b5
1 file changed+55−15
test/Data/SwaggerSpec.hs+55−15
test/Data/SwaggerSpec.hs+55−15
@@ -9,19 +9,35 @@ import Data.Swagger
99import Test.Hspec
1010import Test.Hspec.HUnit
1111
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+
1232infoExample :: SwaggerInfo
1333infoExample = SwaggerInfo
1434 { swaggerInfoTitle = "Swagger Sample App"
1535 , swaggerInfoDescription = Just "This is a sample server Petstore server."
1636 , swaggerInfoTermsOfService = Just "http://swagger.io/terms/"
17− , swaggerInfoContact = Just contact
18− , swaggerInfoLicense = Just license
37+ , swaggerInfoContact = Just contactExample
38+ , swaggerInfoLicense = Just licenseExample
1939 , swaggerInfoVersion = "1.0.1" }
2040 where
21− contact = SwaggerContact
22− { swaggerContactName = Just "API Support"
23− , swaggerContactUrl = Just (URL "http://www.swagger.io/support")
24− , swaggerContactEmail = Just "support@swagger.io" }
2541 license = SwaggerLicense
2642 { swaggerLicenseName = "Apache 2.0"
2743 , swaggerLicenseUrl = Just (URL "http://www.apache.org/licenses/LICENSE-2.0.html") }
@@ -45,14 +61,38 @@ infoExampleJSON = [aesonQQ|
4561}
4662|]
4763
48−spec :: Spec
49−spec = do
50− describe "Info Object" $ do
51− it "encodes correctly" $ do
52− toJSON infoExample `shouldBe` infoExampleJSON
53− it "decodes correctly" $ do
54− fromJSON infoExampleJSON `shouldBe` Success infoExample
64+-- =======================================================================
65+-- Contact object
66+-- =======================================================================
5567
56−main :: IO ()
57−main = hspec spec
68+contactExample :: SwaggerContact
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+|]
5882
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+|]