package com.zd.exam.controller;

import com.zd.exam.base.BaseControllerTest;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

/**
 * 积分记录controller测试
 *
 * @Author: zhoupan
 * @Date: 2021/09/08/8:57
 * @Description:
 */
@DisplayName("积分记录")
class ElPointsRecordControllerTest extends BaseControllerTest {

    /**
     * controller 前缀
     */
    private String cp = "/points/record";

    /**
     * 测试前置方法
     *
     * @throws Exception
     */
    @BeforeAll
    void init() throws Exception {
        //使用账号登陆
        beforeAll("admin", "admin123");
    }

    @Test
    @DisplayName("获取积分记录列表")
    public void list() throws Exception {
        MvcResult mvcResult = (MvcResult) mockMvc
                .perform(MockMvcRequestBuilders.get(cp + "/list").headers(httpHeaders))
                .andDo(print())
                .andExpect(status().isOk())
                .andExpect(MockMvcResultMatchers.jsonPath("$.rows").isArray())
                .andExpect(MockMvcResultMatchers.jsonPath("$.code").value(200))
                .andReturn();
        logger.debug("测试结果:" + mvcResult.getResponse().getContentAsString());
    }

    @Test
    @DisplayName("我的积分记录列表")
    public void myList() throws Exception {

        MvcResult mvcResult = (MvcResult) mockMvc
                .perform(MockMvcRequestBuilders.get(cp + "/list/my").headers(httpHeaders))
                .andDo(print())
                .andExpect(status().isOk())
                .andExpect(MockMvcResultMatchers.jsonPath("$.rows").isArray())
                .andExpect(MockMvcResultMatchers.jsonPath("$.code").value(200))
                .andReturn();
        logger.debug("测试结果:" + mvcResult.getResponse().getContentAsString());

    }


}
