|
13 | 13 |
|
14 | 14 | import static org.junit.jupiter.api.Assertions.*; |
15 | 15 |
|
| 16 | +import java.util.List; |
| 17 | + |
16 | 18 | public class TestAPIUtil { |
17 | 19 |
|
18 | 20 | @BeforeAll |
@@ -111,26 +113,61 @@ public void testJenkins() { |
111 | 113 | assertNull(JenkinsAPI.getJobInfo(user2, j2)); |
112 | 114 | assertTrue(JenkinsAPI.deleteUser(user2)); |
113 | 115 | assertTrue(JenkinsAPI.getJenkinsUser(user2).isEmpty()); |
| 116 | + |
| 117 | + String user3 = "TestJenkins3"; |
| 118 | + String j3 = "Job"; |
| 119 | + Member u3 = MockJDA.mockMember(user3); |
| 120 | + String p3 = APIUtil.newPassword(); |
| 121 | + InteractionHook h3 = MockJDA.mockInteractionHook(u3, MockJDA.REQUEST_CHANNEL, InteractionType.MODAL_SUBMIT); |
| 122 | + |
| 123 | + JenkinsAPI.createJenkinsUser(user3, p3, false); |
| 124 | + APIUtil.createJenkinsJob(h3, user3, p3, j3, "https://github.com/CodeMC/Bot", false); |
| 125 | + |
| 126 | + MockJDA.assertEmbeds( |
| 127 | + List.of(CommandUtil.embedError("Jenkins User for " + user3 + " already exists!")), |
| 128 | + MockJDA.getEmbeds(h3.getIdLong()), |
| 129 | + true |
| 130 | + ); |
| 131 | + |
| 132 | + assertTrue(JenkinsAPI.deleteUser(user3)); |
114 | 133 | } |
115 | 134 |
|
116 | 135 | @Test |
117 | 136 | @DisplayName("Test APIUtil#changePassword") |
118 | 137 | public void testChangePassword() { |
119 | | - String username = "TestChangePassword"; |
120 | | - String job = "Job"; |
121 | | - Member user = MockJDA.mockMember(username); |
122 | | - InteractionHook hook = MockJDA.mockInteractionHook(user, MockJDA.REQUEST_CHANNEL, InteractionType.MODAL_SUBMIT); |
| 138 | + String u1 = "TestChangePassword1"; |
| 139 | + String j1 = "Job"; |
| 140 | + Member user1 = MockJDA.mockMember(u1); |
| 141 | + InteractionHook h1 = MockJDA.mockInteractionHook(user1, MockJDA.REQUEST_CHANNEL, InteractionType.MODAL_SUBMIT); |
| 142 | + |
| 143 | + String old1 = APIUtil.newPassword(); |
| 144 | + assertTrue(APIUtil.createNexus(h1, u1, old1)); |
| 145 | + assertTrue(APIUtil.createJenkinsJob(h1, u1, old1, j1, "https://github.com/CodeMC/API", false)); |
| 146 | + |
| 147 | + String new1 = APIUtil.newPassword(); |
| 148 | + assertTrue(APIUtil.changePassword(h1, u1, new1)); |
| 149 | + |
| 150 | + assertTrue(JenkinsAPI.deleteJob(u1, j1)); |
| 151 | + assertTrue(JenkinsAPI.deleteUser(u1)); |
| 152 | + assertTrue(NexusAPI.deleteNexus(u1)); |
| 153 | + |
| 154 | + String u2 = "TestChangePassword2"; |
| 155 | + Member user2 = MockJDA.mockMember(u2); |
| 156 | + InteractionHook h2 = MockJDA.mockInteractionHook(user2, MockJDA.REQUEST_CHANNEL, InteractionType.MODAL_SUBMIT); |
| 157 | + |
| 158 | + String old2 = APIUtil.newPassword(); |
| 159 | + assertTrue(APIUtil.createNexus(h2, u2, old2)); |
123 | 160 |
|
124 | | - String oldPassword = APIUtil.newPassword(); |
125 | | - assertTrue(APIUtil.createNexus(hook, username, oldPassword)); |
126 | | - assertTrue(APIUtil.createJenkinsJob(hook, username, oldPassword, job, "https://github.com/CodeMC/API", false)); |
| 161 | + String new2 = APIUtil.newPassword(); |
| 162 | + APIUtil.changePassword(h2, u2, new2); |
127 | 163 |
|
128 | | - String newPassword = APIUtil.newPassword(); |
129 | | - assertTrue(APIUtil.changePassword(hook, username, newPassword)); |
| 164 | + MockJDA.assertEmbeds( |
| 165 | + List.of(CommandUtil.embedError("Failed to change Jenkins Password for " + u2 + "!")), |
| 166 | + MockJDA.getEmbeds(h2.getIdLong()), |
| 167 | + false |
| 168 | + ); |
130 | 169 |
|
131 | | - assertTrue(JenkinsAPI.deleteJob(username, job)); |
132 | | - assertTrue(JenkinsAPI.deleteUser(username)); |
133 | | - assertTrue(NexusAPI.deleteNexus(username)); |
| 170 | + assertTrue(NexusAPI.deleteNexus(u2)); |
134 | 171 | } |
135 | 172 |
|
136 | 173 | } |
0 commit comments