package com.rj.service;

/**
 * Author: 李中华  wx: spllzh  email(qq): 28668817@qq.com
 * Date: 2025/8/5 19:02
 **/


import com.rj.pojo.Reservation;

import com.rj.service.impl.ReservationServiceImpl;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;


import static org.junit.jupiter.api.Assertions.*;
import java.time.LocalDateTime;
import java.util.List;


//@SpringBootTest(classes = AISmartCard20250803Application.class)
class ReservationServiceTest {

    @Autowired
    private IReservationService reservationService;

    @Test
    void testSaveReservation() {
        // 创建测试数据
        Reservation reservation = new Reservation();
        reservation.setName("张三");
        reservation.setGender("男");
        reservation.setPhone("13800138000");
        reservation.setProvince("北京市");
        reservation.setDatetime(LocalDateTime.now());

        // 测试保存功能
        boolean result = reservationService.save(reservation);

        // 验证保存成功
        assertTrue(result);
        assertNotNull(reservation.getId());
    }

    @Test
    void testGetReservationsByPhone() {
        // 先保存一条测试数据
        Reservation reservation = new Reservation();
        reservation.setName("李四");
        reservation.setGender("女");
        reservation.setPhone("13900139000");
        reservation.setProvince("上海市");
        reservation.setDatetime(LocalDateTime.now());
        reservationService.save(reservation);

        // 测试根据手机号查询功能
        List<Reservation> reservations = ((ReservationServiceImpl) reservationService)
                .getReservationsByPhone("13900139000");

        // 验证查询结果
        assertNotNull(reservations);
        assertFalse(reservations.isEmpty());
        assertEquals("李四", reservations.get(0).getName());
        assertEquals("13900139000", reservations.get(0).getPhone());
    }

    @Test
    void testGetReservationsByPhoneWithNoResults() {
        // 测试查询不存在的手机号
        List<Reservation> reservations = ((ReservationServiceImpl) reservationService)
                .getReservationsByPhone("00000000000");

        // 验证查询结果为空
        assertNotNull(reservations);
        assertTrue(reservations.isEmpty());
    }
}
