27 date trunc postgres (#181)

* write test case

* weird

* better error message

* rename, fix
This commit is contained in:
Matt Parsons 2020-03-30 12:55:19 -06:00 committed by GitHub
parent b6279ca9f2
commit 9e643acb3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -489,7 +489,11 @@ testAggregateFunctions = do
testPostgresModule :: Spec
testPostgresModule = do
<<<<<<< HEAD
describe "date_trunc" $ modifyMaxSuccess (`div` 10) $ do
=======
describe "date_trunc" $ do
>>>>>>> master
prop "works" $ \listOfDateParts -> run $ do
let
utcTimes =
@ -511,6 +515,9 @@ testPostgresModule = do
for_ vals $ \(idx, utcTime) -> do
insertKey idx (DateTruncTest utcTime)
-- Necessary to get the test to pass; see the discussion in
-- https://github.com/bitemyapp/esqueleto/pull/180
rawExecute "SET TIME ZONE 'UTC'" []
ret <-
fmap (Map.fromList . coerce :: _ -> Map DateTruncTestId (UTCTime, UTCTime)) $
select $
@ -526,14 +533,14 @@ testPostgresModule = do
case Map.lookup idx ret of
Nothing ->
expectationFailure "index not found"
Just (original, expected) -> do
Just (original, truncated) -> do
utcTime `shouldBe` original
if utctDay utcTime == utctDay expected
if utctDay utcTime == utctDay truncated
then
utctDay utcTime `shouldBe` utctDay expected
utctDay utcTime `shouldBe` utctDay truncated
else
-- use this if/else to get a beter error message
utcTime `shouldBe` expected
-- use this if/else to get a better error message
utcTime `shouldBe` truncated
describe "PostgreSQL module" $ do
describe "Aggregate functions" testAggregateFunctions