Skip to content

Commit

Permalink
Added test and now strips whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
The1Penguin committed May 30, 2024
1 parent f4818cc commit 30700ea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Model/Linsen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

module Model.Linsen
(
fetchAndCreateLinsen
parse
, fetchAndCreateLinsen
)
where

Expand All @@ -24,7 +25,8 @@ import Data.Bifunctor ( first )
import qualified Data.ByteString.Lazy.Char8 as BL8
import Data.Functor ( (<&>) )
import Data.Text.Lazy ( Text
, replace )
, replace
, strip )
import Data.Thyme.Calendar ( Day )
import Network.HTTP.Req
import Model.Types ( NoMenu(..)
Expand Down Expand Up @@ -86,7 +88,7 @@ parse day =
>=> \case
[] -> pure mempty
vs -> last vs .: "text"
<&> replace "/ " ", "
<&> strip . replace "/ " ", "

fetchAndCreateLinsen
:: (MonadHttp m, MonadIO m, MonadThrow m)
Expand Down
20 changes: 20 additions & 0 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Data.Aeson ( decode )
import Data.Maybe ( fromJust )
import Data.Thyme.Time.Core ( fromGregorian )
import Model.Karen ( parse )
import qualified Model.Linsen as L ( parse )
import Model.Types ( Menu(..)
, NoMenu
)
Expand Down Expand Up @@ -48,6 +49,25 @@ main = hspec $ do
)
)

describe "Cafe Linsen" $ it
"parses a blob of JSON without error"
(do
s1 <- BL.readFile "test/linsen.json"
testFun
[ Menu
(T.pack "Natt Överbakad Högrev.")
(T.pack "Rotfrukter, Timjansky, Persilja, Pommes Chateau.")
, Menu
(T.pack "Stekt Fisk.")
(T.pack "Remouladsås, Citron, Dill, Picklade Morötter, Rostad Potatis.")
, Menu
(T.pack "Chana Masala.")
(T.pack "Kikärtor, Grönsaker, Potatis Pakora, Nannbröd, Ris")
] (L.parse
(fromGregorian 2024 05 31)
(fromJust $ decode s1))
)

describe "The Wijkander's"
$ it "Parses two blobs of HTML correctly on fridays"
$ do
Expand Down
Loading

0 comments on commit 30700ea

Please sign in to comment.