/**
 * All rights Reserved, Designed By www.freemud.cn
 *
 * @Title: StockClientTest
 * @Package cn.freemud.client
 * @Description:
 * @author: ping.wu
 * @date: 2019/2/21 11:51
 * @version V1.0
 * @Copyright: 2019 www.freemud.cn Inc. All rights reserved.
 * 注意：本内容仅限于上海非码科技内部传阅，禁止外泄以及用于其他的商业目
 */
package cn.freemud.client;

import cn.freemud.base.entity.BaseResponse;
import cn.freemud.entities.dto.GetProductStockRequestDto;
import cn.freemud.entities.dto.GetProductStockResponseDto;
import cn.freemud.entities.dto.UpdateProductStockRequestDto;
import cn.freemud.service.thirdparty.StockClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.test.context.junit4.SpringRunner;

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

@RunWith(SpringRunner.class)
@SpringBootTest
@EnableDiscoveryClient
@EnableFeignClients
@EnableAutoConfiguration
public class StockClientTest {

    @Autowired
    private StockClient stockClient;

    /**
     * 查询库存
     */
    @Test
    public void getAvailableStocksTest() {
        GetProductStockRequestDto getProductStockRequestDto = new GetProductStockRequestDto();
        getProductStockRequestDto.setChannel("saas");
        getProductStockRequestDto.setPartnerId("1864");
        getProductStockRequestDto.setStoreId("1001");
        List<Long> productIds =  new ArrayList<>();
        productIds.add(134083341913936391L);
        getProductStockRequestDto.setProductIds(productIds);

        GetProductStockResponseDto availableStocks = stockClient.getAvailableStocks(getProductStockRequestDto);
        System.out.println(availableStocks);
    }

    @Test
    public void updateStocksTest() {
        UpdateProductStockRequestDto requestDto = new UpdateProductStockRequestDto();
        requestDto.setChannel("saas");
        requestDto.setChangeType("2");
        requestDto.setIsOversold(0);
        requestDto.setPartnerId("1864");
        requestDto.setStoreId("1001");
        requestDto.setTransNo("136769237027082010");
        requestDto.setTransTime(new Date());

        List<UpdateProductStockRequestDto.ProductStock> productStocks = new ArrayList<>();
        UpdateProductStockRequestDto.ProductStock productStock = new UpdateProductStockRequestDto.ProductStock();
        productStock.setProductId(134083341913936391L);
        productStock.setQty(1);
        productStocks.add(productStock);

        requestDto.setProductStocks(productStocks);

//        BaseResponse response = stockClient.updateStocks(requestDto);

//        System.out.println(response);
    }

}
