Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE FlexibleContexts #-}
- {-# LANGUAGE MultiParamTypeClasses #-}
- {-# LANGUAGE OverloadedStrings #-}
- {-# LANGUAGE ScopedTypeVariables #-}
- module VertigoIO.IntegrationTest where
- import Control.Lens ((&), (.~), (^.))
- import Control.Monad (forM_, void)
- import Control.Monad.Free (MonadFree, iterM)
- import Control.Monad.Identity (runIdentity)
- import Control.Monad.IO.Class (MonadIO, liftIO)
- import Control.Monad.State (MonadState, State, StateT(StateT), get, put, runState,
- runStateT)
- import Control.Monad.Trans.Identity (runIdentityT)
- import Control.Monad.Trans.Reader (runReaderT)
- import Data.Maybe (fromJust)
- import Data.Monoid ((<>))
- import Data.Text
- import Data.UUID (fromText)
- import Vertigo.AppM
- import Vertigo.Dsl.Notify
- import Vertigo.Dsl.RunProd
- import Vertigo.Dsl.RunTest
- import Vertigo.Ext (buildEnvironmentExt)
- import Vertigo.Token (createToken)
- import Vertigo.Types.Config (Config(Config), EnvEnum(..), enumToConfig, port)
- import Vertigo.Types.DeviceInfo
- import Vertigo.Types.User
- import qualified Data.Map as M
- import qualified Vertigo.Types.Notification as N
- import qualified Vertigo.Types.Notification.Ids as N
- -- test against real service
- run0 :: IO ()
- run0 = do
- let uid1 = UserId $ fromJust $ fromText "3054130c-1925-48e5-9f1f-50bd1134e859"
- ext <- buildEnvironmentExt
- dis <- liftAppToIO ext $ do
- -- userServiceGetUser :: JWT.JSON -> UserId -> Free NotifyDsl (Maybe User)
- -- userServiceGetDevices :: JWT.JSON -> UserId -> Free NotifyDsl (Maybe [DeviceInfo])
- _userMb <- runProd $ userServiceGetUser uid1
- devicesMb <- runProd $ userServiceGetDevices uid1
- liftIO $ putStrLn "--------------------------------------------------"
- -- update diManufacturer
- forM_ (fromJust devicesMb) $ \d ->
- runProd $ userServiceUpdateDevice uid1 (d & diManufacturer .~ "temp")
- _devicesMb1 <- runProd $ userServiceGetDevices uid1
- liftIO $ putStrLn "--------------------------------------------------"
- -- revert
- forM_ (fromJust devicesMb) $ \d ->
- runProd $ userServiceUpdateDevice uid1 d
- _devicesMb2 <- runProd $ userServiceGetDevices uid1
- liftIO $ putStrLn "--------------------------------------------------"
- -- check
- return ()
- liftIO $ putStrLn ""
- liftIO $ print dis
- run1 :: IO ()
- run1 = do
- let conf = enumToConfig LOCAL
- ext <- buildEnvironmentExt conf
- token <- runReaderT (createToken (user0 ^. userId)) ext
- m <- runStateT (runProd $ postNotification conf (Just token) ntf0) database
- print m
- -- test data --
- database :: FakeDb
- database = FakeDb (M.fromList [fdbEntry user0 Nothing]) (M.fromList []) (M.fromList [])
- ntf0 = Notification {
- nReceiverUid = user0 ^. userId
- , nNotificationType = Broadcast
- , nTitle = "title"
- , nPayload = "payload"
- }
- user0 = User (UserId $ fromJust $ fromText "06a8b2d0-b1a9-441b-9a12-e420002ab0de") (UserName "User0")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement