Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: attempted first test in PackageGroupSpec.hs
Browse files Browse the repository at this point in the history
mau5mat committed Nov 12, 2024
1 parent d6b6773 commit e9cccf3
Showing 3 changed files with 47 additions and 24 deletions.
2 changes: 1 addition & 1 deletion test/Flora/ImportSpec.hs
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ testImportIndex fixture = withStdOutLogger $
Nothing -> Update.createPackageIndex defaultRepo defaultRepoURL defaultDescription Nothing
Just _ -> pure ()
importFromIndex
(fixture.hackageUser.userId)
fixture.hackageUser.userId
(defaultRepo, defaultRepoURL)
testIndex
-- check the packages have been imported
65 changes: 44 additions & 21 deletions test/Flora/PackageGroupSpec.hs
Original file line number Diff line number Diff line change
@@ -1,54 +1,77 @@
module Flora.PackageGroupSpec where

import Data.Maybe
import Data.Set qualified as Set
import Data.Vector qualified as Vector
import Data.Maybe (fromJust)
import Data.Text (Text)
import Data.UUID (UUID, fromText)
import Flora.Model.PackageGroup.Query qualified as Query
import Flora.Model.PackageGroup.Types (PackageGroup (..), PackageGroupId (..))
import Flora.Model.PackageGroup.Update qualified as Update
import Flora.TestUtils
import Test.Tasty

spec :: TestEff TestTree
spec =
[ testThese
"package group update tests"
[ testThis "Insert package group" testInsertPackageGroup
, testThis "Add package to package group" testAddPackageToPackageGroup
, testThis "Remove package to package group" testRemovePackageFromPackageGroup
]
, testThese
"package group query tests"
[ testThis "Get packages by package group id" testGetPackagesByPackageGroupId
, testThis "Get packages by package group name" testGetPackageGroupByPackageGroupName
]
]
testThese
"package group"
[ testThis "Insert package group" testInsertPackageGroup
, testThis "Add package to package group" testAddPackageToPackageGroup
, testThis "Remove package to package group" testRemovePackageFromPackageGroup
, testThis "Get packages by package group id" testGetPackagesByPackageGroupId
, testThis "Get packages by package group name" testGetPackageGroupByPackageGroupName
]

defaultPackageGroup :: PackageGroup
defaultPackageGroup =
PackageGroup
{ packageGroupId = defaultPackageGroupId
, groupName = defaultGroupName
}

defaultPackageGroupId :: PackageGroupId
defaultPackageGroupId = PackageGroupId{getPackageGroupId = fromJust defaultUUID}

defaultGroupName :: Text
defaultGroupName = "test-group-name"

defaultUUID :: Maybe UUID
defaultUUID = fromText "db1b378d-58b4-4b50-a70c-7ffa5407ed15"

extractPackageGroupId :: PackageGroup -> PackageGroupId
extractPackageGroupId pg = packageGroupId pg

-- Check DB for absence of the specified `PackageGroup`
-- Run the function `Update.insertPackageGroup`
-- Check the DB for the presence of the specified `PackageGroup`
testInsertPackageGroup :: TestEff ()
testInsertPackageGroup = _
testInsertPackageGroup = do
Update.insertPackageGroup defaultPackageGroup
result <- Query.getPackageGroupByPackageGroupName defaultGroupName
case result of
Nothing ->
assertFailure
"No Package Group named: `test-group-name`"
Just pg ->
assertEqual defaultPackageGroupId (extractPackageGroupId pg)

-- Check the DB for the packages within a specified `PackageGroupPackages`
-- Run the function `Update.addPackageToPackageGroup`
-- Check the DB for the specified `PackageGroupPackages`, and check the
-- additional `Package` id is present
testAddPackageToPackageGroup :: TestEff ()
testAddPackageToPackageGroup = _
testAddPackageToPackageGroup = undefined

-- Check the DB for the packages within a specified `PackageGroupPackages`
-- Run the function `Update.removePackageFromPackageGroup`
-- Check the DB for the specified `PackageGroupPackages`, and check the
-- additional `Package` id is removed
testRemovePackageFromPackageGroup :: TestEff ()
testRemovePackageFromPackageGroup = _
testRemovePackageFromPackageGroup = undefined

-- Check the DB for packages using `PackageGroup` id
-- assert that the id for the packages found matches the expected packages provided
testGetPackagesByPackageGroupId :: TestEff ()
testGetPackagesByPackageGroupId = _
testGetPackagesByPackageGroupId = undefined

-- Check the DB for package groups using `PackageGroup` name
-- assert that the package group id found matches the expected package group provided
testGetPackageGroupByPackageGroupName :: TestEff ()
testGetPackagesByPackageGroupId = _
testGetPackageGroupByPackageGroupName = undefined
4 changes: 2 additions & 2 deletions test/Main.hs
Original file line number Diff line number Diff line change
@@ -76,5 +76,5 @@ cleanUp = dbtToEff $ do
void $ execute Delete "DELETE FROM user_organisation" ()
void $ execute Delete "DELETE FROM package_publishers" ()
void $ execute Delete "DELETE FROM users" ()
void $ execute Delete "DELETE FROM package_groups"
void $ execute Delete "DELETE FROM package_group_packages"
void $ execute Delete "DELETE FROM package_groups" ()
void $ execute Delete "DELETE FROM package_group_packages" ()

0 comments on commit e9cccf3

Please sign in to comment.