From 96b84786100eedceb5a0ef47f7f56311700be063 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 29 Aug 2019 15:33:36 +0200 Subject: [PATCH] chore: fix tests & hlint --- src/Handler/School.hs | 2 +- src/Utils/Lens.hs | 2 +- test/Database.hs | 12 ++++++++++++ test/ModelSpec.hs | 3 +++ test/TestImport.hs | 3 +++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Handler/School.hs b/src/Handler/School.hs index 9223689b6..c743dfae2 100644 --- a/src/Handler/School.hs +++ b/src/Handler/School.hs @@ -69,7 +69,7 @@ mkSchoolForm :: Maybe SchoolId -> Maybe SchoolForm -> Form SchoolForm mkSchoolForm mSsh template = renderAForm FormStandard $ SchoolForm <$> maybe (\f fs -> areq f fs (sfShorthand <$> template)) (\ssh f fs -> aforced f fs (unSchoolKey ssh)) mSsh ciField (fslI MsgSchoolShort) <*> areq ciField (fslI MsgSchoolName) (sfName <$> template) - <*> (Set.fromList . mapMaybe (fmap CI.mk . assertM' (not . Text.null) . Text.strip) <$> massInputListA (textField & addDatalist ldapOrgs) (const $ "") (const Nothing) ("ldap-organisations" :: Text) (fslI MsgSchoolLdapOrganisations & setTooltip MsgSchoolLdapOrganisationsTip) False (fmap CI.original . Set.toList . sfOrgUnits <$> template)) + <*> (Set.fromList . mapMaybe (fmap CI.mk . assertM' (not . Text.null) . Text.strip) <$> massInputListA (textField & addDatalist ldapOrgs) (const "") (const Nothing) ("ldap-organisations" :: Text) (fslI MsgSchoolLdapOrganisations & setTooltip MsgSchoolLdapOrganisationsTip) False (fmap CI.original . Set.toList . sfOrgUnits <$> template)) where ldapOrgs :: WidgetT UniWorX IO (Set (CI Text)) ldapOrgs = liftHandlerT . runDB $ diff --git a/src/Utils/Lens.hs b/src/Utils/Lens.hs index 7d082f255..4789c7b59 100644 --- a/src/Utils/Lens.hs +++ b/src/Utils/Lens.hs @@ -44,7 +44,7 @@ _SchoolId :: Iso' SchoolId SchoolShorthand _SchoolId = iso unSchoolKey SchoolKey _Maybe :: Iso' (Maybe ()) Bool -_Maybe = iso (maybe False $ const True) (bool Nothing (Just ())) +_Maybe = iso (is _Just) (bool Nothing (Just ())) ----------------------------------- diff --git a/test/Database.hs b/test/Database.hs index 6a02c9d2d..065f6015f 100755 --- a/test/Database.hs +++ b/test/Database.hs @@ -106,6 +106,8 @@ fillDb = do , userWarningDays = userDefaultWarningDays , userMailLanguages = MailLanguages ["en"] , userNotificationSettings = def + , userCreated = now + , userLastLdapSynchronisation = Nothing } fhamann <- insert User { userIdent = "felix.hamann@campus.lmu.de" @@ -127,6 +129,8 @@ fillDb = do , userWarningDays = userDefaultWarningDays , userMailLanguages = MailLanguages ["de"] , userNotificationSettings = def + , userCreated = now + , userLastLdapSynchronisation = Nothing } jost <- insert User { userIdent = "jost@tcs.ifi.lmu.de" @@ -148,6 +152,8 @@ fillDb = do , userWarningDays = userDefaultWarningDays , userMailLanguages = MailLanguages ["de"] , userNotificationSettings = def + , userCreated = now + , userLastLdapSynchronisation = Nothing } maxMuster <- insert User { userIdent = "max@campus.lmu.de" @@ -169,6 +175,8 @@ fillDb = do , userWarningDays = userDefaultWarningDays , userMailLanguages = MailLanguages ["de"] , userNotificationSettings = def + , userCreated = now + , userLastLdapSynchronisation = Nothing } tinaTester <- insert $ User { userIdent = "tester@campus.lmu.de" @@ -190,6 +198,8 @@ fillDb = do , userWarningDays = userDefaultWarningDays , userMailLanguages = MailLanguages ["de"] , userNotificationSettings = def + , userCreated = now + , userLastLdapSynchronisation = Nothing } svaupel <- insert User { userIdent = "vaupel.sarah@campus.lmu.de" @@ -211,6 +221,8 @@ fillDb = do , userWarningDays = userDefaultWarningDays , userMailLanguages = MailLanguages ["de"] , userNotificationSettings = def + , userCreated = now + , userLastLdapSynchronisation = Nothing } void . repsert (TermKey summer2017) $ Term { termName = summer2017 diff --git a/test/ModelSpec.hs b/test/ModelSpec.hs index 0549a5692..ecab8fe15 100644 --- a/test/ModelSpec.hs +++ b/test/ModelSpec.hs @@ -102,6 +102,9 @@ instance Arbitrary User where userMailLanguages <- arbitrary userNotificationSettings <- arbitrary + userCreated <- arbitrary + userLastLdapSynchronisation <- arbitrary + return User{..} shrink = genericShrink diff --git a/test/TestImport.hs b/test/TestImport.hs index d198ab41a..080f4782a 100644 --- a/test/TestImport.hs +++ b/test/TestImport.hs @@ -108,6 +108,7 @@ authenticateAs (Entity _ User{..}) = do createUser :: (User -> User) -> YesodExample UniWorX (Entity User) createUser adjUser = do UserDefaultConf{..} <- appUserDefaults . view appSettings <$> getTestYesod + now <- liftIO getCurrentTime let userMatrikelnummer = Nothing userAuthentication = AuthLDAP @@ -128,6 +129,8 @@ createUser adjUser = do userWarningDays = userDefaultWarningDays userMailLanguages = def userNotificationSettings = def + userCreated = now + userLastLdapSynchronisation = Nothing runDB . insertEntity $ adjUser User{..} lawsCheckHspec :: Typeable a => Proxy a -> [Proxy a -> Laws] -> Spec