package http.cases.SaasDeveloperTest;

import base.Config;
import utils.PublicMethod;
import http.service.Saas.PlannedTaskService;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.Assert;
import org.testng.annotations.Test;


/**
 * Created by humengxin on 2018/9/3.
 */

@ContextConfiguration(classes = Config.class)
public class 计划任务 extends AbstractTestNGSpringContextTests {
    @Autowired
    PlannedTaskService plannedTaskService;


    private static DuibaLog logger = DuibaLog.getLogger();

    @Test(description = "添加商品类型计划任务")
    public void a_添加商品类型计划任务() throws Exception {

        String data=PublicMethod.data();

        //查询实物商品集合
       Response response= plannedTaskService.appItems();

        // 获取到集合商品的ID
        String sourceId =  response.jsonPath().getString("data.list[0].id");
        plannedTaskService.addTask("2239",sourceId);

        //查看商品列表确认商品成功添加
        Response response2=plannedTaskService.queryTasks("2239");
        Assert.assertEquals(response2.jsonPath().getString("data[0].sourceName"),"【自动化】自有实物19:51:09", "校验名称失败");
        Assert.assertEquals(response2.jsonPath().getString("data[0].sourceTypeName"),"商品", "校验类型失败");
        logger.info("校验名称,类型成功");


        //新建后删除测试数据
        plannedTaskService.delTask("2239",sourceId);

    }

    @Test(description = "添加活动类型计划任务")
    public void b_添加活动计划任务() throws Exception {

        String data = PublicMethod.data();


        //查询活动集合
        Response response= plannedTaskService.list2();

        // 获取到集合活动的ID
        String sourceId =  response.jsonPath().getString("data.list[0].id");
        plannedTaskService.addTask2(sourceId);



        //查看活动列表确认活动成功添加
        Response response2=plannedTaskService.queryTasks("2239");

        Assert.assertEquals(response2.jsonPath().getString("data[1].sourceName"),"自有刮刮乐", "校验名称失败");
        Assert.assertEquals(response2.jsonPath().getString("data[1].sourceTypeName"),"活动工具", "校验类型失败");
        logger.info("校验名称,类型成功");

        //新建后删除测试数据
        plannedTaskService.delTask("2239",sourceId);

    }

    @Test(description = "添加自定义链接类型计划任务")
    public void c_添加自定义链接类型计划任务() throws Exception {

         String data = PublicMethod.data();



        //新建自定义链接计划任务
        plannedTaskService.uploadBanner();

        //查看列表是否成功添加
        Response response=plannedTaskService.queryTasks("2239");


        // 获取id
        String sourceId=response.jsonPath().getString("data[0].sourceId");
        //新建后删除测试数据
        plannedTaskService.delTask("2239",sourceId);


    }


    @Test(description = "查看活动计划任务——活动规则")
    public void d_查看活动规则() throws Exception {

        String data = PublicMethod.data();


        Response response= plannedTaskService.list2();

        // 获取ID
        String sourceId =  response.jsonPath().getString("data.list[0].id");
        plannedTaskService.addTask2(sourceId);

        Response response2=plannedTaskService.queryTasks("2239");


        plannedTaskService.rules("2239",sourceId,"appHdtool");

        //新建后删除测试数据
        plannedTaskService.delTask("2239",sourceId);
    }



    @Test(description = "删除计划任务")
    public void e_删除计划任务() throws Exception {

        String data = PublicMethod.data();

        Response response= plannedTaskService.list2();

        // 获取ID
        String sourceId =  response.jsonPath().getString("data.list[0].id");
        plannedTaskService.addTask2(sourceId);

        Response response2=plannedTaskService.queryTasks("2239");

        plannedTaskService.delTask("2239",sourceId);
    }

    @Test(description = "预览计划任务")
    public void f_预览计划任务() throws Exception {

        String data = PublicMethod.data();

        Response response= plannedTaskService.list2();

        // 获取ID
        String sourceId =  response.jsonPath().getString("data.list[0].id");
        plannedTaskService.addTask2(sourceId);

        Response response2=plannedTaskService.queryTasks("2239");

        // 获取id
        String id=response2.jsonPath().getString("data[0].id");
        plannedTaskService.preview("2239",id,sourceId,"appHdtool");

    }
}