@Test public void requestRefund() throws Exception { final long requestId = 38L; final RequestDto request = RequestDtoMother.fundRequestArea51(); request.setStatus(RequestStatus.FUNDED); final String funderAddress = "0x24356789"; when(profileService.getUserProfile(principal)).thenReturn(UserProfile.builder().etherAddresses(Collections.singletonList(funderAddress)).build()); when(requestService.findRequest(requestId)).thenReturn(request); when(refundService.findAllRefundRequestsFor(requestId, PENDING, APPROVED)).thenReturn(Collections.singletonList(RefundRequestDto.builder() .funderAddress("0xeab43f") .build())); mockMvc.perform(post("/requests/{request-id}/refunds", requestId).principal(principal).param("funder_address", funderAddress)) .andExpect(status().is3xxRedirection()) .andExpect(redirectAlert("success", "Your refund has been requested and is waiting for approval.")) .andExpect(redirectedUrl("/requests/38#details")); verify(refundService).requestRefund(RequestRefundCommand.builder().requestId(requestId).funderAddress(funderAddress).requestedBy(principal.getName()).build()); }
@PostMapping(value = "/requests/{requestId}/refunds") public ModelAndView requestRefund(final Principal principal, @PathVariable("requestId") final Long requestId, @RequestParam("funder_address") final String funderAddress, final RedirectAttributes redirectAttributes) { final RedirectBuilder redirectBuilder = redirectView(redirectAttributes).url("/requests/" + requestId + "#details"); if (isValid(redirectBuilder, principal, requestId, funderAddress)) { refundService.requestRefund(RequestRefundCommand.builder() .requestId(requestId) .funderAddress(funderAddress) .requestedBy(principal.getName()) .build()); return redirectBuilder.withSuccessMessage("Your refund has been requested and is waiting for approval.").build(); } else { return redirectBuilder.build(); } }
FundController extends AbstractController { @PostMapping(value = "/requests/{requestId}/refunds") public ModelAndView requestRefund(final Principal principal, @PathVariable("requestId") final Long requestId, @RequestParam("funder_address") final String funderAddress, final RedirectAttributes redirectAttributes) { final RedirectBuilder redirectBuilder = redirectView(redirectAttributes).url("/requests/" + requestId + "#details"); if (isValid(redirectBuilder, principal, requestId, funderAddress)) { refundService.requestRefund(RequestRefundCommand.builder() .requestId(requestId) .funderAddress(funderAddress) .requestedBy(principal.getName()) .build()); return redirectBuilder.withSuccessMessage("Your refund has been requested and is waiting for approval.").build(); } else { return redirectBuilder.build(); } } }
FundController extends AbstractController { @PostMapping(value = "/requests/{requestId}/refunds") public ModelAndView requestRefund(final Principal principal, @PathVariable("requestId") final Long requestId, @RequestParam("funder_address") final String funderAddress, final RedirectAttributes redirectAttributes) { final RedirectBuilder redirectBuilder = redirectView(redirectAttributes).url("/requests/" + requestId + "#details"); if (isValid(redirectBuilder, principal, requestId, funderAddress)) { refundService.requestRefund(RequestRefundCommand.builder() .requestId(requestId) .funderAddress(funderAddress) .requestedBy(principal.getName()) .build()); return redirectBuilder.withSuccessMessage("Your refund has been requested and is waiting for approval.").build(); } else { return redirectBuilder.build(); } } FundController(final RequestService requestService,
                          final RefundService refundService,
                          final ProfileService profileService); }
FundController extends AbstractController { @PostMapping(value = "/requests/{requestId}/refunds") public ModelAndView requestRefund(final Principal principal, @PathVariable("requestId") final Long requestId, @RequestParam("funder_address") final String funderAddress, final RedirectAttributes redirectAttributes) { final RedirectBuilder redirectBuilder = redirectView(redirectAttributes).url("/requests/" + requestId + "#details"); if (isValid(redirectBuilder, principal, requestId, funderAddress)) { refundService.requestRefund(RequestRefundCommand.builder() .requestId(requestId) .funderAddress(funderAddress) .requestedBy(principal.getName()) .build()); return redirectBuilder.withSuccessMessage("Your refund has been requested and is waiting for approval.").build(); } else { return redirectBuilder.build(); } } FundController(final RequestService requestService,
                          final RefundService refundService,
                          final ProfileService profileService); @RequestMapping("/fund/{type}") ModelAndView details(Principal principal, @PathVariable String type, @RequestParam(name = "url", required = false) String url); @RequestMapping("/requests/{request-id}/fund") ModelAndView fundRequestById(Principal principal, @PathVariable("request-id") Long requestId); @PostMapping(value = "/requests/{requestId}/refunds") ModelAndView requestRefund(final Principal principal,
                                      @PathVariable("requestId") final Long requestId,
                                      @RequestParam("funder_address") final String funderAddress,
                                      final RedirectAttributes redirectAttributes); }
FundController extends AbstractController { @PostMapping(value = "/requests/{requestId}/refunds") public ModelAndView requestRefund(final Principal principal, @PathVariable("requestId") final Long requestId, @RequestParam("funder_address") final String funderAddress, final RedirectAttributes redirectAttributes) { final RedirectBuilder redirectBuilder = redirectView(redirectAttributes).url("/requests/" + requestId + "#details"); if (isValid(redirectBuilder, principal, requestId, funderAddress)) { refundService.requestRefund(RequestRefundCommand.builder() .requestId(requestId) .funderAddress(funderAddress) .requestedBy(principal.getName()) .build()); return redirectBuilder.withSuccessMessage("Your refund has been requested and is waiting for approval.").build(); } else { return redirectBuilder.build(); } } FundController(final RequestService requestService,
                          final RefundService refundService,
                          final ProfileService profileService); @RequestMapping("/fund/{type}") ModelAndView details(Principal principal, @PathVariable String type, @RequestParam(name = "url", required = false) String url); @RequestMapping("/requests/{request-id}/fund") ModelAndView fundRequestById(Principal principal, @PathVariable("request-id") Long requestId); @PostMapping(value = "/requests/{requestId}/refunds") ModelAndView requestRefund(final Principal principal,
                                      @PathVariable("requestId") final Long requestId,
                                      @RequestParam("funder_address") final String funderAddress,
                                      final RedirectAttributes redirectAttributes);  }