Skip to content

Commit

Permalink
Merge branch 'main' into bug(CSTM-CPC-1017)Fix-Pet-UUID-Generation-an…
Browse files Browse the repository at this point in the history
…d-Pet-Type-Appearance
  • Loading branch information
Nmazza1 authored Oct 24, 2023
2 parents e38601a + 3395e5e commit c9d3a62
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ function OwnerDetailsController($http, $state, $stateParams, $scope, $timeout, $
vm.getBirthday = function(birthday) {

Check notice on line 35 in api-gateway/src/main/resources/static/scripts/owner-details/owner-details.controller.js

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Duplicated code fragment

Duplicated code
if (birthday) {
var date = new Date(birthday);
var year = date.getUTCFullYear();
var month = (date.getUTCMonth() + 1).toString().padStart(2, '0'); // Months are zero-based, so we add 1
var day = date.getUTCDate().toString().padStart(2, '0');
var timezoneOffset = date.getTimezoneOffset() * 60000;
date = new Date(date.getTime() - timezoneOffset);
var year = date.getFullYear();
var month = (date.getMonth() + 1).toString().padStart(2, '0'); // Months are zero-based, so we add 1
var day = date.getDate().toString().padStart(2, '0');
return year + ' / ' + month + ' / ' + day;
} else {
return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ function PetDetailsController($http, $state, $stateParams, $scope, $timeout, $q)
vm.getBirthday = function(birthday) {
if (birthday) {
var date = new Date(birthday);
var year = date.getUTCFullYear();
var month = (date.getUTCMonth() + 1).toString().padStart(2, '0'); // Months are zero-based, so we add 1
var day = date.getUTCDate().toString().padStart(2, '0');
var timezoneOffset = date.getTimezoneOffset() * 60000;
date = new Date(date.getTime() - timezoneOffset);
var year = date.getFullYear();
var month = (date.getMonth() + 1).toString().padStart(2, '0'); // Months are zero-based, so we add 1
var day = date.getDate().toString().padStart(2, '0');
return year + ' / ' + month + ' / ' + day;
} else {
return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ angular.module('petForm')
"Pet Birth Date: " + formattedBirthDate + "\n" +
"Weight: " + self.pet.weight + " KG" + "\n" +
"Pet Type: " + petTypeName)) {

var data = {
petId: self.pet.petId,
name: self.pet.name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="bColor"><h2 class="titleOwner form">Pet</h2></div>
<div class="bColor"><h2 class="titleOwner form">Edit Pet</h2></div>

<form id="petForm" class="form-horizontal" ng-submit="$ctrl.submit()">
<div class="form-group formColor">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,31 @@ void getVisitsForStatus() throws JsonProcessingException{
.verifyComplete();
}

@Test
void getVisitByPractitionerId() throws JsonProcessingException {
VisitResponseDTO visitResponseDTO = VisitResponseDTO.builder()
.visitId("73b5c112-5703-4fb7-b7bc-ac8186811ae1")
.visitDate(LocalDateTime.parse("2024-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")))
.description("this is a dummy description")
.petId("2")
.petName("YourPetNameHere")
.petBirthDate(new Date())
.practitionerId("2")
.vetFirstName("VetFirstNameHere")
.vetLastName("VetLastNameHere")
.vetEmail("[email protected]")
.vetPhoneNumber("123-456-7890")
.status(Status.UPCOMING)
.build();
server.enqueue(new MockResponse().setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.setBody(objectMapper.writeValueAsString(visitResponseDTO)).addHeader("Content-Type", "application/json"));

Flux<VisitResponseDTO> visitResponseDTOFlux = visitsServiceClient.getVisitByPractitionerId("2");
StepVerifier.create(visitResponseDTOFlux)
.expectNext(visitResponseDTO)
.verifyComplete();
}

@Test
void createVisitForPet_Valid() throws JsonProcessingException {
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.petclinic.bffapigateway.dtos.Pets.PetTypeResponseDTO;
import com.petclinic.bffapigateway.dtos.Vets.*;
import com.petclinic.bffapigateway.dtos.Visits.Status;
import com.petclinic.bffapigateway.dtos.Visits.VisitRequestDTO;
import com.petclinic.bffapigateway.dtos.Visits.VisitResponseDTO;
import com.petclinic.bffapigateway.exceptions.ExistingVetNotFoundException;
import com.petclinic.bffapigateway.exceptions.GenericHttpException;
Expand Down Expand Up @@ -2215,13 +2216,15 @@ void shouldDeleteBillsByVetId() {
//todo fix
/*@Test
void shouldCreateAVisitWithOwnerInfo(){
String ownerId = "1";
String cookie = "aCookie";
OwnerResponseDTO owner = new OwnerResponseDTO();
VisitRequestDTO visit = VisitRequestDTO.builder()
.visitDate(LocalDateTime.parse("2021-12-12T14:00:00"))
.visitDate(LocalDateTime.parse("2021-12-12T14:00"))
.description("Charle's Richard cat has a paw infection.")
.petId("1")
.practitionerId("1")
.status(false)
.status(Status.UPCOMING)
.build();
VisitResponseDTO visitResponseDTO = VisitResponseDTO.builder()
Expand All @@ -2230,7 +2233,7 @@ void shouldCreateAVisitWithOwnerInfo(){
.petId("1")
.description("Charle's Richard cat has a paw infection.")
.practitionerId("1")
.status(false)
.status(Status.UPCOMING)
.build();
Expand All @@ -2239,23 +2242,107 @@ void shouldCreateAVisitWithOwnerInfo(){
client.post()
.uri("/api/gateway/visit/owners/{ownerId}/pets/{petId}/visits", owner.getOwnerId(), visit.getPetId())
.body(Mono.just(visit), VisitDetails.class)
.uri("/api/gateway/visit/owners/" + ownerId + "/pets/" + visitResponseDTO.getPetId() + "/visits", owner.getOwnerId(), visit.getPetId())
.cookie("Bearer",cookie)
.body(Mono.just(visit), VisitRequestDTO.class)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus().isOk()
.expectStatus().isCreated()
.expectHeader().contentType(MediaType.APPLICATION_JSON)
.expectBody()
.jsonPath("$.visitId").isEqualTo(visitResponseDTO.getVisitId())
.jsonPath("$.petId").isEqualTo("1")
.jsonPath("$.visitDate").isEqualTo("2021-12-12T14:00:00")
.jsonPath("$.visitDate").isEqualTo("2021-12-12 14:00")
.jsonPath("$.description").isEqualTo("Charle's Richard cat has a paw infection.")
.jsonPath("$.status").isEqualTo(false)
.jsonPath("$.status").isEqualTo("UPCOMING")
.jsonPath("$.practitionerId").isEqualTo(1);
}*/

@Test
public void addVisit_ShouldReturnCreatedStatus() {
String ownerId = "owner1";
String petId = "pet1";
VisitRequestDTO visit = VisitRequestDTO.builder()
.visitDate(LocalDateTime.parse("2021-12-12T14:00"))
.description("Charle's Richard cat has a paw infection.")
.petId("1")
.practitionerId("1")
.status(Status.UPCOMING)
.build();

VisitResponseDTO visitResponseDTO = VisitResponseDTO.builder()
.visitId(VISIT_ID)
.visitDate(LocalDateTime.parse("2021-12-12T14:00:00"))
.petId("1")
.description("Charle's Richard cat has a paw infection.")
.practitionerId("1")
.status(Status.UPCOMING)
.build();

when(visitsServiceClient.createVisitForPet(any(VisitRequestDTO.class)))
.thenReturn(Mono.just(visitResponseDTO));

client.post()
.uri("/api/gateway/visit/owners/{ownerId}/pets/{petId}/visits", ownerId, petId)
.cookie("Bearer", "your-auth-token") // Assuming "Bearer" is the name of the cookie
.body(Mono.just(visit), VisitRequestDTO.class)
.accept(MediaType.APPLICATION_JSON)
.exchange()
// Validate the response
.expectStatus().isCreated()
.expectBody()
.jsonPath("$.visitId").isEqualTo(visitResponseDTO.getVisitId())
.jsonPath("$.petId").isEqualTo("1")
.jsonPath("$.visitDate").isEqualTo("2021-12-12 14:00")
.jsonPath("$.description").isEqualTo("Charle's Richard cat has a paw infection.")
.jsonPath("$.status").isEqualTo("UPCOMING")
.jsonPath("$.practitionerId").isEqualTo(1);
}

}

@Test
void shouldCreateAVisitWithOwnerAndPetInfo(){
String ownerId = "5fe81e29-1f1d-4f9d-b249-8d3e0cc0b7dd";
String petId = "9";
VisitRequestDTO visit = VisitRequestDTO.builder()
.visitDate(LocalDateTime.parse("2021-12-12T14:00:00"))
.description("Charle's Richard cat has a paw infection.")
.petId(petId)
.practitionerId("1")
.status(Status.UPCOMING)
.build();

VisitResponseDTO visitResponseDTO = VisitResponseDTO.builder()
.visitId(VISIT_ID)
.visitDate(LocalDateTime.parse("2021-12-12T14:00:00"))
.petId(petId)
.description("Charle's Richard cat has a paw infection.")
.practitionerId("1")
.status(Status.UPCOMING)
.build();

when(visitsServiceClient.createVisitForPet(visit))
.thenReturn(Mono.just(visitResponseDTO));

client.post()
.uri("/api/gateway/visit/owners/{ownerId}/pets/{petId}/visits", ownerId, petId)
.body(Mono.just(visit), VisitRequestDTO.class)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus().isCreated()
.expectHeader().contentType(MediaType.APPLICATION_JSON)
.expectBody()
.jsonPath("$.visitId").isEqualTo(visitResponseDTO.getVisitId())
.jsonPath("$.petId").isEqualTo(petId)
.jsonPath("$.visitDate").isEqualTo("2021-12-12 14:00")
.jsonPath("$.description").isEqualTo("Charle's Richard cat has a paw infection.")
.jsonPath("$.status").isEqualTo("UPCOMING")
.jsonPath("$.practitionerId").isEqualTo("1");
}



/* @Test
void shouldDeleteAVisit() {
VisitDetails visit = new VisitDetails();
OwnerDetails owner = new OwnerDetails();
Expand Down Expand Up @@ -2551,7 +2638,7 @@ void getSingleVisit_Valid() {
when(visitsServiceClient.getVisitByVisitId(anyString())).thenReturn(Mono.just(visitResponseDTO));

client.get()
.uri("/api/gateway/visits/{visitId}", visitResponseDTO.getVisitId())
.uri("/api/gateway/visits/" + visitResponseDTO.getVisitId())
.exchange()
.expectStatus().isOk()
.expectBody()
Expand All @@ -2561,6 +2648,78 @@ void getSingleVisit_Valid() {
.jsonPath("$.description").isEqualTo(visitResponseDTO.getDescription())
.jsonPath("$.practitionerId").isEqualTo(visitResponseDTO.getPractitionerId());
}
@Test
void getVisitsByStatus_Valid() {
VisitResponseDTO visitResponseDTO = VisitResponseDTO.builder()
.visitId("73b5c112-5703-4fb7-b7bc-ac8186811ae1")
.visitDate(LocalDateTime.parse("2024-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")))
.description("this is a dummy description")
.petId("2")
.petName("YourPetNameHere")
.petBirthDate(new Date())
.practitionerId("2")
.vetFirstName("VetFirstNameHere")
.vetLastName("VetLastNameHere")
.vetEmail("[email protected]")
.vetPhoneNumber("123-456-7890")
.status(Status.UPCOMING)
.build();

when(visitsServiceClient.getVisitsForStatus(visitResponseDTO.getStatus().toString())).thenReturn(Flux.just(visitResponseDTO));

client.get()
.uri("/api/gateway/visits/status/{status}", visitResponseDTO.getStatus())
.exchange()
.expectStatus().isOk()
.expectBodyList(VisitResponseDTO.class)
.consumeWith(response -> {
Assertions.assertTrue(response.getResponseBody().size() > 0);
VisitResponseDTO responseBody = response.getResponseBody().get(0);
// Asserting that the values match what's expected
Assertions.assertEquals(visitResponseDTO.getVisitId(), responseBody.getVisitId());
Assertions.assertEquals(visitResponseDTO.getPetId(), responseBody.getPetId());
Assertions.assertEquals(visitResponseDTO.getVisitDate(), responseBody.getVisitDate());
Assertions.assertEquals(visitResponseDTO.getDescription(), responseBody.getDescription());
Assertions.assertEquals(visitResponseDTO.getPractitionerId(), responseBody.getPractitionerId());
});
}

@Test
void getVisitsByPractitionerId_Valid() {
VisitResponseDTO visitResponseDTO = VisitResponseDTO.builder()
.visitId("73b5c112-5703-4fb7-b7bc-ac8186811ae1")
.visitDate(LocalDateTime.parse("2024-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")))
.description("this is a dummy description")
.petId("2")
.petName("YourPetNameHere")
.petBirthDate(new Date())
.practitionerId("2")
.vetFirstName("VetFirstNameHere")
.vetLastName("VetLastNameHere")
.vetEmail("[email protected]")
.vetPhoneNumber("123-456-7890")
.status(Status.UPCOMING)
.build();

when(visitsServiceClient.getVisitByPractitionerId(visitResponseDTO.getPractitionerId())).thenReturn(Flux.just(visitResponseDTO));

client.get()
.uri("/api/gateway/visits/vets/{practitionerId}", visitResponseDTO.getPractitionerId())
.exchange()
.expectStatus().isOk()
.expectBodyList(VisitResponseDTO.class)
.consumeWith(response -> {
Assertions.assertTrue(response.getResponseBody().size() > 0);
VisitResponseDTO responseBody = response.getResponseBody().get(0);

Assertions.assertEquals(visitResponseDTO.getVisitId(), responseBody.getVisitId());
Assertions.assertEquals(visitResponseDTO.getPetId(), responseBody.getPetId());
Assertions.assertEquals(visitResponseDTO.getVisitDate(), responseBody.getVisitDate());
Assertions.assertEquals(visitResponseDTO.getDescription(), responseBody.getDescription());
Assertions.assertEquals(visitResponseDTO.getPractitionerId(), responseBody.getPractitionerId());
});
}


// @Test
// void getSingleVisit_Invalid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public void run(String... args) throws Exception {


BillRequestDTO b1 = new BillRequestDTO( "1", "general", "1", LocalDate.of(2023,9,19),59.99,BillStatus.PAID, LocalDate.of(2023, 10,3));
BillRequestDTO b3 = new BillRequestDTO( "3", "operation", "1", LocalDate.of(2023,9,21), 199.99,BillStatus.PAID,LocalDate.of(2023, 10,5));
BillRequestDTO b4 = new BillRequestDTO( "4", "injury", "1", LocalDate.of(2023,9,30), 199.99,BillStatus.UNPAID,LocalDate.of(2023, 10,14));
BillRequestDTO b2 = new BillRequestDTO( "2", "operation", "2", LocalDate.of(2023,9,20), 199.99,BillStatus.OVERDUE,LocalDate.of(2023, 10,4));
BillRequestDTO b5 = new BillRequestDTO( "5", "chronic", "3", LocalDate.of(2023,10,3), 199.99,BillStatus.UNPAID,LocalDate.of(2023, 10,17));
BillRequestDTO b3 = new BillRequestDTO( "3", "operation", "1", LocalDate.of(2023,9,27), 199.99,BillStatus.PAID,LocalDate.of(2023, 10,11));
BillRequestDTO b4 = new BillRequestDTO( "4", "injury", "1", LocalDate.of(2023,10,11), 199.99,BillStatus.UNPAID,LocalDate.of(2023, 10,25));
BillRequestDTO b2 = new BillRequestDTO( "2", "operation", "2", LocalDate.of(2023,10,6), 199.99,BillStatus.OVERDUE,LocalDate.of(2023, 10,20));
BillRequestDTO b5 = new BillRequestDTO( "5", "chronic", "3", LocalDate.of(2023,10,13), 199.99,BillStatus.UNPAID,LocalDate.of(2023, 10,27));

Flux.just(b1,b2,b3,b4,b5)
.flatMap(b -> billService.CreateBill(Mono.just(b))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public Mono<VisitResponseDTO> addVisit(Mono<VisitRequestDTO> visitRequestDTOMono
)
// .doOnNext(v -> System.out.println("Request Date: " + v.getVisitDate())) // Debugging
.map(visitRequestDTO -> entityDtoUtil.toVisitEntity(visitRequestDTO))
// .doOnNext(x -> x.setVisitId(entityDtoUtil.generateVisitIdString()))
.doOnNext(x -> x.setVisitId(entityDtoUtil.generateVisitIdString()))
// .doOnNext(v -> System.out.println("Entity Date: " + v.getVisitDate())) // Debugging
.flatMap(visit ->
repo.findByVisitDateAndPractitionerId(visit.getVisitDate(), visit.getPractitionerId()) // FindVisits method in repository
Expand Down

0 comments on commit c9d3a62

Please sign in to comment.