-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GRAD2-3032 - Adds new V2 endpoint for getting school by schoolId (#369)
* GRAD2-3032 - Adds new V2 endpoint for getting school by schoolId * GRAD2-3032 - Fixes UT
- Loading branch information
Showing
14 changed files
with
453 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
api/src/test/java/ca/bc/gov/educ/api/trax/controller/v2/SchoolControllerIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package ca.bc.gov.educ.api.trax.controller.v2; | ||
|
||
import ca.bc.gov.educ.api.trax.EducGradTraxApiApplication; | ||
import ca.bc.gov.educ.api.trax.model.dto.institute.School; | ||
import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolDetail; | ||
import ca.bc.gov.educ.api.trax.model.transformer.institute.SchoolTransformer; | ||
import ca.bc.gov.educ.api.trax.model.transformer.institute.SchoolDetailTransformer; | ||
import ca.bc.gov.educ.api.trax.repository.redis.SchoolRedisRepository; | ||
import ca.bc.gov.educ.api.trax.repository.redis.SchoolDetailRedisRepository; | ||
import ca.bc.gov.educ.api.trax.support.MockConfiguration; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
import ca.bc.gov.educ.api.trax.support.TestRedisConfiguration; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest(classes = {EducGradTraxApiApplication.class}) | ||
@AutoConfigureMockMvc | ||
@ActiveProfiles({"test", "redisTest"}) | ||
@ContextConfiguration(classes = {TestRedisConfiguration.class, MockConfiguration.class}) | ||
class SchoolControllerIntegrationTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Autowired | ||
private SchoolRedisRepository schoolRedisRepository; | ||
|
||
@Autowired | ||
private SchoolDetailRedisRepository schoolDetailRedisRepository; | ||
|
||
@Autowired | ||
private SchoolTransformer schoolTransformer; | ||
|
||
@Autowired | ||
private SchoolDetailTransformer schoolDetailTransformer; | ||
|
||
private final String schoolId = UUID.randomUUID().toString(); | ||
private final String districtId = UUID.randomUUID().toString(); | ||
|
||
@BeforeEach | ||
void setup() { | ||
schoolRedisRepository.deleteAll(); | ||
schoolDetailRedisRepository.deleteAll(); | ||
|
||
School school = new School(); | ||
school.setSchoolId(schoolId); | ||
school.setMincode("1234567"); | ||
school.setDistrictId(districtId); | ||
schoolRedisRepository.save(schoolTransformer.transformToEntity(school)); | ||
|
||
SchoolDetail schoolDetail = new SchoolDetail(); | ||
schoolDetail.setSchoolId(schoolId); | ||
schoolDetail.setDistrictId(districtId); | ||
schoolDetailRedisRepository.save(schoolDetailTransformer.transformToEntity(schoolDetail)); | ||
} | ||
|
||
@Test | ||
void testGetSchoolDetails_givenValidPayload_shouldReturnOk() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.get("/api/v2/trax/school/{schoolId}", schoolId) | ||
.with(jwt().jwt(jwt -> jwt.claim("scope", "READ_GRAD_SCHOOL_DATA"))) | ||
.accept(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$.schoolId").value(schoolId)) | ||
.andExpect(jsonPath("$.mincode").value("1234567")); | ||
} | ||
|
||
@Test | ||
void testGetSchoolDetails_givenInvalidSchoolId_shouldReturnNotFound() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.get("/api/v2/trax/school/{schoolId}", "invalid_id") | ||
.with(jwt().jwt(jwt -> jwt.claim("scope", "READ_GRAD_SCHOOL_DATA"))) | ||
.accept(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isBadRequest()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$.message").value("Parameter 'schoolId' with value 'invalid_id' could not be converted to type 'UUID'.")); | ||
} | ||
|
||
@Test | ||
void testGetSchoolDetails_givenInvalidScope_shouldReturnUnauthorized() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.get("/api/v2/trax/school/{schoolId}", schoolId) | ||
.with(jwt().jwt(jwt -> jwt.claim("scope", "BAD_SCOPE"))) | ||
.accept(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
void testGetSchoolsByParams_givenValidPayload_shouldReturnOk() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.get("/api/v2/trax/school/search") | ||
.param("districtId", districtId) | ||
.with(jwt().jwt(jwt -> jwt.claim("scope", "READ_GRAD_SCHOOL_DATA"))) | ||
.param("mincode", "1234567") | ||
.accept(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(content().json("[{\"schoolId\":\""+schoolId+"\",\"districtId\":\""+districtId+"\"}]")); | ||
} | ||
|
||
@Test | ||
void testGetSchoolsByParams_givenNoResult_shouldReturnOk() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.get("/api/v2/trax/school/search") | ||
.param("districtId", UUID.randomUUID().toString()) | ||
.with(jwt().jwt(jwt -> jwt.claim("scope", "READ_GRAD_SCHOOL_DATA"))) | ||
.param("mincode", "1234567") | ||
.accept(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(content().json("[]")); | ||
} | ||
|
||
@Test | ||
void testGetSchoolsByParams_givenBadDistrictId_shouldReturnBadRequest() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.get("/api/v2/trax/school/search") | ||
.param("districtId", "BAD_ID123") | ||
.with(jwt().jwt(jwt -> jwt.claim("scope", "READ_GRAD_SCHOOL_DATA"))) | ||
.param("mincode", "1234567") | ||
.accept(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isBadRequest()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$.message").value("Parameter 'districtId' with value 'BAD_ID123' could not be converted to type 'UUID'.")); | ||
} | ||
|
||
@Test | ||
void testGetSchoolsByParams_givenScope_shouldReturnForbidden() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.get("/api/v2/trax/school/search") | ||
.param("districtId", districtId) | ||
.with(jwt().jwt(jwt -> jwt.claim("scope", "BAD_SCOPE"))) | ||
.param("mincode", "1234567") | ||
.accept(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isForbidden()); | ||
} | ||
} |
Oops, something went wrong.