package io.wdd.server.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.wdd.common.response.R;
import io.wdd.common.utils.FakeDataUtils;
import io.wdd.server.beans.po.ServerInfoPO;
import io.wdd.server.beans.request.ServerQueryEntity;
import io.wdd.server.beans.vo.ServerInfoVO;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@SpringBootTest
public class ServerInfoTest {

    @Resource
    ServerController serverController;

    // Test serverGetAllByPage returns expected result
    @Test
    public void test_serverGetAllByPage_returns_expected_result() {
        // Arrange
        ServerQueryEntity serverQueryEntity = new ServerQueryEntity();

        // Act
        R<Page<ServerInfoPO>> result = serverController.serverGetAllByPage(serverQueryEntity);

        // Assert
        assertNotNull(result);
        assertNotNull(result.getData());
    }

    // Test serverCreate creates a new server successfully
    @Test
    public void test_serverCreate_creates_new_server_successfully() {

        ServerInfoVO serverInfoVO = FakeDataUtils.FakeServerInfo();

        // Act
        R result = serverController.serverCreate(serverInfoVO);

        // Assert
        assertNotNull(result);
        assertEquals(
                "Create Server Success !",
                result.getData()
        );
    }

    // Test serverCreate with invalid input returns error
    @Test
    public void test_serverCreate_with_invalid_input_returns_error() {
        // Arrange
        ServerInfoVO serverInfoVO = null;

        // Act
        R result = serverController.serverCreate(serverInfoVO);

        // Assert
        assertNotNull(result);
        assertEquals(
                "Create Server Failed !",
                result.getData()
        );
    }

    // Test serverUpdate with invalid input returns error
    @Test
    public void test_serverUpdate_with_invalid_input_returns_error() {
        // Arrange
        ServerInfoPO serverInfoPO = null;

        // Act
        R result = serverController.serverUpdate(serverInfoPO);

        // Assert
        assertNotNull(result);
        assertEquals(
                "Server info update failed !",
                result.getData()
        );
    }

}
