Skip to content

Commit

Permalink
Define AssignmentSystemTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapter1990 committed Aug 20, 2023
1 parent 7af3f06 commit 336a484
Showing 1 changed file with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.ays.assignment.controller;

import com.ays.AbstractSystemTest;
import com.ays.assignment.model.dto.request.AssignmentSaveRequest;
import com.ays.assignment.model.dto.request.AssignmentSaveRequestBuilder;
import com.ays.common.model.AysPhoneNumberBuilder;
import com.ays.common.model.dto.response.AysResponse;
import com.ays.common.model.dto.response.AysResponseBuilder;
import com.ays.common.util.exception.model.AysError;
import com.ays.util.AysMockMvcRequestBuilders;
import com.ays.util.AysMockResultMatchersBuilders;
import org.junit.jupiter.api.Test;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;

class AssignmentSystemTest extends AbstractSystemTest {

private static final String BASE_PATH = "/api/v1";

@Test
void givenValidAssignmentSaveRequest_whenAssignmentSaved_thenReturnAssignmentSavedResponse() throws Exception {
// Given
AssignmentSaveRequest mockAssignmentSaveRequest = new AssignmentSaveRequestBuilder()
.withPhoneNumber(new AysPhoneNumberBuilder().withValidFields().build())
.build();


// Then
String endpoint = BASE_PATH.concat("/assignment");

AysResponse<Void> mockAysResponse = AysResponse.SUCCESS;

mockMvc.perform(AysMockMvcRequestBuilders
.post(endpoint, adminUserTokenOne.getAccessToken(), mockAssignmentSaveRequest))
.andDo(MockMvcResultHandlers.print())
.andExpect(AysMockResultMatchersBuilders.status().isOk())
.andExpect(AysMockResultMatchersBuilders.time()
.isNotEmpty())
.andExpect(AysMockResultMatchersBuilders.httpStatus()
.value(mockAysResponse.getHttpStatus().getReasonPhrase()))
.andExpect(AysMockResultMatchersBuilders.isSuccess()
.value(mockAysResponse.getIsSuccess()))
.andExpect(AysMockResultMatchersBuilders.response()
.doesNotExist());

}


@Test
void givenValidAssignmentSaveRequest_whenUserUnauthorizedForSaving_thenReturnAccessDeniedException() throws Exception {
// Given
AssignmentSaveRequest mockAssignmentSaveRequest = new AssignmentSaveRequestBuilder()
.withPhoneNumber(new AysPhoneNumberBuilder().withValidFields().build())
.build();

// Then
String endpoint = BASE_PATH.concat("/assignment");
MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders
.post(endpoint, userTokenOne.getAccessToken(), mockAssignmentSaveRequest);

AysResponse<AysError> mockResponse = AysResponseBuilder.FORBIDDEN;
mockMvc.perform(mockHttpServletRequestBuilder)
.andDo(MockMvcResultHandlers.print())
.andExpect(AysMockResultMatchersBuilders.status().isForbidden())
.andExpect(AysMockResultMatchersBuilders.time()
.isNotEmpty())
.andExpect(AysMockResultMatchersBuilders.httpStatus()
.value(mockResponse.getHttpStatus().name()))
.andExpect(AysMockResultMatchersBuilders.isSuccess()
.value(mockResponse.getIsSuccess()))
.andExpect(AysMockResultMatchersBuilders.response()
.doesNotExist());

}

}

0 comments on commit 336a484

Please sign in to comment.