Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsuter committed Dec 27, 2024
1 parent 3e650b0 commit 6b1c5c0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,24 @@ public ResponseEntity<String> push(@RequestBody PushBean bean) {
}

@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE, headers = "X-GitHub-Event=delete")
public ResponseEntity<BranchBean> deleteBranch(@RequestBody BranchBean bean) {
public ResponseEntity<String> delete(@RequestBody BranchBean bean) {
if ("branch".equals(bean.ref_type)) {
branches.delete(bean.repo(), bean.name());
return ResponseEntity.ok().body(bean);
branches.delete(bean.repository().full_name(), bean.ref());
return ResponseEntity.ok().body("DELETED");
}
throw new RuntimeException("ref type not supported: " + bean.ref_type);
}

@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE, headers = "X-GitHub-Event=pull_request")
public ResponseEntity<PullRequest> pr(@RequestBody PullRequestBean bean) {
public ResponseEntity<String> pr(@RequestBody PullRequestBean bean) {
var pr = bean.toPullRequest();
if ("opened".equals(bean.action)) {
prs.create(pr);
return ResponseEntity.ok().body(pr);
return ResponseEntity.ok().body("CREATED");
}
if ("closed".equals(bean.action)) {
prs.delete(pr);
return ResponseEntity.ok().body(pr);
return ResponseEntity.ok().body("DELETED");
}
return ResponseEntity.noContent().build();
}
Expand All @@ -94,7 +94,6 @@ Branch toBranch() {
.repository(this.repository.full_name)
.name(ref.replace("refs/heads/", ""))
.lastCommitAuthor(this.head_commit.author.username)
.protectedBranch(false)
.authoredDate(tsToDate(this.head_commit.timestamp))
.build();
}
Expand All @@ -103,17 +102,7 @@ Branch toBranch() {
record BranchBean(
String ref,
String ref_type,
Repository repository,
User sender,
String updated_at) {

String repo() {
return repository.full_name;
}

String name() {
return ref;
}
Repository repository) {
}

record PullRequestBean(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,29 @@ void push_delete() throws Exception {
assertThat(response.body()).isEqualTo("DELETED");
}
}

@Test
void delete() throws Exception {
var push = """
{
"ref": "market-install-result",
"repository": {
"full_name": "axonivy/core"
},
"ref_type": "branch"
}
""";

try (var client = HttpClient.newHttpClient()) {
var request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:8080/github-webhook/"))
.header("X-GitHub-Event", "delete")
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(push))
.build();
var response = client.send(request, BodyHandlers.ofString());
assertThat(response.statusCode()).isEqualTo(200);
assertThat(response.body()).isEqualTo("DELETED");
}
}
}

0 comments on commit 6b1c5c0

Please sign in to comment.