Skip to content

Commit

Permalink
Feat/vist/cpc 1119/display visits (#630)
Browse files Browse the repository at this point in the history
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
ioannisp03 authored and viktorkuts committed Sep 17, 2024
1 parent 5dfd2d0 commit d5c81de
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
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


}
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();
}

}
10 changes: 10 additions & 0 deletions petclinic-frontend/src/pages/Visit/Visit.tsx
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>
);
}

0 comments on commit d5c81de

Please sign in to comment.