Advertisement
NLinker

Ntf IO test 1

Jul 28th, 2017
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE FlexibleContexts      #-}
  2. {-# LANGUAGE MultiParamTypeClasses #-}
  3. {-# LANGUAGE OverloadedStrings     #-}
  4. {-# LANGUAGE ScopedTypeVariables   #-}
  5.  
  6. module VertigoIO.IntegrationTest where
  7.  
  8. import Control.Lens                 ((&), (.~), (^.))
  9. import Control.Monad                (forM_, void)
  10. import Control.Monad.Free           (MonadFree, iterM)
  11. import Control.Monad.Identity       (runIdentity)
  12. import Control.Monad.IO.Class       (MonadIO, liftIO)
  13. import Control.Monad.State          (MonadState, State, StateT(StateT), get, put, runState,
  14.                                      runStateT)
  15. import Control.Monad.Trans.Identity (runIdentityT)
  16. import Control.Monad.Trans.Reader   (runReaderT)
  17. import Data.Maybe                   (fromJust)
  18. import Data.Monoid                  ((<>))
  19. import Data.Text
  20. import Data.UUID                    (fromText)
  21. import Vertigo.AppM
  22. import Vertigo.Dsl.Notify
  23. import Vertigo.Dsl.RunProd
  24. import Vertigo.Dsl.RunTest
  25. import Vertigo.Ext                  (buildEnvironmentExt)
  26. import Vertigo.Token                (createToken)
  27. import Vertigo.Types.Config         (Config(Config), EnvEnum(..), enumToConfig, port)
  28. import Vertigo.Types.DeviceInfo
  29. import Vertigo.Types.User
  30.  
  31. import qualified Data.Map                       as M
  32. import qualified Vertigo.Types.Notification     as N
  33. import qualified Vertigo.Types.Notification.Ids as N
  34.  
  35.  
  36. -- test against real service
  37. run0 :: IO ()
  38. run0 = do
  39.   let uid1 = UserId $ fromJust $ fromText "3054130c-1925-48e5-9f1f-50bd1134e859"
  40.   ext <- buildEnvironmentExt
  41.   dis <- liftAppToIO ext $ do
  42.     -- userServiceGetUser :: JWT.JSON -> UserId -> Free NotifyDsl (Maybe User)
  43.     -- userServiceGetDevices :: JWT.JSON -> UserId -> Free NotifyDsl (Maybe [DeviceInfo])
  44.     _userMb <- runProd $ userServiceGetUser uid1
  45.     devicesMb <- runProd $ userServiceGetDevices uid1
  46.     liftIO $ putStrLn "--------------------------------------------------"
  47.     -- update diManufacturer
  48.     forM_ (fromJust devicesMb) $ \d ->
  49.       runProd $ userServiceUpdateDevice uid1 (d & diManufacturer .~ "temp")
  50.     _devicesMb1 <- runProd $ userServiceGetDevices uid1
  51.     liftIO $ putStrLn "--------------------------------------------------"
  52.     -- revert
  53.     forM_ (fromJust devicesMb) $ \d ->
  54.       runProd $ userServiceUpdateDevice uid1 d
  55.     _devicesMb2 <- runProd $ userServiceGetDevices uid1
  56.     liftIO $ putStrLn "--------------------------------------------------"
  57.     -- check
  58.     return ()
  59.   liftIO $ putStrLn ""
  60.   liftIO $ print dis
  61.  
  62. run1 :: IO ()
  63. run1 = do
  64.   let conf = enumToConfig LOCAL
  65.   ext <- buildEnvironmentExt conf
  66.   token <- runReaderT (createToken (user0 ^. userId)) ext
  67.   m <- runStateT (runProd $ postNotification conf (Just token) ntf0) database
  68.   print m
  69.  
  70. -- test data --
  71.  
  72. database :: FakeDb
  73. database = FakeDb (M.fromList [fdbEntry user0 Nothing]) (M.fromList []) (M.fromList [])
  74.  
  75. ntf0 = Notification {
  76.     nReceiverUid      = user0 ^. userId
  77.   , nNotificationType = Broadcast
  78.   , nTitle            = "title"
  79.   , nPayload          = "payload"
  80.   }
  81.  
  82. user0 = User (UserId $ fromJust $ fromText "06a8b2d0-b1a9-441b-9a12-e420002ab0de") (UserName "User0")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement