Commit 0cc0f9e6 authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Add test for adding language to Corpus

parent fcdfc898
Pipeline #4555 passed with stages
in 38 minutes and 15 seconds
...@@ -58,6 +58,7 @@ library ...@@ -58,6 +58,7 @@ library
Gargantext.API.Node Gargantext.API.Node
Gargantext.API.Node.Corpus.New Gargantext.API.Node.Corpus.New
Gargantext.API.Node.Corpus.Types Gargantext.API.Node.Corpus.Types
Gargantext.API.Node.Corpus.Update
Gargantext.API.Node.File Gargantext.API.Node.File
Gargantext.API.Node.Share Gargantext.API.Node.Share
Gargantext.API.Prelude Gargantext.API.Prelude
...@@ -175,7 +176,6 @@ library ...@@ -175,7 +176,6 @@ library
Gargantext.API.Node.Corpus.New.File Gargantext.API.Node.Corpus.New.File
Gargantext.API.Node.Corpus.New.Types Gargantext.API.Node.Corpus.New.Types
Gargantext.API.Node.Corpus.Searx Gargantext.API.Node.Corpus.Searx
Gargantext.API.Node.Corpus.Update
Gargantext.API.Node.Document.Export Gargantext.API.Node.Document.Export
Gargantext.API.Node.Document.Export.Types Gargantext.API.Node.Document.Export.Types
Gargantext.API.Node.DocumentsFromWriteNodes Gargantext.API.Node.DocumentsFromWriteNodes
......
...@@ -7,17 +7,18 @@ import Control.Lens ...@@ -7,17 +7,18 @@ import Control.Lens
import Control.Monad import Control.Monad
import Data.Proxy import Data.Proxy
import Gargantext.Core import Gargantext.Core
import Gargantext.Database.Action.Flow.Types
import Gargantext.Database.Admin.Types.Hyperdata.Corpus import Gargantext.Database.Admin.Types.Hyperdata.Corpus
import Gargantext.Database.Admin.Types.Node import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Prelude
import Gargantext.Database.Query.Table.Node import Gargantext.Database.Query.Table.Node
import Gargantext.Database.Query.Table.Node.Error
import Gargantext.Database.Query.Table.Node.UpdateOpaleye (updateHyperdata) import Gargantext.Database.Query.Table.Node.UpdateOpaleye (updateHyperdata)
import Gargantext.Database.Schema.Node (node_hyperdata) import Gargantext.Database.Schema.Node (node_hyperdata)
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Utils.Jobs import Gargantext.Utils.Jobs
-- | Updates the 'HyperdataCorpus' with the input 'Lang'. -- | Updates the 'HyperdataCorpus' with the input 'Lang'.
addLanguageToCorpus :: (FlowCmdM env err m, MonadJobStatus m) addLanguageToCorpus :: (HasNodeError err, DbCmd' env err m, MonadJobStatus m)
=> CorpusId => CorpusId
-> Lang -> Lang
-> m () -> m ()
......
...@@ -260,7 +260,7 @@ getNode nId = do ...@@ -260,7 +260,7 @@ getNode nId = do
Just r -> pure r Just r -> pure r
getNodeWith :: (HasNodeError err, JSONB a) getNodeWith :: (HasNodeError err, JSONB a)
=> NodeId -> proxy a -> Cmd err (Node a) => NodeId -> proxy a -> DBCmd err (Node a)
getNodeWith nId _ = do getNodeWith nId _ = do
maybeNode <- headMay <$> runOpaQuery (selectNode (pgNodeId nId)) maybeNode <- headMay <$> runOpaQuery (selectNode (pgNodeId nId))
case maybeNode of case maybeNode of
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-} {-# OPTIONS_GHC -Wno-orphans #-}
{-# LANGUAGE TypeFamilies #-}
module Database.Operations ( module Database.Operations (
tests tests
...@@ -44,6 +45,13 @@ import Test.Hspec ...@@ -44,6 +45,13 @@ import Test.Hspec
import Test.QuickCheck.Monadic import Test.QuickCheck.Monadic
import Test.Tasty.HUnit hiding (assert) import Test.Tasty.HUnit hiding (assert)
import Test.Tasty.QuickCheck import Test.Tasty.QuickCheck
import Gargantext.API.Node.Corpus.Update
import Gargantext.Core
import Gargantext.Utils.Jobs
import qualified Gargantext.API.Admin.EnvTypes as EnvTypes
import Gargantext.API.Admin.EnvTypes
import Gargantext.API.Prelude
import Gargantext.API.Admin.Orchestrator.Types
-- | Keeps a log of usernames we have already generated, so that our -- | Keeps a log of usernames we have already generated, so that our
-- roundtrip tests won't fail. -- roundtrip tests won't fail.
...@@ -89,6 +97,21 @@ newtype TestMonad a = TestMonad { runTestMonad :: ReaderT TestEnv IO a } ...@@ -89,6 +97,21 @@ newtype TestMonad a = TestMonad { runTestMonad :: ReaderT TestEnv IO a }
, MonadIO , MonadIO
) )
instance MonadJobStatus TestMonad where
type JobHandle TestMonad = EnvTypes.ConcreteJobHandle GargError
type JobType TestMonad = GargJob
type JobOutputType TestMonad = JobLog
type JobEventType TestMonad = JobLog
getLatestJobStatus _ = TestMonad (pure noJobLog)
withTracer _ jh n = n jh
markStarted _ _ = TestMonad $ pure ()
markProgress _ _ = TestMonad $ pure ()
markFailure _ _ _ = TestMonad $ pure ()
markComplete _ = TestMonad $ pure ()
markFailed _ _ = TestMonad $ pure ()
addMoreSteps _ _ = TestMonad $ pure ()
data DBHandle = DBHandle { data DBHandle = DBHandle {
_DBHandle :: Pool PG.Connection _DBHandle :: Pool PG.Connection
, _DBTmp :: Tmp.DB , _DBTmp :: Tmp.DB
...@@ -158,6 +181,7 @@ tests = sequential $ aroundAll withTestDB $ describe "Database" $ do ...@@ -158,6 +181,7 @@ tests = sequential $ aroundAll withTestDB $ describe "Database" $ do
it "Read/Write roundtrip" prop_userCreationRoundtrip it "Read/Write roundtrip" prop_userCreationRoundtrip
describe "Corpus creation" $ do describe "Corpus creation" $ do
it "Simple write/read" corpusReadWrite01 it "Simple write/read" corpusReadWrite01
it "Can add language to Corpus" corpusAddLanguage
data ExpectedActual a = data ExpectedActual a =
Expected a Expected a
...@@ -224,5 +248,15 @@ corpusReadWrite01 env = do ...@@ -224,5 +248,15 @@ corpusReadWrite01 env = do
[corpusId] <- mk (Just "Test_Corpus") (Nothing :: Maybe HyperdataCorpus) parentId uid [corpusId] <- mk (Just "Test_Corpus") (Nothing :: Maybe HyperdataCorpus) parentId uid
liftIO $ corpusId `shouldBe` NodeId 409 liftIO $ corpusId `shouldBe` NodeId 409
-- Retrieve the corpus by Id -- Retrieve the corpus by Id
[corpusId'] <- getCorporaWithParentId parentId [corpus] <- getCorporaWithParentId parentId
liftIO $ corpusId `shouldBe` (_node_id corpusId') liftIO $ corpusId `shouldBe` (_node_id corpus)
corpusAddLanguage :: TestEnv -> Assertion
corpusAddLanguage env = do
flip runReaderT env $ runTestMonad $ do
parentId <- getRootId (UserName "alfredo")
[corpus] <- getCorporaWithParentId parentId
liftIO $ (_hc_lang . _node_hyperdata $ corpus) `shouldBe` Just EN -- defaults to English
addLanguageToCorpus (_node_id corpus) IT
[corpus'] <- getCorporaWithParentId parentId
liftIO $ (_hc_lang . _node_hyperdata $ corpus') `shouldBe` Just IT
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment