mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 02:11:53 +00:00
rework to normalize version in db and small cleanups
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
module Handler.AppSpec (spec) where
|
||||
|
||||
import Startlude
|
||||
import TestImport
|
||||
import Database.Persist.Sql
|
||||
import Data.Maybe
|
||||
|
||||
import TestImport
|
||||
import Model
|
||||
|
||||
spec :: Spec
|
||||
@@ -23,6 +25,12 @@ spec = do
|
||||
setMethod "GET"
|
||||
setUrl ("/apps/bitcoind.s9pk?spec=0.18.3" :: Text)
|
||||
statusIs 404
|
||||
describe "GET /apps/:appId with unknown app" $
|
||||
withApp $ it "fails to get an unregistered app" $ do
|
||||
request $ do
|
||||
setMethod "GET"
|
||||
setUrl ("/apps/tempapp.s9pk?spec=0.0.1" :: Text)
|
||||
statusIs 404
|
||||
describe "GET /apps/:appId with existing version spec for bitcoin" $
|
||||
withApp $ it "creates app and metric records" $ do
|
||||
request $ do
|
||||
@@ -43,3 +51,6 @@ spec = do
|
||||
metrics <- runDBtest $ selectList [MetricEvent ==. "cups"] []
|
||||
assertEq "app should exist" (length apps) 1
|
||||
assertEq "metric should exist" (length metrics) 1
|
||||
let app = fromJust $ head apps
|
||||
version <- runDBtest $ selectList [VersionAppId ==. entityKey app] []
|
||||
assertEq "version should exist" (length version) 1
|
||||
@@ -44,7 +44,7 @@ getTables = do
|
||||
AND table_type = 'BASE TABLE';
|
||||
|] []
|
||||
|
||||
return $ map unSingle tables
|
||||
return $ fmap unSingle tables
|
||||
|
||||
wipeDB :: AgentCtx -> IO ()
|
||||
wipeDB app = runDBWithApp app $ do
|
||||
@@ -52,7 +52,7 @@ wipeDB app = runDBWithApp app $ do
|
||||
sqlBackend <- ask
|
||||
|
||||
let escapedTables = map (T.unpack . connEscapeName sqlBackend . DBName) tables
|
||||
query = "TRUNCATE TABLE " ++ (intercalate ", " $ escapedTables)
|
||||
query = "TRUNCATE TABLE " ++ (intercalate ", " escapedTables)
|
||||
rawExecute (T.pack query) []
|
||||
|
||||
runDBtest :: SqlPersistM a -> YesodExample AgentCtx a
|
||||
@@ -63,6 +63,6 @@ runDBtest query = do
|
||||
runDBWithApp :: AgentCtx -> SqlPersistM a -> IO a
|
||||
runDBWithApp app query = runSqlPersistMPool query (appConnPool app)
|
||||
|
||||
-- A convenient synonym for database access functions.
|
||||
-- A convenient synonym for database access functions
|
||||
type DB a = forall (m :: * -> *).
|
||||
(MonadUnliftIO m) => ReaderT SqlBackend m a
|
||||
|
||||
Reference in New Issue
Block a user