-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/vist/cpc 1119/display visits (#630)
https://champlainsaintlambert.atlassian.net/browse/CPC-1119 ## Context: View All The Visits using getAllVisits ## Changes Added a controller in the API Gateway under the V2 folder with a getAllVisits with a new V2 endpoint. Added some ControllerUniTests to test getAllVisits. Created a folder in react that hold the visit page. ## Dev notes (Optional) - Still missing other tests, still need to display all the visits and add the route to the visit page
- Loading branch information
1 parent
306a47e
commit 287584f
Showing
3 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...teway/src/main/java/com/petclinic/bffapigateway/presentationlayer/v2/VisitController.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,39 @@ | ||
package com.petclinic.bffapigateway.presentationlayer.v2; | ||
|
||
import com.petclinic.bffapigateway.domainclientlayer.VisitsServiceClient; | ||
import com.petclinic.bffapigateway.dtos.Auth.Role; | ||
import com.petclinic.bffapigateway.dtos.Visits.VisitResponseDTO; | ||
import com.petclinic.bffapigateway.utils.Security.Annotations.SecuredEndpoint; | ||
import com.petclinic.bffapigateway.utils.Security.Variables.Roles; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import reactor.core.publisher.Flux; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("api/v2/gateway/visits") | ||
@Validated | ||
@Slf4j | ||
@CrossOrigin(origins = "http://localhost:3000, http://localhost:80") | ||
public class VisitController { | ||
|
||
private final VisitsServiceClient visitsServiceClient; | ||
|
||
@SecuredEndpoint(allowedRoles = {Roles.ADMIN}) | ||
@GetMapping(value = "", produces = MediaType.TEXT_EVENT_STREAM_VALUE) | ||
public ResponseEntity<Flux<VisitResponseDTO>> getAllVisits() { | ||
return ResponseEntity.ok().body(visitsServiceClient.getAllVisits()); | ||
} | ||
|
||
|
||
//add more endpoints here | ||
|
||
|
||
} |
91 changes: 91 additions & 0 deletions
91
.../java/com/petclinic/bffapigateway/presentationlayer/v2/visit/VisitControllerUnitTest.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,91 @@ | ||
package com.petclinic.bffapigateway.presentationlayer.v2.visit; | ||
|
||
import com.petclinic.bffapigateway.domainclientlayer.VisitsServiceClient; | ||
import com.petclinic.bffapigateway.dtos.Visits.Status; | ||
import com.petclinic.bffapigateway.dtos.Visits.VisitResponseDTO; | ||
import com.petclinic.bffapigateway.presentationlayer.v2.VisitController; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; | ||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
import reactor.core.publisher.Flux; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.util.Date; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
@WebFluxTest(controllers = VisitController.class) | ||
@AutoConfigureWebTestClient | ||
@ContextConfiguration(classes = { | ||
VisitController.class, | ||
VisitsServiceClient.class | ||
}) | ||
public class VisitControllerUnitTest { | ||
@Autowired | ||
private WebTestClient webTestClient; | ||
|
||
@MockBean | ||
private VisitsServiceClient visitsServiceClient; | ||
|
||
private final String BASE_VISIT_URL = "/api/v2/gateway/visits"; | ||
|
||
//VisitResponseDTO Objects for testing purposes | ||
private final VisitResponseDTO visitResponseDTO1 = VisitResponseDTO.builder() | ||
.visitId("V001") | ||
.visitDate(LocalDate.of(2021, 5, 1).atStartOfDay()) | ||
.description("Routine check-up") | ||
.petId("P001") | ||
.petName("Buddy") | ||
.petBirthDate(Date.from(LocalDate.of(2020, 5, 1).atStartOfDay(ZoneId.systemDefault()).toInstant())) | ||
.practitionerId("PR001") | ||
.vetFirstName("John") | ||
.vetLastName("Doe") | ||
.vetEmail("[email protected]") | ||
.vetPhoneNumber("555-1234") | ||
.status(Status.COMPLETED) | ||
.build(); | ||
@Test | ||
void getAllVisits_whenAllPropertiesExist_thenReturnFluxResponseDTO() { | ||
// Arrange | ||
when(visitsServiceClient.getAllVisits()) | ||
.thenReturn(Flux.just(visitResponseDTO1)); | ||
|
||
// Act | ||
webTestClient.get() | ||
.uri(BASE_VISIT_URL) | ||
.accept(MediaType.TEXT_EVENT_STREAM) | ||
.exchange() | ||
.expectStatus().isOk() | ||
.expectBodyList( VisitResponseDTO.class) | ||
.hasSize(1); | ||
// Assert | ||
verify(visitsServiceClient, times(1)).getAllVisits(); | ||
} | ||
|
||
@Test | ||
void getAllVisits_whenNoVisitsExist_thenReturnEmptyFlux(){ | ||
// Arrange | ||
when(visitsServiceClient.getAllVisits()) | ||
.thenReturn(Flux.empty()); // no visits should not throw an error | ||
// Act | ||
webTestClient.get() | ||
.uri(BASE_VISIT_URL) | ||
.accept(MediaType.TEXT_EVENT_STREAM) | ||
.exchange() | ||
.expectStatus().isOk() | ||
.expectBodyList(VisitResponseDTO.class) | ||
.hasSize(0); | ||
// Assert | ||
verify(visitsServiceClient, times(1)).getAllVisits(); | ||
} | ||
|
||
} |
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,10 @@ | ||
import { NavBar } from '@/layouts/AppNavBar'; | ||
|
||
export default function Visits(): JSX.Element { | ||
return ( | ||
<div> | ||
<NavBar /> | ||
<h1>This is the Visits Page</h1> | ||
</div> | ||
); | ||
} |