mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 14:05:52 +01:00
Add test
This commit is contained in:
@@ -2,8 +2,9 @@ package gitbucket.core.api
|
||||
|
||||
import java.util.{Base64, Calendar, Date, TimeZone}
|
||||
|
||||
import gitbucket.core.model.Account
|
||||
import gitbucket.core.util.JGitUtil.{CommitInfo, DiffInfo}
|
||||
import gitbucket.core.model.{Account, Repository, RepositoryOptions}
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.util.JGitUtil.{CommitInfo, DiffInfo, TagInfo}
|
||||
import gitbucket.core.util.RepositoryName
|
||||
import org.eclipse.jgit.diff.DiffEntry.ChangeType
|
||||
|
||||
@@ -42,18 +43,56 @@ object ApiSpecModels {
|
||||
val sha1 = "6dcb09b5b57875f334f61aebed695e2e4193db5e"
|
||||
val repo1Name = RepositoryName("octocat/Hello-World")
|
||||
|
||||
val repository = Repository(
|
||||
userName = repo1Name.owner,
|
||||
repositoryName = repo1Name.name,
|
||||
isPrivate = false,
|
||||
description = Some("This your first repo!"),
|
||||
defaultBranch = "master",
|
||||
registeredDate = date1,
|
||||
updatedDate = date1,
|
||||
lastActivityDate = date1,
|
||||
originUserName = Some("octopus plus cat"),
|
||||
originRepositoryName = Some("Hello World"),
|
||||
parentUserName = Some("github"),
|
||||
parentRepositoryName = Some("Hello-World"),
|
||||
options = RepositoryOptions(
|
||||
issuesOption = "PUBLIC",
|
||||
externalIssuesUrl = Some("https://external.com/gitbucket"),
|
||||
wikiOption = "PUBLIC",
|
||||
externalWikiUrl = Some("https://external.com/gitbucket"),
|
||||
allowFork = true,
|
||||
mergeOptions = "merge-commit,squash,rebase",
|
||||
defaultMergeOption = "merge-commit"
|
||||
)
|
||||
)
|
||||
|
||||
val repositoryInfo = RepositoryInfo(
|
||||
owner = repo1Name.owner,
|
||||
name = repo1Name.name,
|
||||
repository = repository,
|
||||
issueCount = 1,
|
||||
pullCount = 1,
|
||||
forkedCount = 1,
|
||||
branchList = Seq("master", "develop"),
|
||||
tags = Seq(
|
||||
TagInfo(name = "v1.0", time = date("2015-05-05T23:40:27Z"), id = "id1", message = "1.0 released"),
|
||||
TagInfo(name = "v2.0", time = date("2016-05-05T23:40:27Z"), id = "id2", message = "2.0 released")
|
||||
),
|
||||
managers = Seq("myboss")
|
||||
)
|
||||
|
||||
val apiUser = ApiUser(account)
|
||||
|
||||
val repository = ApiRepository(
|
||||
name = repo1Name.name,
|
||||
full_name = repo1Name.fullName,
|
||||
description = "This your first repo!",
|
||||
val apiRepository = ApiRepository(
|
||||
repository = repository,
|
||||
owner = apiUser,
|
||||
forkedCount = repositoryInfo.forkedCount,
|
||||
watchers = 0,
|
||||
forks = 0,
|
||||
`private` = false,
|
||||
default_branch = "master",
|
||||
owner = apiUser
|
||||
)(urlIsHtmlUrl = false)
|
||||
urlIsHtmlUrl = false
|
||||
)
|
||||
|
||||
// TODO ------------
|
||||
|
||||
val apiCommitStatus = ApiCommitStatus(
|
||||
created_at = date1,
|
||||
@@ -112,7 +151,7 @@ object ApiSpecModels {
|
||||
sha = sha1,
|
||||
total_count = 2,
|
||||
statuses = List(apiCommitStatus),
|
||||
repository = repository
|
||||
repository = apiRepository
|
||||
)
|
||||
|
||||
val apiLabel = ApiLabel(
|
||||
@@ -147,8 +186,8 @@ object ApiSpecModels {
|
||||
state = "open",
|
||||
updated_at = date1,
|
||||
created_at = date1,
|
||||
head = ApiPullRequest.Commit(sha = sha1, ref = "new-topic", repo = repository)("octocat"),
|
||||
base = ApiPullRequest.Commit(sha = sha1, ref = "master", repo = repository)("octocat"),
|
||||
head = ApiPullRequest.Commit(sha = sha1, ref = "new-topic", repo = apiRepository)("octocat"),
|
||||
base = ApiPullRequest.Commit(sha = sha1, ref = "master", repo = apiRepository)("octocat"),
|
||||
mergeable = None,
|
||||
merged = false,
|
||||
merged_at = Some(date1),
|
||||
|
||||
@@ -1,38 +1,112 @@
|
||||
package gitbucket.core.service
|
||||
|
||||
import gitbucket.core.api.JsonFormat
|
||||
import gitbucket.core.service.WebHookService._
|
||||
import org.json4s.jackson.JsonMethods.parse
|
||||
import org.json4s._
|
||||
import org.scalatest.FunSuite
|
||||
import org.scalatest.{Assertion, FunSuite}
|
||||
|
||||
class WebHookJsonFormatSpec extends FunSuite {
|
||||
import gitbucket.core.api.ApiSpecModels._
|
||||
|
||||
test("WebHookCreatePayload"){
|
||||
// TODO move to ApiSpecModels?
|
||||
val jsonUser = """{
|
||||
|"login":"octocat",
|
||||
|"email":"octocat@example.com",
|
||||
|"type":"User",
|
||||
|"site_admin":false,
|
||||
|"created_at":"2011-04-14T16:00:49Z",
|
||||
|"id":0,
|
||||
|"url":"http://gitbucket.exmple.com/api/v3/users/octocat",
|
||||
|"html_url":"http://gitbucket.exmple.com/octocat",
|
||||
|"avatar_url":"http://gitbucket.exmple.com/octocat/_avatar"
|
||||
|}""".stripMargin
|
||||
|
||||
val jsonRepository = s"""{
|
||||
|"name":"Hello-World",
|
||||
|"full_name":"octocat/Hello-World",
|
||||
|"description":"This your first repo!",
|
||||
|"watchers":0,
|
||||
|"forks":1,
|
||||
|"private":false,
|
||||
|"default_branch":"master",
|
||||
|"owner":$jsonUser,
|
||||
|"id":0,
|
||||
|"forks_count":1,
|
||||
|"watchers_count":0,
|
||||
|"url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World",
|
||||
|"http_url":"http://gitbucket.exmple.com/git/octocat/Hello-World.git",
|
||||
|"clone_url":"http://gitbucket.exmple.com/git/octocat/Hello-World.git",
|
||||
|"html_url":"http://gitbucket.exmple.com/octocat/Hello-World"
|
||||
|}""".stripMargin
|
||||
|
||||
private def assert(payload: WebHookPayload, expected: String): Assertion = {
|
||||
val json = JsonFormat(payload)
|
||||
assert(json == expected.replaceAll("\n", ""))
|
||||
}
|
||||
|
||||
test("WebHookCreatePayload") {
|
||||
fail("TODO")
|
||||
}
|
||||
|
||||
test("WebHookPushPayload"){
|
||||
test("WebHookPushPayload") {
|
||||
fail("TODO")
|
||||
}
|
||||
|
||||
test("WebHookIssuesPayload"){
|
||||
test("WebHookIssuesPayload") {
|
||||
val payload = WebHookIssuesPayload(
|
||||
action = "edited",
|
||||
number = 1,
|
||||
repository = apiRepository,
|
||||
issue = apiIssue,
|
||||
sender = apiUser
|
||||
)
|
||||
val expected = s"""{
|
||||
|"action":"edited",
|
||||
|"number":1,
|
||||
|"repository":$jsonRepository,
|
||||
|"issue":{
|
||||
|"number":1347,
|
||||
|"title":"Found a bug",
|
||||
|"user":$jsonUser,
|
||||
|"labels":[{"name":"bug","color":"f29513","url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/labels/bug"}],
|
||||
|"state":"open",
|
||||
|"created_at":"2011-04-14T16:00:49Z",
|
||||
|"updated_at":"2011-04-14T16:00:49Z",
|
||||
|"body":"I'm having a problem with this.",
|
||||
|"id":0,
|
||||
|"comments_url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/issues/1347/comments",
|
||||
|"html_url":"http://gitbucket.exmple.com/octocat/Hello-World/issues/1347"},
|
||||
|"sender":$jsonUser
|
||||
|}""".stripMargin
|
||||
assert(payload, expected)
|
||||
}
|
||||
|
||||
test("WebHookPullRequestPayload") {
|
||||
fail("TODO")
|
||||
}
|
||||
|
||||
test("WebHookPullRequestPayload"){
|
||||
test("WebHookIssueCommentPayload") {
|
||||
fail("TODO")
|
||||
}
|
||||
|
||||
test("WebHookIssueCommentPayload"){
|
||||
test("WebHookPullRequestReviewCommentPayload") {
|
||||
fail("TODO")
|
||||
}
|
||||
|
||||
test("WebHookPullRequestReviewCommentPayload"){
|
||||
fail("TODO")
|
||||
}
|
||||
|
||||
test("WebHookGollumPayload"){
|
||||
fail("TODO")
|
||||
test("WebHookGollumPayload") {
|
||||
val payload = WebHookGollumPayload(
|
||||
pages = Seq(("edited", "Home", sha1)),
|
||||
repository = repositoryInfo,
|
||||
repositoryUser = account,
|
||||
sender = account
|
||||
)
|
||||
val expected = s"""{
|
||||
|"pages":[{"page_name":"Home","title":"Home","action":"edited","sha":"6dcb09b5b57875f334f61aebed695e2e4193db5e","html_url":"http://gitbucket.exmple.com/octocat/Hello-World/wiki/Home"}],
|
||||
|"repository":$jsonRepository,
|
||||
|"sender":$jsonUser
|
||||
|}""".stripMargin
|
||||
assert(payload, expected)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user