package com.izouma.immall.repo;

import com.izouma.immall.domain.User;
import com.izouma.immall.domain.UserAddress;
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.List;
import java.util.Optional;

@RunWith(SpringRunner.class)
@SpringBootTest
public class UserAddressRepoTest {
    @Autowired
    private UserAddressRepo userAddressRepo;
    @Autowired
    private UserRepo userRepo;

    @Test
    public void testUserAddress() {
        List<User> users = userRepo.findAll();
        User user = users.get(0);
        System.out.println(user);
        UserAddress add1 = UserAddress.builder()
                .userId(user.getId())
                .name("张三")
                .phone("123456")
                .province("江苏")
                .citry("南京")
                .district("江宁")
                .address("将军大道1号")
                .isDefault(true)
                .build();
        userAddressRepo.save(add1);
    }

    @Test
    public void setUserAddress() {
        Optional<UserAddress> adds = userAddressRepo.findById(6L);
        UserAddress userAddress = adds.get();
        userAddress.setAddress("弘景大道");
        userAddressRepo.save(userAddress);
    }

    @Test
    public void findAllUserAddress(){
        List<UserAddress> list = userAddressRepo.findAllByUserId(5L);
        System.out.println("------>"+list+"<-----------");
    }
}
