package com.izouma.immall.repo;

import com.izouma.immall.domain.VipUser;
import com.izouma.immall.enums.VipType;
import com.izouma.immall.security.VipAuthority;
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.time.LocalDateTime;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@RunWith(SpringRunner.class)
@SpringBootTest
public class VipUserRepoTest {
    @Autowired
    private VipUserRepo vipUserRepo;

    @Test
    public void AddVip() {
        LocalDateTime now = LocalDateTime.now();
        Set<VipAuthority> authorities = new HashSet<>();
        authorities.add(new VipAuthority(VipAuthority.NAMES.VIP_MASK.name()));
        VipUser vip = VipUser.builder()
                .userId(5L)
                .startTime(now)
                .endTime(now.plusYears(1L))
                .vipType(VipType.VIP_CLEANSER)
                .openId("1111")
                .enabled(true)
                .build();
        vipUserRepo.save(vip);
    }

    @Test
    public void findOpenId() {
        List<VipUser> byOpenId = vipUserRepo.findByOpenId("111");
        System.out.println(byOpenId);
    }

    @Test
    public void findUserId() {
        List<VipUser> list = vipUserRepo.findAllByUserId(5L);
        System.out.println(list);
    }

    @Test
    public void outTime(){

    }
}
