package com.izouma.immall.repo;

import com.izouma.immall.domain.User;
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.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class UserRepoTest {
    @Autowired
    private UserRepo userRepo;

    @Test
    public void testUser() {
        User user = User.builder()
                .username("testuser")
                .password("123")
                .avatar("")
                .phone("123456")
                .enabled(true)
                .build();
        userRepo.save(user);
    }

    @Test
    public void createUser() {

        User user = userRepo.findByUsername("testuser");
        user.setPassword(new BCryptPasswordEncoder().encode("123456"));
        userRepo.save(user);
    }

//    @Test
//    public void findAllByAuthoritiesContains() {
//        List<User> list = userRepo.findAllByAuthoritiesContains(Authority.builder().name("ROLE_ADMIN").build());
//        System.out.println(list);
//    }

    @Test
    public void findAllUser(){
        List<User> list = userRepo.findAll();
        System.out.println(list);
    }
}
