Skip to content

Commit 7de1e85

Browse files
committed
feat: add unit service and controller tests
1 parent 2f473b0 commit 7de1e85

2 files changed

Lines changed: 471 additions & 60 deletions

File tree

src/test/java/com/itasocialacademy/oitassist/participation/controller/ApplicationControllerTest.java

Lines changed: 164 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.itasocialacademy.oitassist.participation.controller;
22

33
import com.itasocialacademy.oitassist.ControllerUnitTest;
4+
import com.itasocialacademy.oitassist.participation.dao.dto.request.AcceptApplicationListRequest;
5+
import com.itasocialacademy.oitassist.participation.dao.dto.request.RejectApplicationListRequest;
46
import com.itasocialacademy.oitassist.participation.dao.dto.request.RejectEnrollmentRequest;
5-
import com.itasocialacademy.oitassist.participation.dao.dto.response.ApplicationListItemResponse;
6-
import com.itasocialacademy.oitassist.participation.dao.dto.response.CreateApplicationResponse;
7-
import com.itasocialacademy.oitassist.participation.dao.dto.response.ProcessApplicationResponse;
8-
import com.itasocialacademy.oitassist.participation.dao.dto.response.UserSummary;
7+
import com.itasocialacademy.oitassist.participation.dao.dto.response.*;
98
import com.itasocialacademy.oitassist.participation.dao.enums.RequestStatus;
109
import com.itasocialacademy.oitassist.participation.service.interfaces.ApplicationService;
1110
import java.time.Instant;
@@ -31,6 +30,7 @@
3130

3231
class ApplicationControllerTest extends ControllerUnitTest<ApplicationController> {
3332
private static final String ENROLLMENT_BASE_LINK = "/api/v1/enrollment/applications/{id}";
33+
private static final String ENROLLMENT_BATCH_BASE_LINK = "/api/v1/enrollment/applications/";
3434
private static final String COMPETITION_BASE_LINK = "/api/v1/competitions/{compId}/stages/{stId}/applications";
3535

3636
@Mock
@@ -101,6 +101,86 @@ void acceptRequest_shouldReturnCreated_whenApplicationIsPending() throws Excepti
101101
verify(applicationService).acceptRequest(applicationId);
102102
}
103103

