package com.tuoheng.admin.service;

import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.entity.domain.User;
import com.tuoheng.admin.service.system.user.IUserService;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserServiceTest {

    @Autowired
    private IUserService userService;

    @Test
    public void testAdd() {
       User user = User.builder().build()
               .setCode("TH1001")
               .setUsername("1001")
               .setRealname("1001")
               .setRoleId(1)
               .setClientId("1")
               .setNote("test");

        JSONObject json = (JSONObject) JSONObject.toJSON(user);
        log.info("-----> 新增用户：json={}", json);

        JsonResult result = userService.add(user);
        log.info("-----> 新增用户：{}", result);
    }

    @Test
    public void testEdit() {
        User user = User.builder().build()
                .setId("4c188b54f5f8fb34f3b71a064f48c8af")
                .setCode("TH1001")
                .setRealname("1001111")
                .setRoleId(2)
                .setClientId("1,2")
                .setNote("test1111");

        JSONObject json = (JSONObject) JSONObject.toJSON(user);
        log.info("-----> 修改用户：json={}", user);

        JsonResult result = userService.edit(user);
        log.info("-----> 修改用户：{}", result);
    }

    @Test
    public void testResetPassword() {
        String id = "";
        JsonResult result = userService.resetPassword(id);
    }

    @Test
    public void testDelete() {
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("1");
        JsonResult result = userService.deleteByIdList(list);
        log.info("-----> 删除用户：{}", result);

    }


}
