Skip to content

Commit b9b6198

Browse files
committed
test: SessionName ToJSON/ToSchema
1 parent 25179de commit b9b6198

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

primer-service/primer-service.cabal

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cabal-version: 2.4
1+
cabal-version: 3.0
22
name: primer-service
33
version: 0.7.2.0
44
license: AGPL-3.0-or-later
@@ -12,14 +12,12 @@ category: Web
1212

1313
library
1414
exposed-modules:
15+
Primer.OpenAPI
1516
Primer.Pagination
1617
Primer.Server
1718

1819
hs-source-dirs: src
19-
other-modules:
20-
Primer.OpenAPI
21-
Servant.OpenApi.OperationId
22-
20+
other-modules: Servant.OpenApi.OperationId
2321
default-language: GHC2021
2422
default-extensions:
2523
NoImplicitPrelude
@@ -114,7 +112,10 @@ test-suite service-test
114112
type: exitcode-stdio-1.0
115113
main-is: Test.hs
116114
hs-source-dirs: test
117-
other-modules: Tests.Pagination
115+
other-modules:
116+
Tests.OpenAPI
117+
Tests.Pagination
118+
118119
default-language: GHC2021
119120
default-extensions:
120121
NoImplicitPrelude
@@ -133,13 +134,17 @@ test-suite service-test
133134
, aeson
134135
, base
135136
, hasql
137+
, hedgehog ^>=1.1.1
138+
, openapi3 >=3.2 && <=3.3
136139
, postgres-options ^>=0.2
137140
, primer
141+
, primer:primer-hedgehog
138142
, primer-rel8
139143
, primer-service
140144
, rel8 ^>=1.3
141145
, tasty ^>=1.4.1
142146
, tasty-discover ^>=4.2.4
147+
, tasty-hedgehog ^>=1.2.0
143148
, tasty-hunit ^>=0.10.0
144149
, temporary ^>=1.3
145150
, text

primer-service/test/Tests/OpenAPI.hs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module Tests.OpenAPI where
2+
3+
import Data.Aeson (ToJSON)
4+
import Data.OpenApi (ToSchema, validatePrettyToJSON)
5+
import Hedgehog (Gen, annotateShow, failure, forAll)
6+
import Hedgehog.Gen qualified as G
7+
import Hedgehog.Range qualified as R
8+
import Primer.Database (safeMkSessionName)
9+
import Primer.OpenAPI ()
10+
import Tasty (Property, property)
11+
12+
import Foreword
13+
14+
testToJSON :: (ToJSON a, ToSchema a, Show a) => Gen a -> Property
15+
testToJSON g = property $ do
16+
x <- forAll g
17+
case validatePrettyToJSON x of
18+
Nothing -> pure ()
19+
Just errs -> annotateShow errs >> failure
20+
21+
tasty_SessionName :: Property
22+
tasty_SessionName = testToJSON $ safeMkSessionName <$> G.text (R.linear 1 100) G.unicode

0 commit comments

Comments
 (0)