Skip to content

Commit

Permalink
Made recommended changes from last pull request.
Browse files Browse the repository at this point in the history
  • Loading branch information
Futurespast committed Sep 14, 2024
1 parent 2bf84ee commit 5023e4c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.petclinic.bffapigateway.presentationlayer.v2;

import com.petclinic.bffapigateway.domainclientlayer.BillServiceClient;
import com.petclinic.bffapigateway.dtos.Bills.BillResponseDTO;
import com.petclinic.bffapigateway.dtos.Bills.BillStatus;
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.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 static org.mockito.Mockito.when;

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {
BillController.class,
BillServiceClient.class
})
@WebFluxTest(controllers = BillController.class)
@AutoConfigureWebTestClient
public class BillControllerUnitTest {

@Autowired
private WebTestClient webTestClient;
@MockBean
private BillServiceClient billServiceClient;

private final String baseBillURL = "/api/v2/gateway/bills";

private BillResponseDTO billresponse = BillResponseDTO.builder()
.billId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a")
.customerId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a")
.visitType("general")
.vetId("3")
.date(LocalDate.parse("2024-10-11"))
.amount(100.0)
.taxedAmount(0.0)
.billStatus(BillStatus.UNPAID)
.dueDate(LocalDate.parse("2024-10-13"))
.build();

private BillResponseDTO billresponse2 = BillResponseDTO.builder()
.billId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361b")
.customerId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a")
.visitType("general")
.vetId("2")
.date(LocalDate.parse("2024-10-11"))
.amount(120.0)
.taxedAmount(10.0)
.billStatus(BillStatus.UNPAID)
.dueDate(LocalDate.parse("2024-10-13"))
.build();


@Test
public void whenGetAllBillsByCustomerId_ThenReturnCustomerBills() {
when(billServiceClient.getBillsByOwnerId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a")).thenReturn(Flux.just(billresponse, billresponse2));
webTestClient.get()
.uri(baseBillURL + "/customer/{customerId}", "e6c7398e-8ac4-4e10-9ee0-03ef33f0361a")
.exchange()
.expectStatus().isOk()
.expectBodyList(BillResponseDTO.class)
.hasSize(2)
.contains(billresponse, billresponse2);
}


}
2 changes: 1 addition & 1 deletion petclinic-frontend/src/features/bills/BillsListTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function BillsListTable(): JSX.Element {
const fetchBills = async (): Promise<void> => {
try {
const response = await fetch(
`http://localhost:8080/api/gateway/bills/customer/${user.userId}`,
`http://localhost:8080/api/v2/gateway/bills/customer/${user.userId}`,
{
headers: {
Accept: 'text/event-stream',
Expand Down
7 changes: 1 addition & 6 deletions petclinic-frontend/src/layouts/AppNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ export function NavBar(): JSX.Element {
});
};

const customerBillsUrl = AppRoutePaths.CustomerBills.replace(
':userId',
user.userId
);

return (
<nav className="navbar">
<a className="navbar-brand" href="#">
Expand Down Expand Up @@ -74,7 +69,7 @@ export function NavBar(): JSX.Element {
</li>
)}
<li className="nav-item">
<Link className="nav-link" to={customerBillsUrl}>
<Link className="nav-link" to={AppRoutePaths.CustomerBills}>
Bills
</Link>
</li>
Expand Down
2 changes: 1 addition & 1 deletion petclinic-frontend/src/shared/models/path.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export enum AppRoutePaths {
Default = '/',
Inventories = '/inventories',
Vet = '/vet',
CustomerBills = '/bills/customer/:userId',
CustomerBills = '/bills/customer',
PageNotFound = '/page-not-found',
Unauthorized = '/unauthorized',
ServiceTimeout = '/service-timeout',
Expand Down

0 comments on commit 5023e4c

Please sign in to comment.