package com.izouma.jiashanxia.repo;

import com.alibaba.fastjson.JSONObject;
import com.izouma.jiashanxia.domain.PackageGoods;
import com.izouma.jiashanxia.domain.UserPackageFlow;
import com.izouma.jiashanxia.dto.GoodsDTO;
import com.izouma.jiashanxia.enums.FlowType;
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;

@SpringBootTest
@RunWith(SpringRunner.class)
public class UserPackageFlowRepoTest {
    @Autowired
    private UserPackageFlowRepo userPackageFlowRepo;
    @Autowired
    private PackageGoodsRepo    packageGoodsRepo;

    @Test
    public void test() {
        List<PackageGoods> setGoodsList = packageGoodsRepo.findAllByPackageId(17L);
        List<GoodsDTO> goodsDTOS = JSONObject.parseArray(JSONObject.toJSONString(setGoodsList), GoodsDTO.class);
        String str = JSONObject.toJSONString(goodsDTOS);
        userPackageFlowRepo.save(UserPackageFlow.builder()
                .userId(2L)
                .type(FlowType.BUY)
                .content(str)
                .build());
    }
}