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

Fix kåren misshap from today #133

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Model/Karen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ parse lang =
menuParser :: Value -> Parser Menu
menuParser = withObject "Menu Object" $ \obj ->
Menu
<$> (obj .: "dishType" >>= (.: "name"))
<$> (obj .: "dishType" >>= maybe (pure "Unknown menu") (.: "name"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean that Kåren has changed the payload to sometimes not return an object with a "name"-field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This occured once, which was the morning of today, the 14th of august. Later, around ten, the payload was updated and looked as it has done before. This is a precaution if it would happen again.

<*> ((obj .: "displayNames") >>= withArray
"An array of meal names"
( mapM
Expand Down
22 changes: 22 additions & 0 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ main = hspec $ do
)
)

describe "The Karen Express" $ it
"parses a blob of JSON without error, but it has an dish without dishType"
( testFun
(Right [ Menu
(T.pack "Unknown menu")
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh. I see. Lovely surprise!

(T.pack "Fläskfilé, svampsås & rostad klyftpotatis")
, Menu
(T.pack "Greens")
(T.pack "Bönburgare, syrad vitkål- morot, vitlöksdressing & rostad potatis")
, Menu
(T.pack "Street food")
(T.pack "Färskost bakad fisk, vitvinssås, broccoli, potatis")
, Menu
(T.pack "Nordic")
(T.pack "Köttbullar, gräddsås, potatispuré, rårörda lingon, pressgurka")
])
$ parse
"Swedish"
(fromJust . decode $ BL8.pack "{\"data\":{\"dishOccurrencesByTimeRange\":[{\"dish\":{\"name\":\"Fl\195\164skfil\195\169, svamps\195\165s & rostad klyftpotatis\"},\"dishType\":null,\"displayNames\":[{\"categoryName\":\"Swedish\",\"name\":\"Fl\195\164skfil\195\169, svamps\195\165s & rostad klyftpotatis\"}],\"startDate\":\"08/14/2024 00:00:00\"},{\"dish\":{\"name\":\"B\195\182nbiff, rostad matvetesallad, purjol\195\182k, citroncr\195\168me\\n\"},\"dishType\":{\"name\":\"Greens\"},\"displayNames\":[{\"categoryName\":\"Swedish\",\"name\":\"B\195\182nburgare, syrad vitk\195\165l- morot, vitl\195\182ksdressing & rostad potatis\"},{\"categoryName\":\"English\",\"name\":\"Beanburger, pickled cabbage- carrot, garlic dressin & roasted potatoe\"}],\"startDate\":\"08/14/2024 00:00:00\"},{\"dish\":{\"name\":\"Bakad fisk, vitvinss\195\165s, potatispur\195\169\"},\"dishType\":{\"name\":\"Street food\"},\"displayNames\":[{\"categoryName\":\"Swedish\",\"name\":\"F\195\164rskost bakad fisk, vitvinss\195\165s, broccoli, potatis\"},{\"categoryName\":\"English\",\"name\":\"Cream cheese baked fish, whitewine sauce, broccoli, potatoes\"}],\"startDate\":\"08/14/2024 00:00:00\"},{\"dish\":{\"name\":\"K\195\182ttbullar, gr\195\164dds\195\165s, potatispur\195\169, lingon\"},\"dishType\":{\"name\":\"Nordic\"},\"displayNames\":[{\"categoryName\":\"English\",\"name\":\"Meat balls, cream sauce, mashed potato, lingonberries, pickled cucumber\"},{\"categoryName\":\"Swedish\",\"name\":\"K\195\182ttbullar, gr\195\164dds\195\165s, potatispur\195\169, r\195\165r\195\182rda lingon, pressgurka\"}],\"startDate\":\"08/14/2024 00:00:00\"}]}}"
)
)

describe "Cafe Linsen" $ it
"parses a blob of JSON without error"
(do
Expand Down
Loading