-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finalize the implementation and add tests
- Loading branch information
Ender Tunc
committed
Mar 19, 2023
1 parent
ba61a1d
commit d2c7bd7
Showing
7 changed files
with
328 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
modules/core/src/test/scala/org/scalasteward/core/forge/gitlab/GitLabAlgTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.scalasteward.core.forge.gitlab | ||
|
||
import munit.CatsEffectSuite | ||
import org.http4s.Request | ||
import org.scalasteward.core.TestInstances.ioLogger | ||
import org.scalasteward.core.application.Config.{GitLabCfg, MergeRequestApprovalRulesCfg} | ||
import org.scalasteward.core.data.Repo | ||
import org.scalasteward.core.forge.ForgeType | ||
import org.scalasteward.core.mock.MockConfig.config | ||
import org.scalasteward.core.mock.MockContext.context.httpJsonClient | ||
import org.scalasteward.core.mock.MockEff | ||
import org.scalasteward.core.util.Nel | ||
|
||
class GitLabAlgTest extends CatsEffectSuite { | ||
|
||
private val gitlabApiAlg = new GitLabApiAlg[MockEff]( | ||
forgeCfg = config.forgeCfg.copy(tpe = ForgeType.GitLab), | ||
gitLabCfg = GitLabCfg( | ||
mergeWhenPipelineSucceeds = false, | ||
requiredApprovals = None, | ||
removeSourceBranch = true | ||
), | ||
modify = (_: Repo) => (request: Request[MockEff]) => MockEff.pure(request) | ||
) | ||
|
||
test( | ||
"calculateRulesToUpdate -- ignore active approval rule that doesn't have approval rule configuration" | ||
) { | ||
val activeApprovalRules = | ||
List( | ||
MergeRequestLevelApprovalRuleOut(name = "A", id = 101), | ||
MergeRequestLevelApprovalRuleOut(name = "B", id = 201) | ||
) | ||
val approvalRulesCfg = | ||
Nel.one(MergeRequestApprovalRulesCfg(approvalRuleName = "B", requiredApprovals = 1)) | ||
|
||
val result = | ||
gitlabApiAlg.calculateRulesToUpdate(activeApprovalRules, approvalRulesCfg) | ||
val expectedResult = | ||
List( | ||
( | ||
MergeRequestApprovalRulesCfg(approvalRuleName = "B", requiredApprovals = 1), | ||
MergeRequestLevelApprovalRuleOut(id = 201, name = "B") | ||
) | ||
) | ||
|
||
assertEquals(result, expectedResult) | ||
} | ||
|
||
test( | ||
"calculateRulesToUpdate -- ignore approval rule configuration that doesn't have active approval rule" | ||
) { | ||
val activeApprovalRules = | ||
List(MergeRequestLevelApprovalRuleOut(name = "A", id = 101)) | ||
val approvalRulesCfg = | ||
Nel.of( | ||
MergeRequestApprovalRulesCfg(approvalRuleName = "A", requiredApprovals = 1), | ||
MergeRequestApprovalRulesCfg(approvalRuleName = "B", requiredApprovals = 2) | ||
) | ||
|
||
val result = | ||
gitlabApiAlg.calculateRulesToUpdate(activeApprovalRules, approvalRulesCfg) | ||
val expectedResult = | ||
List( | ||
( | ||
MergeRequestApprovalRulesCfg(approvalRuleName = "A", requiredApprovals = 1), | ||
MergeRequestLevelApprovalRuleOut(name = "A", id = 101) | ||
) | ||
) | ||
|
||
assertEquals(result, expectedResult) | ||
} | ||
} |
Oops, something went wrong.