|
16 | 16 |
|
17 | 17 | package com.bytechef.component.github.action; |
18 | 18 |
|
19 | | -import com.bytechef.component.definition.Context; |
| 19 | +import static com.bytechef.component.github.constant.GithubConstants.BASE; |
| 20 | +import static com.bytechef.component.github.constant.GithubConstants.BODY; |
| 21 | +import static com.bytechef.component.github.constant.GithubConstants.HEAD; |
| 22 | +import static com.bytechef.component.github.constant.GithubConstants.HEAD_REPO; |
| 23 | +import static com.bytechef.component.github.constant.GithubConstants.OWNER; |
| 24 | +import static com.bytechef.component.github.constant.GithubConstants.REPOSITORY; |
| 25 | +import static com.bytechef.component.github.constant.GithubConstants.TITLE; |
| 26 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 27 | +import static org.mockito.ArgumentMatchers.any; |
| 28 | +import static org.mockito.Mockito.when; |
| 29 | + |
| 30 | +import com.bytechef.component.definition.Context.Http; |
20 | 31 | import com.bytechef.component.definition.Parameters; |
21 | 32 | import com.bytechef.component.definition.TypeReference; |
22 | 33 | import com.bytechef.component.test.definition.MockParametersFactory; |
23 | | -import org.junit.jupiter.api.Test; |
24 | | - |
25 | 34 | import java.util.Map; |
26 | | - |
27 | | -import static com.bytechef.component.github.constant.GithubConstants.*; |
28 | | -import static org.junit.jupiter.api.Assertions.assertEquals; |
29 | | -import static org.mockito.ArgumentMatchers.any; |
30 | | -import static org.mockito.Mockito.when; |
| 35 | +import org.junit.jupiter.api.Test; |
31 | 36 |
|
32 | 37 | /** |
33 | 38 | * @author Anas Elgarhy (@0x61nas) |
| 39 | + * @author Monika Kušter |
34 | 40 | */ |
35 | 41 | class GitHubCreatePullRequestActionTest extends AbstractGithubActionTest { |
36 | | - private final Map<String, Object> parameterMap = Map.of(TITLE, "name", HEAD, "feat/make-it-awesome", |
37 | | - HEAD_REPO, "happy-repo", BASE, "master", BODY, "description"); |
38 | | - private final Parameters mockedParameters = MockParametersFactory.create(parameterMap); |
| 42 | + |
| 43 | + private final Parameters mockedParameters = MockParametersFactory.create( |
| 44 | + Map.of( |
| 45 | + OWNER, "testOwner", REPOSITORY, "testRepo", TITLE, "name", HEAD, "feat/123", |
| 46 | + HEAD_REPO, "head-repo", BASE, "master", BODY, "description")); |
39 | 47 |
|
40 | 48 | @Test |
41 | | - void testPerform() { |
| 49 | + void testPerform() throws Exception { |
| 50 | + when(mockedHttp.post(stringArgumentCaptor.capture())) |
| 51 | + .thenReturn(mockedExecutor); |
42 | 52 | when(mockedResponse.getBody(any(TypeReference.class))) |
43 | | - .thenReturn(responseMap); |
44 | | - |
45 | | - Map<String, Object> result = GitHubCreatePullRequestAction |
46 | | - .perform(mockedParameters, mockedParameters, mockedContext); |
47 | | - |
48 | | - assertEquals(responseMap, result); |
| 53 | + .thenReturn(Map.of()); |
49 | 54 |
|
50 | | - Context.Http.Body body = bodyArgumentCaptor.getValue(); |
| 55 | + Object result = executePerformFunction(GitHubCreatePullRequestAction.ACTION_DEFINITION, mockedParameters); |
51 | 56 |
|
52 | | - assertEquals(parameterMap, body.getContent()); |
| 57 | + assertEquals(Map.of(), result); |
| 58 | + assertEquals("/repos/testOwner/testRepo/pulls", stringArgumentCaptor.getValue()); |
| 59 | + assertEquals( |
| 60 | + Http.Body.of( |
| 61 | + Map.of(TITLE, "name", HEAD, "feat/123", HEAD_REPO, "head-repo", BASE, "master", BODY, "description"), |
| 62 | + Http.BodyContentType.JSON), |
| 63 | + bodyArgumentCaptor.getValue()); |
53 | 64 | } |
54 | 65 | } |
0 commit comments