Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Christian Merten
haskell-gargantext
Commits
895f3895
Commit
895f3895
authored
Sep 28, 2023
by
Alfredo Di Napoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call setupEnvironment in each DB-related test
parent
1230ea3a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
20 deletions
+31
-20
Authentication.hs
test/Test/API/Authentication.hs
+7
-4
Private.hs
test/Test/API/Private.hs
+3
-1
Setup.hs
test/Test/API/Setup.hs
+19
-0
Operations.hs
test/Test/Database/Operations.hs
+2
-15
No files found.
test/Test/API/Authentication.hs
View file @
895f3895
...
@@ -22,9 +22,10 @@ import Control.Monad
...
@@ -22,9 +22,10 @@ import Control.Monad
import
Control.Monad.Reader
import
Control.Monad.Reader
import
Gargantext.Database.Action.User.New
import
Gargantext.Database.Action.User.New
import
Gargantext.Core.Types
import
Gargantext.Core.Types
import
Test.API.Setup
(
withTestDBAndPort
)
import
Test.API.Setup
(
withTestDBAndPort
,
setupEnvironment
)
import
qualified
Data.Text
as
T
import
qualified
Data.Text
as
T
import
Control.Lens
import
Control.Lens
import
Data.Maybe
auth_api
::
AuthRequest
->
ClientM
AuthResponse
auth_api
::
AuthRequest
->
ClientM
AuthResponse
auth_api
=
client
(
Proxy
::
Proxy
(
MkGargAPI
(
GargAPIVersion
AuthAPI
)))
auth_api
=
client
(
Proxy
::
Proxy
(
MkGargAPI
(
GargAPIVersion
AuthAPI
)))
...
@@ -34,6 +35,8 @@ cannedToken = "eyJhbGciOiJIUzUxMiJ9.eyJkYXQiOnsiaWQiOjF9fQ.t49zZSqkPAulEkYEh4pW1
...
@@ -34,6 +35,8 @@ cannedToken = "eyJhbGciOiJIUzUxMiJ9.eyJkYXQiOnsiaWQiOjF9fQ.t49zZSqkPAulEkYEh4pW1
tests
::
Spec
tests
::
Spec
tests
=
sequential
$
aroundAll
withTestDBAndPort
$
do
tests
=
sequential
$
aroundAll
withTestDBAndPort
$
do
describe
"Prelude"
$
do
it
"setup DB triggers"
$
\
((
testEnv
,
_
),
_
)
->
setupEnvironment
testEnv
describe
"Authentication"
$
do
describe
"Authentication"
$
do
baseUrl
<-
runIO
$
parseBaseUrl
"http://localhost"
baseUrl
<-
runIO
$
parseBaseUrl
"http://localhost"
manager
<-
runIO
$
newManager
defaultManagerSettings
manager
<-
runIO
$
newManager
defaultManagerSettings
...
@@ -56,17 +59,17 @@ tests = sequential $ aroundAll withTestDBAndPort $ do
...
@@ -56,17 +59,17 @@ tests = sequential $ aroundAll withTestDBAndPort $ do
let
authPayload
=
AuthRequest
"alice"
(
GargPassword
"alice"
)
let
authPayload
=
AuthRequest
"alice"
(
GargPassword
"alice"
)
result0
<-
runClientM
(
auth_api
authPayload
)
(
clientEnv
port
)
result0
<-
runClientM
(
auth_api
authPayload
)
(
clientEnv
port
)
let
result
=
over
(
_Right
.
authRes_valid
.
_Just
.
authVal_token
)
(
const
cannedToken
)
result0
let
expected
=
AuthResponse
{
let
expected
=
AuthResponse
{
_authRes_valid
=
Just
$
_authRes_valid
=
Just
$
AuthValid
{
AuthValid
{
_authVal_token
=
cannedToken
_authVal_token
=
cannedToken
,
_authVal_tree_id
=
NodeId
1
,
_authVal_tree_id
=
fromMaybe
(
NodeId
1
)
$
listToMaybe
$
result0
^..
_Right
.
authRes_valid
.
_Just
.
authVal_tree_id
,
_authVal_user_id
=
1
,
_authVal_user_id
=
fromMaybe
1
$
listToMaybe
$
result0
^..
_Right
.
authRes_valid
.
_Just
.
authVal_user_id
}
}
,
_authRes_inval
=
Nothing
,
_authRes_inval
=
Nothing
}
}
let
result
=
over
(
_Right
.
authRes_valid
.
_Just
.
authVal_token
)
(
const
cannedToken
)
result0
result
`
shouldBe
`
(
Right
expected
)
result
`
shouldBe
`
(
Right
expected
)
it
"denies login for user 'alice' if password is invalid"
$
\
((
_testEnv
,
port
),
_
)
->
do
it
"denies login for user 'alice' if password is invalid"
$
\
((
_testEnv
,
port
),
_
)
->
do
...
...
test/Test/API/Private.hs
View file @
895f3895
...
@@ -21,7 +21,7 @@ import Servant
...
@@ -21,7 +21,7 @@ import Servant
import
Servant.Auth.Client
()
import
Servant.Auth.Client
()
import
Servant.Client
import
Servant.Client
import
Test.API.Authentication
(
auth_api
)
import
Test.API.Authentication
(
auth_api
)
import
Test.API.Setup
(
withTestDBAndPort
)
import
Test.API.Setup
(
withTestDBAndPort
,
setupEnvironment
)
import
Test.Database.Types
import
Test.Database.Types
import
Test.Hspec
import
Test.Hspec
import
Test.Hspec.Wai
hiding
(
pendingWith
)
import
Test.Hspec.Wai
hiding
(
pendingWith
)
...
@@ -70,6 +70,8 @@ withValidLogin port ur pwd act = do
...
@@ -70,6 +70,8 @@ withValidLogin port ur pwd act = do
tests
::
Spec
tests
::
Spec
tests
=
sequential
$
aroundAll
withTestDBAndPort
$
do
tests
=
sequential
$
aroundAll
withTestDBAndPort
$
do
describe
"Prelude"
$
do
it
"setup DB triggers"
$
\
((
testEnv
,
_
),
_
)
->
setupEnvironment
testEnv
describe
"Private API"
$
do
describe
"Private API"
$
do
baseUrl
<-
runIO
$
parseBaseUrl
"http://localhost"
baseUrl
<-
runIO
$
parseBaseUrl
"http://localhost"
manager
<-
runIO
$
newManager
defaultManagerSettings
manager
<-
runIO
$
newManager
defaultManagerSettings
...
...
test/Test/API/Setup.hs
View file @
895f3895
...
@@ -10,7 +10,11 @@ import Gargantext.API.Admin.Types
...
@@ -10,7 +10,11 @@ import Gargantext.API.Admin.Types
import
Gargantext.API.Prelude
import
Gargantext.API.Prelude
import
Gargantext.Core.NLP
import
Gargantext.Core.NLP
import
Gargantext.Core.NodeStory
import
Gargantext.Core.NodeStory
import
Gargantext.Database.Action.Flow
import
Gargantext.Database.Admin.Config
(
userMaster
,
corpusMasterName
)
import
Gargantext.Database.Admin.Trigger.Init
import
Gargantext.Database.Prelude
import
Gargantext.Database.Prelude
import
Gargantext.Database.Query.Table.Node
(
getOrMkList
)
import
Gargantext.Prelude.Config
import
Gargantext.Prelude.Config
import
Gargantext.System.Logging
import
Gargantext.System.Logging
import
Network.HTTP.Client.TLS
(
newTlsManager
)
import
Network.HTTP.Client.TLS
(
newTlsManager
)
...
@@ -28,6 +32,10 @@ import qualified Gargantext.Utils.Jobs.Queue as Jobs
...
@@ -28,6 +32,10 @@ import qualified Gargantext.Utils.Jobs.Queue as Jobs
import
qualified
Gargantext.Utils.Jobs.Settings
as
Jobs
import
qualified
Gargantext.Utils.Jobs.Settings
as
Jobs
import
qualified
Network.Wai.Handler.Warp
as
Warp
import
qualified
Network.Wai.Handler.Warp
as
Warp
import
qualified
Servant.Job.Async
as
ServantAsync
import
qualified
Servant.Job.Async
as
ServantAsync
import
Gargantext.Database.Admin.Types.Hyperdata
import
Control.Monad.Reader
import
Gargantext.Core.Types.Individu
import
Gargantext.Database.Action.User.New
newTestEnv
::
TestEnv
->
Logger
(
GargM
Env
GargError
)
->
Warp
.
Port
->
IO
Env
newTestEnv
::
TestEnv
->
Logger
(
GargM
Env
GargError
)
->
Warp
.
Port
->
IO
Env
...
@@ -80,3 +88,14 @@ withTestDBAndPort action =
...
@@ -80,3 +88,14 @@ withTestDBAndPort action =
makeApp
env
makeApp
env
withGargApp
app
$
\
port
->
withGargApp
app
$
\
port
->
action
((
testEnv
,
port
),
app
)
action
((
testEnv
,
port
),
app
)
setupEnvironment
::
TestEnv
->
IO
()
setupEnvironment
env
=
flip
runReaderT
env
$
runTestMonad
$
do
void
$
initFirstTriggers
"secret_key"
void
$
new_user
$
mkNewUser
(
userMaster
<>
"@cnrs.com"
)
(
GargPassword
"secret_key"
)
(
masterUserId
,
_masterRootId
,
masterCorpusId
)
<-
getOrMk_RootWithCorpus
(
UserName
userMaster
)
(
Left
corpusMasterName
)
(
Nothing
::
Maybe
HyperdataCorpus
)
masterListId
<-
getOrMkList
masterCorpusId
masterUserId
void
$
initLastTriggers
masterListId
test/Test/Database/Operations.hs
View file @
895f3895
...
@@ -19,16 +19,14 @@ import Gargantext.Database.Action.User
...
@@ -19,16 +19,14 @@ import Gargantext.Database.Action.User
import
Gargantext.Database.Action.User.New
import
Gargantext.Database.Action.User.New
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.Query.Table.Node
(
mk
,
getCorporaWithParentId
,
getOrMkList
)
import
Gargantext.Database.Query.Table.Node
import
Gargantext.Database.Query.Tree.Root
(
getRootId
)
import
Gargantext.Database.Query.Tree.Root
(
getRootId
)
import
Gargantext.Database.Schema.Node
(
NodePoly
(
..
))
import
Gargantext.Database.Schema.Node
(
NodePoly
(
..
))
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Prelude
import
Prelude
import
Test.API.Setup
(
setupEnvironment
)
import
qualified
Data.Text
as
T
import
qualified
Data.Text
as
T
import
Gargantext.Database.Action.Flow
import
Gargantext.Database.Admin.Config
(
userMaster
,
corpusMasterName
)
import
Gargantext.Database.Admin.Trigger.Init
import
Test.Database.Operations.DocumentSearch
import
Test.Database.Operations.DocumentSearch
import
Test.Database.Setup
(
withTestDB
)
import
Test.Database.Setup
(
withTestDB
)
import
Test.Database.Types
import
Test.Database.Types
...
@@ -77,17 +75,6 @@ instance Eq a => Eq (ExpectedActual a) where
...
@@ -77,17 +75,6 @@ instance Eq a => Eq (ExpectedActual a) where
(
Actual
a
)
==
(
Expected
b
)
=
a
==
b
(
Actual
a
)
==
(
Expected
b
)
=
a
==
b
_
==
_
=
False
_
==
_
=
False
setupEnvironment
::
TestEnv
->
IO
()
setupEnvironment
env
=
flip
runReaderT
env
$
runTestMonad
$
do
void
$
initFirstTriggers
"secret_key"
void
$
new_user
$
mkNewUser
(
userMaster
<>
"@cnrs.com"
)
(
GargPassword
"secret_key"
)
(
masterUserId
,
_masterRootId
,
masterCorpusId
)
<-
getOrMk_RootWithCorpus
(
UserName
userMaster
)
(
Left
corpusMasterName
)
(
Nothing
::
Maybe
HyperdataCorpus
)
masterListId
<-
getOrMkList
masterCorpusId
masterUserId
void
$
initLastTriggers
masterListId
writeRead01
::
TestEnv
->
Assertion
writeRead01
::
TestEnv
->
Assertion
writeRead01
env
=
do
writeRead01
env
=
do
flip
runReaderT
env
$
runTestMonad
$
do
flip
runReaderT
env
$
runTestMonad
$
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment