Skip to content

Commit

Permalink
Remove unnecessary marketplaceAllows field from API
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrisbin committed May 31, 2023
1 parent 4e6a614 commit e453c73
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
2 changes: 0 additions & 2 deletions src/Restyled/Api/Repo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ data ApiRepo = ApiRepo
, isPrivate :: Bool
, isEnabled :: Bool
, installationId :: InstallationId
, marketplacePlanAllows :: Maybe MarketplacePlanAllows
, restylerImage :: RestylerImage
, restylerEnv :: [Text]
}
Expand All @@ -32,7 +31,6 @@ apiRepo (Entity _ Repo {..}) AppSettings {..} mAllows = ApiRepo
, isPrivate = repoIsPrivate
, isEnabled = repoEnabled
, installationId = repoInstallationId
, marketplacePlanAllows = mAllows -- Remove after agent is updated
, restylerImage = fromMaybe appRestylerImage repoRestylerImage
, restylerEnv =
[ "REPO_DISABLED=" <> if repoEnabled then "" else "x"
Expand Down
47 changes: 27 additions & 20 deletions test/Restyled/Api/UpsertRepoSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ module Restyled.Api.UpsertRepoSpec

import Restyled.Test hiding (upsertRepo)

import qualified Data.Text as T
import Restyled.Api.Repo (ApiRepo)
import qualified Restyled.Api.Repo as ApiRepo
import Restyled.Api.UpsertRepo (ApiUpsertRepo(ApiUpsertRepo), upsertRepo)
import qualified Restyled.Api.UpsertRepo as ApiUpsertRepo
import Restyled.Marketplace
import Restyled.Test.Graphula

spec :: Spec
Expand Down Expand Up @@ -53,13 +54,12 @@ spec = withApp $ do
repoIsPrivate repo `shouldBe` False
repoInstallationId repo `shouldBe` 1

context "marketplacePlanAllows" $ do
context "restylerEnv" $ do
it "allows public repos" $ runDB $ do
Right repo <- runValidateT
$ upsertRepo body { ApiUpsertRepo.isPrivate = False }

ApiRepo.marketplacePlanAllows repo
`shouldBe` Just MarketplacePlanAllows
lookupRestylerEnv "PLAN_RESTRICTION" repo `shouldBe` Just ""

it "handles private plans" $ graph $ do
plan <- node @MarketplacePlan () $ edit $ setPlanLimited 1
Expand All @@ -70,20 +70,27 @@ spec = withApp $ do
)
$ edit setAccountUnexpired

lift $ runDB $ do
Right (repo1, repo2) <-
runValidateT
$ (,)
<$> upsertRepo body
{ ApiUpsertRepo.name = "one"
, ApiUpsertRepo.isPrivate = True
}
<*> upsertRepo body
{ ApiUpsertRepo.name = "two"
, ApiUpsertRepo.isPrivate = True
}
Right (repo1, repo2) <-
lift
$ runDB
$ runValidateT
$ (,)
<$> upsertRepo body
{ ApiUpsertRepo.name = "one"
, ApiUpsertRepo.isPrivate = True
}
<*> upsertRepo body
{ ApiUpsertRepo.name = "two"
, ApiUpsertRepo.isPrivate = True
}

ApiRepo.marketplacePlanAllows repo1
`shouldBe` Just MarketplacePlanAllows
ApiRepo.marketplacePlanAllows repo2 `shouldBe` Just
(MarketplacePlanForbids MarketplacePlanMaxRepos)
lookupRestylerEnv "PLAN_RESTRICTION" repo1 `shouldBe` Just ""
lookupRestylerEnv "PLAN_RESTRICTION" repo2
`shouldBe` Just
"You have reached the maximum number of private repositories for the Marketplace plan for the owner of this repository (foo)"

lookupRestylerEnv :: Text -> ApiRepo -> Maybe Text
lookupRestylerEnv k =
fmap (T.drop (T.length k + 1))
. find ((k <> "=") `T.isPrefixOf`)
. ApiRepo.restylerEnv
5 changes: 0 additions & 5 deletions test/Restyled/Handlers/ReposSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ spec = withApp $ do
^?! key "installationId"
. _JSON @_ @InstallationId
`shouldBe` 1
resp
^? key "marketplacePlanAllows"
. key "tag"
. _String
`shouldBe` Just "MarketplacePlanAllows"
Just (Entity _ Repo {..}) <- runDB $ getBy $ UniqueRepo
GitHubSVCS
"foo"
Expand Down

0 comments on commit e453c73

Please sign in to comment.