diff --git a/test/Flora/ImportSpec.hs b/test/Flora/ImportSpec.hs index 79bdf9d6..f06a6eea 100644 --- a/test/Flora/ImportSpec.hs +++ b/test/Flora/ImportSpec.hs @@ -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 diff --git a/test/Flora/PackageGroupSpec.hs b/test/Flora/PackageGroupSpec.hs index e6a5b4e1..884cdef1 100644 --- a/test/Flora/PackageGroupSpec.hs +++ b/test/Flora/PackageGroupSpec.hs @@ -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 diff --git a/test/Main.hs b/test/Main.hs index b820fc67..f94624ca 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -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" ()