From e94792195595c07a08124e778cba6785c80f92e5 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 5 Apr 2019 17:15:26 +0200 Subject: [PATCH] Fix Test --- .../Handler/SendNotification/CorrectionsAssigned.hs | 2 +- src/Jobs/Handler/SendNotification/SheetActive.hs | 2 +- src/Jobs/Handler/SendNotification/SheetInactive.hs | 4 ++-- src/Jobs/Handler/SendNotification/UserRightsUpdate.hs | 2 +- src/Model/Token.hs | 4 ++-- test.sh | 11 +++++++++++ test/Database.hs | 5 +++++ test/ModelSpec.hs | 1 + test/TestImport.hs | 3 ++- 9 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Jobs/Handler/SendNotification/CorrectionsAssigned.hs b/src/Jobs/Handler/SendNotification/CorrectionsAssigned.hs index f7943cb6c..2644a36ef 100644 --- a/src/Jobs/Handler/SendNotification/CorrectionsAssigned.hs +++ b/src/Jobs/Handler/SendNotification/CorrectionsAssigned.hs @@ -30,5 +30,5 @@ dispatchNotificationCorrectionsAssigned nUser nSheet jRecipient = do editNotifications <- mkEditNotifications jRecipient - addAlternatives $ do + addAlternatives $ providePreferredAlternative ($(ihamletFile "templates/mail/correctionsAssigned.hamlet") :: HtmlUrlI18n UniWorXMessage (Route UniWorX)) diff --git a/src/Jobs/Handler/SendNotification/SheetActive.hs b/src/Jobs/Handler/SendNotification/SheetActive.hs index 6e3618de2..1530d3e44 100644 --- a/src/Jobs/Handler/SendNotification/SheetActive.hs +++ b/src/Jobs/Handler/SendNotification/SheetActive.hs @@ -29,5 +29,5 @@ dispatchNotificationSheetActive nSheet jRecipient = userMailT jRecipient $ do editNotifications <- mkEditNotifications jRecipient - addAlternatives $ do + addAlternatives $ providePreferredAlternative ($(ihamletFile "templates/mail/sheetActive.hamlet") :: HtmlUrlI18n UniWorXMessage (Route UniWorX)) diff --git a/src/Jobs/Handler/SendNotification/SheetInactive.hs b/src/Jobs/Handler/SendNotification/SheetInactive.hs index bab937c89..21cd7aced 100644 --- a/src/Jobs/Handler/SendNotification/SheetInactive.hs +++ b/src/Jobs/Handler/SendNotification/SheetInactive.hs @@ -32,7 +32,7 @@ dispatchNotificationSheetSoonInactive nSheet jRecipient = userMailT jRecipient $ editNotifications <- mkEditNotifications jRecipient - addAlternatives $ do + addAlternatives $ providePreferredAlternative ($(ihamletFile "templates/mail/sheetSoonInactive.hamlet") :: HtmlUrlI18n UniWorXMessage (Route UniWorX)) dispatchNotificationSheetInactive :: SheetId -> UserId -> Handler () @@ -58,6 +58,6 @@ dispatchNotificationSheetInactive nSheet jRecipient = userMailT jRecipient $ do editNotifications <- mkEditNotifications jRecipient - addAlternatives $ do + addAlternatives $ providePreferredAlternative ($(ihamletFile "templates/mail/sheetInactive.hamlet") :: HtmlUrlI18n UniWorXMessage (Route UniWorX)) diff --git a/src/Jobs/Handler/SendNotification/UserRightsUpdate.hs b/src/Jobs/Handler/SendNotification/UserRightsUpdate.hs index 90e645de7..a70d167e9 100644 --- a/src/Jobs/Handler/SendNotification/UserRightsUpdate.hs +++ b/src/Jobs/Handler/SendNotification/UserRightsUpdate.hs @@ -23,6 +23,6 @@ dispatchNotificationUserRightsUpdate nUser _originalRights jRecipient = userMai setSubjectI $ MsgMailSubjectUserRightsUpdate userDisplayName -- MsgRenderer mr <- getMailMsgRenderer editNotifications <- mkEditNotifications jRecipient - addAlternatives $ do + addAlternatives $ providePreferredAlternative ($(ihamletFile "templates/mail/userRightsUpdate.hamlet") :: HtmlUrlI18n UniWorXMessage (Route UniWorX)) diff --git a/src/Model/Token.hs b/src/Model/Token.hs index a4d108714..cfaaacb55 100644 --- a/src/Model/Token.hs +++ b/src/Model/Token.hs @@ -136,8 +136,8 @@ bearerToken :: forall m. -> Maybe UTCTime -- ^ @Nothing@ means token starts to be valid immediately -> m (BearerToken (HandlerSite m)) bearerToken tokenAuthority tokenRoutes tokenAddAuth mTokenExpiresAt tokenStartsAt = do - tokenIdentifier <- liftIO $ getRandom - tokenIssuedAt <- liftIO $ getCurrentTime + tokenIdentifier <- liftIO getRandom + tokenIssuedAt <- liftIO getCurrentTime tokenIssuedBy <- getsYesod $ view instanceID defaultExpiration <- getsYesod $ view _appJWTExpiration diff --git a/test.sh b/test.sh index 09d4b3a53..f4a4da1cf 100755 --- a/test.sh +++ b/test.sh @@ -1,3 +1,14 @@ #!/usr/bin/env bash +move-back() { + mv -v .stack-work .stack-work-test + [[ -d .stack-work-build ]] && mv -v .stack-work-build .stack-work +} + +if [[ -d .stack-work-test ]]; then + [[ -d .stack-work ]] && mv -v .stack-work .stack-work-build + mv -v .stack-work-test .stack-work + trap move-back EXIT +fi + exec -- stack build --test --fast --flag uniworx:dev --flag uniworx:library-only ${@} diff --git a/test/Database.hs b/test/Database.hs index d0404df66..3943263db 100755 --- a/test/Database.hs +++ b/test/Database.hs @@ -94,6 +94,7 @@ fillDb = do { userIdent = "G.Kleen@campus.lmu.de" , userAuthentication = AuthLDAP , userLastAuthentication = Just now + , userTokensIssuedAfter = Just now , userMatrikelnummer = Nothing , userEmail = "G.Kleen@campus.lmu.de" , userDisplayName = "Gregor Kleen" @@ -111,6 +112,7 @@ fillDb = do { userIdent = "felix.hamann@campus.lmu.de" , userAuthentication = AuthLDAP , userLastAuthentication = Nothing + , userTokensIssuedAfter = Nothing , userMatrikelnummer = Nothing , userEmail = "felix.hamann@campus.lmu.de" , userDisplayName = "Felix Hamann" @@ -128,6 +130,7 @@ fillDb = do { userIdent = "jost@tcs.ifi.lmu.de" , userAuthentication = AuthLDAP , userLastAuthentication = Nothing + , userTokensIssuedAfter = Nothing , userMatrikelnummer = Nothing , userEmail = "jost@tcs.ifi.lmu.de" , userDisplayName = "Steffen Jost" @@ -145,6 +148,7 @@ fillDb = do { userIdent = "max@campus.lmu.de" , userAuthentication = AuthLDAP , userLastAuthentication = Just now + , userTokensIssuedAfter = Nothing , userMatrikelnummer = Just "1299" , userEmail = "max@campus.lmu.de" , userDisplayName = "Max Musterstudent" @@ -162,6 +166,7 @@ fillDb = do { userIdent = "tester@campus.lmu.de" , userAuthentication = AuthLDAP , userLastAuthentication = Nothing + , userTokensIssuedAfter = Nothing , userMatrikelnummer = Just "999" , userEmail = "tester@campus.lmu.de" , userDisplayName = "Tina Tester" diff --git a/test/ModelSpec.hs b/test/ModelSpec.hs index 258211f94..3850363a6 100644 --- a/test/ModelSpec.hs +++ b/test/ModelSpec.hs @@ -41,6 +41,7 @@ instance Arbitrary User where ] userAuthentication <- arbitrary userLastAuthentication <- arbitrary + userTokensIssuedAfter <- arbitrary userMatrikelnummer <- fmap pack . assertM' (not . null) <$> listOf (elements ['0'..'9']) userEmail <- CI.mk . decodeUtf8 . Email.toByteString <$> arbitrary diff --git a/test/TestImport.hs b/test/TestImport.hs index f576ccf30..4ba8082bd 100644 --- a/test/TestImport.hs +++ b/test/TestImport.hs @@ -103,11 +103,12 @@ authenticateAs (Entity _ User{..}) = do -- checking is switched off in wipeDB for those database backends which need it. createUser :: (User -> User) -> YesodExample UniWorX (Entity User) createUser adjUser = do - UserDefaultConf{..} <- appUserDefaults . appSettings <$> getTestYesod + UserDefaultConf{..} <- appUserDefaults . view appSettings <$> getTestYesod let userMatrikelnummer = Nothing userAuthentication = AuthLDAP userLastAuthentication = Nothing + userTokensIssuedAfter = Nothing userIdent = "dummy@example.invalid" userEmail = "dummy@example.invalid" userDisplayName = "Dummy Example"