Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linsen, you have arrived #126

Merged
merged 12 commits into from
Jun 4, 2024
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests <3

"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
Loading