104+
@Test
105+
void acceptRequests_shouldReturnCreated_whenAllSucceed() throws Exception {
106+
AcceptApplicationListRequest request = new AcceptApplicationListRequest(List.of(1L, 2L));
107+
108+
AcceptedApplicationListResponse response = AcceptedApplicationListResponse.builder()
109+
.application(new ApplicationDecisionSummary(2L, 3L, 4L, Instant.parse("2026-07-28T10:00:00Z")))
110+
.succeeded(List.of(
111+
new SucceededApplicationAcceptingItemResponse(1L, 10L, RequestStatus.ACCEPTED),
112+
new SucceededApplicationAcceptingItemResponse(2L, 11L, RequestStatus.ACCEPTED)))
113+
.failed(List.of())
114+
.build();
115+
116+
when(applicationService.acceptApplicationList(any(AcceptApplicationListRequest.class))).thenReturn(response);
117+
118+
mockMvc.perform(post(ENROLLMENT_BATCH_BASE_LINK + "/accept-batch")
119+
.contentType(MediaType.APPLICATION_JSON)
120+
.content(objectMapper.writeValueAsString(request)))
121+
.andExpect(status().isCreated())
122+
.andExpect(jsonPath("$.succeeded").isArray())
123+
.andExpect(jsonPath("$.succeeded[0].applicationId").value(1L))
124+
.andExpect(jsonPath("$.succeeded[0].status").value("ACCEPTED"))
125+
.andExpect(jsonPath("$.succeeded[1].applicationId").value(2L))
126+
.andExpect(jsonPath("$.failed").isEmpty());
127+
128+
verify(applicationService).acceptApplicationList(any(AcceptApplicationListRequest.class));
129+
}
130+
131+
@Test
132+
void acceptRequests_shouldReturnCreated_withPartialFailures() throws Exception {
133+
AcceptApplicationListRequest request = new AcceptApplicationListRequest(List.of(1L, 99L));
134+
135+
AcceptedApplicationListResponse response = AcceptedApplicationListResponse.builder()
136+
.application(new ApplicationDecisionSummary(2L, 3L, 4L, Instant.parse("2026-07-28T10:00:00Z")))
137+
.succeeded(List.of(new SucceededApplicationAcceptingItemResponse(1L, 10L, RequestStatus.ACCEPTED)))
138+
.failed(List.of(new FailedApplicationDecisionItemResponse(99L, "Application not found")))
139+
.build();
140+
141+
when(applicationService.acceptApplicationList(any(AcceptApplicationListRequest.class))).thenReturn(response);
142+
143+
mockMvc.perform(post(ENROLLMENT_BATCH_BASE_LINK + "/accept-batch")
144+
.contentType(MediaType.APPLICATION_JSON)
145+
.content(objectMapper.writeValueAsString(request)))
146+
.andExpect(status().isCreated())
147+
.andExpect(jsonPath("$.succeeded[0].applicationId").value(1L))
148+
.andExpect(jsonPath("$.failed[0].applicationId").value(99L))
149+
.andExpect(jsonPath("$.failed[0].reason").value("Application not found"));
150+
151+
verify(applicationService).acceptApplicationList(any(AcceptApplicationListRequest.class));
152+
}
153+
154+
@Test
155+
void acceptRequests_shouldReturnCreated_whenAllFail() throws Exception {
156+
AcceptApplicationListRequest request = new AcceptApplicationListRequest(List.of(1L));
157+
158+
AcceptedApplicationListResponse response = AcceptedApplicationListResponse.builder()
159+
.application(new ApplicationDecisionSummary(2L, 3L, 4L, Instant.parse("2026-07-28T10:00:00Z")))
160+
.succeeded(List.of())
161+
.failed(List.of(new FailedApplicationDecisionItemResponse(1L, "Application is not pending")))
162+
.build();
163+
164+
when(applicationService.acceptApplicationList(any(AcceptApplicationListRequest.class))).thenReturn(response);
165+
166+
mockMvc.perform(post(ENROLLMENT_BATCH_BASE_LINK + "/accept-batch")
167+
.contentType(MediaType.APPLICATION_JSON)
168+
.content(objectMapper.writeValueAsString(request)))
169+
.andExpect(status().isCreated())
170+
.andExpect(jsonPath("$.succeeded").isEmpty())
171+
.andExpect(jsonPath("$.failed[0].reason").value("Application is not pending"));
172+
}
173+
174+
@Test
175+
void acceptRequests_shouldReturnBadRequest_whenRequestIsInvalid() throws Exception {
176+
AcceptApplicationListRequest request = new AcceptApplicationListRequest(List.of());
177+
178+
mockMvc.perform(post(ENROLLMENT_BATCH_BASE_LINK + "/accept-batch")
179+
.contentType(MediaType.APPLICATION_JSON)
180+
.content(objectMapper.writeValueAsString(request)))
181+
.andExpect(status().isBadRequest());
182+
}
183+
104184
@Test
105185
void rejectRequest_shouldReturnOk_whenApplicationIsPending() throws Exception {
106186
Long applicationId = 1L;
@@ -132,6 +212,86 @@ void rejectRequest_shouldReturnOk_whenApplicationIsPending() throws Exception {
132212
verify(applicationService).rejectRequest(eq(applicationId), any(RejectEnrollmentRequest.class));
133213
}
134214

215+
@Test
216+
void rejectRequests_shouldReturnCreated_whenAllSucceed() throws Exception {
217+
RejectApplicationListRequest request = new RejectApplicationListRequest(List.of(1L, 2L), "Reason");
218+
219+
RejectedApplicationListResponse response = RejectedApplicationListResponse.builder()
220+
.application(new ApplicationDecisionSummary(2L, 3L, 4L, Instant.parse("2026-07-28T10:00:00Z")))
221+
.succeeded(List.of(
222+
new SucceededApplicationRejectingItemResponse(1L, 10L, RequestStatus.REJECTED),
223+
new SucceededApplicationRejectingItemResponse(2L, 11L, RequestStatus.REJECTED)))
224+
.failed(List.of())
225+
.build();
226+
227+
when(applicationService.rejectApplicationList(any(RejectApplicationListRequest.class))).thenReturn(response);
228+
229+
mockMvc.perform(post(ENROLLMENT_BATCH_BASE_LINK + "/reject-batch")
230+
.contentType(MediaType.APPLICATION_JSON)
231+
.content(objectMapper.writeValueAsString(request)))
232+
.andExpect(status().isCreated())
233+
.andExpect(jsonPath("$.succeeded").isArray())
234+
.andExpect(jsonPath("$.succeeded[0].applicationId").value(1L))
235+
.andExpect(jsonPath("$.succeeded[0].status").value("REJECTED"))
236+
.andExpect(jsonPath("$.succeeded[1].applicationId").value(2L))
237+
.andExpect(jsonPath("$.failed").isEmpty());
238+
239+
verify(applicationService).rejectApplicationList(any(RejectApplicationListRequest.class));
240+
}
241+
242+
@Test
243+
void rejectRequests_shouldReturnCreated_withPartialFailures() throws Exception {
244+
RejectApplicationListRequest request = new RejectApplicationListRequest(List.of(1L, 99L), "Reason");
245+
246+
RejectedApplicationListResponse response = RejectedApplicationListResponse.builder()
247+
.application(new ApplicationDecisionSummary(2L, 3L, 4L, Instant.parse("2026-07-28T10:00:00Z")))
248+
.succeeded(List.of(new SucceededApplicationRejectingItemResponse(1L, 10L, RequestStatus.REJECTED)))
249+
.failed(List.of(new FailedApplicationDecisionItemResponse(99L, "Application not found")))
250+
.build();
251+
252+
when(applicationService.rejectApplicationList(any(RejectApplicationListRequest.class))).thenReturn(response);
253+
254+
mockMvc.perform(post(ENROLLMENT_BATCH_BASE_LINK + "/reject-batch")
255+
.contentType(MediaType.APPLICATION_JSON)
256+
.content(objectMapper.writeValueAsString(request)))
257+
.andExpect(status().isCreated())
258+
.andExpect(jsonPath("$.succeeded[0].applicationId").value(1L))
259+
.andExpect(jsonPath("$.failed[0].applicationId").value(99L))
260+
.andExpect(jsonPath("$.failed[0].reason").value("Application not found"));
261+
262+
verify(applicationService).rejectApplicationList(any(RejectApplicationListRequest.class));
263+
}
264+
265+
@Test
266+
void rejectRequests_shouldReturnCreated_whenAllFail() throws Exception {
267+
RejectApplicationListRequest request = new RejectApplicationListRequest(List.of(1L), "Reason");
268+
269+
RejectedApplicationListResponse response = RejectedApplicationListResponse.builder()
270+
.application(new ApplicationDecisionSummary(2L, 3L, 4L, Instant.parse("2026-07-28T10:00:00Z")))
271+
.succeeded(List.of())
272+
.failed(List.of(new FailedApplicationDecisionItemResponse(1L, "Application is not pending")))
273+
.build();
274+
275+
when(applicationService.rejectApplicationList(any(RejectApplicationListRequest.class))).thenReturn(response);
276+
277+
mockMvc.perform(post(ENROLLMENT_BATCH_BASE_LINK + "/reject-batch")
278+
.contentType(MediaType.APPLICATION_JSON)
279+
.content(objectMapper.writeValueAsString(request)))
280+
.andExpect(status().isCreated())
281+
.andExpect(jsonPath("$.succeeded").isEmpty())
282+
.andExpect(jsonPath("$.failed[0].reason").value("Application is not pending"));
283+
}
284+
285+
@Test
286+
void rejectRequests_shouldReturnBadRequest_whenRequestIsInvalid() throws Exception {
287+
RejectApplicationListRequest request = new RejectApplicationListRequest(List.of(), "Reason");
288+
289+
mockMvc.perform(post(ENROLLMENT_BATCH_BASE_LINK + "/reject-batch")
290+
.contentType(MediaType.APPLICATION_JSON)
291+
.content(objectMapper.writeValueAsString(request)))
292+
.andExpect(status().isBadRequest());
293+
}
294+
135295
@Test
136296
void cancelRequest_shouldReturnOk_whenApplicationIsPending() throws Exception {
137297
Long applicationId = 1L;

0 commit comments

Comments
 (0)