Replace the mock test-payment button with a real manual Swish flow where the user sends a Swish payment with the order ID as message and confirms via a button. Admin verifies Swish and processes manually. Backend - Rename OrderStatus LOOKUP_STARTED to PROCESSING (Swedish: Hanteras) - Update V5 migration CHECK constraint from lookup_started to processing - Rename OrderService.markAsPaid() to confirmPayment(), sets PROCESSING instead of PAID, stop hardcoding amountPaid - Add GET /api/payment/swish-info endpoint returning swish number and letter price from app.payment config - Permit /api/payment/swish-info without authentication - Update UpdateStatusRequest regex to accept processing - Update PaymentControllerTest for renamed method, new status, and public swish-info endpoint test Frontend - Rewrite PaymentRedirect.vue: Swish number, order ID as message, Jag har betalat button with confirmation dialog - Add fetchSwishInfo() to api/payment.ts - AdminPage: rename Skickade stat to Att göra (processing orders), highlight processing rows with admin__row--todo - OrdersPage: update status labels/badge classes for new flow - Refactor ApiError in client.ts to property declaration syntax - Exclude __tests__ from tsconfig.app.json and Docker builds Tests - Rewrite PaymentRedirect.spec.ts for Swish info, confirmation dialog, cancel flow, and processing status - Update OrdersPage.spec.ts with processing status test - Update AdminDashboard.spec.ts with Att göra stat and row highlight - Add amountPaid to ComposePage.spec.ts mock Config - Add SWISH_NUMBER to .env.example and docker-compose.yml
78 lines
3.1 KiB
Java
78 lines
3.1 KiB
Java
package se.bilhalsning.controller;
|
|
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
import static org.mockito.Mockito.when;
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
|
import java.util.UUID;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.security.test.context.support.WithMockUser;
|
|
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
import se.bilhalsning.entity.Order;
|
|
import se.bilhalsning.entity.OrderStatus;
|
|
import se.bilhalsning.exception.OrderNotFoundException;
|
|
import se.bilhalsning.service.OrderService;
|
|
|
|
@SpringBootTest
|
|
@AutoConfigureMockMvc
|
|
class PaymentControllerTest {
|
|
|
|
@Autowired
|
|
private MockMvc mockMvc;
|
|
|
|
@MockitoBean
|
|
private OrderService orderService;
|
|
|
|
@Test
|
|
void shouldReturn403WhenNotAuthenticated() throws Exception {
|
|
mockMvc.perform(post("/api/payment/{orderId}/pay",
|
|
"c1eebc99-9c0b-4ef8-bb6d-6bb9bd380a11"))
|
|
.andExpect(status().isForbidden());
|
|
}
|
|
|
|
@Test
|
|
@WithMockUser(username = "test@bilhalsning.se")
|
|
void shouldConfirmPaymentSuccessfully() throws Exception {
|
|
UUID orderId = UUID.fromString("c1eebc99-9c0b-4ef8-bb6d-6bb9bd380a11");
|
|
Order order = new Order();
|
|
order.setId(orderId);
|
|
order.setPlate("ABC123");
|
|
order.setStatus(OrderStatus.PROCESSING);
|
|
|
|
when(orderService.confirmPayment(eq(orderId))).thenReturn(order);
|
|
|
|
mockMvc.perform(post("/api/payment/{orderId}/pay", orderId)
|
|
.contentType(MediaType.APPLICATION_JSON))
|
|
.andExpect(status().isOk())
|
|
.andExpect(jsonPath("$.id").value(orderId.toString()))
|
|
.andExpect(jsonPath("$.status").value("processing"));
|
|
}
|
|
|
|
@Test
|
|
@WithMockUser(username = "test@bilhalsning.se")
|
|
void shouldReturn404WhenOrderNotFound() throws Exception {
|
|
UUID orderId = UUID.fromString("c1eebc99-9c0b-4ef8-bb6d-6bb9bd380a11");
|
|
when(orderService.confirmPayment(eq(orderId)))
|
|
.thenThrow(new OrderNotFoundException(orderId));
|
|
|
|
mockMvc.perform(post("/api/payment/{orderId}/pay", orderId)
|
|
.contentType(MediaType.APPLICATION_JSON))
|
|
.andExpect(status().isNotFound());
|
|
}
|
|
|
|
@Test
|
|
void shouldReturnSwishInfoUnauthenticated() throws Exception {
|
|
mockMvc.perform(get("/api/payment/swish-info"))
|
|
.andExpect(status().isOk())
|
|
.andExpect(jsonPath("$.number").exists())
|
|
.andExpect(jsonPath("$.amount").exists());
|
|
}
|
|
}
|