*** Settings ***
Resource          flow_zmx.resource
Resource          res_zmx.resource
Library           DateTime

*** Variables ***
${path}           /api/v1/plan/create_plan

*** Test Cases ***
正例-正常创建计划
    [Tags]    F
    create session    URI    ${URL}
    ${timestamp}    Get Time    epoch
    ${plan_name}    Catenate    SEPARATOR=    接口测试    ${timestamp}
    ${current_time}    Get Current Date
    ${future_time}    Add Time To Date    ${current_time}    10 seconds
    ${formatted_timec}    Convert Date    ${current_time}    result_format=%Y-%m-%dT%H:%M:%S
    ${formatted_timef}    Convert Date    ${future_time}    result_format=%Y-%m-%dT%H:%M:%S
    ${content}    POST请求结果    ${path}    {"name":"${plan_name}","description":"来自接口测试","is_active":true,"ability_id":-1,"executor_type":"client","dispatch_type":"immediate","extensions":{"skipError":false,"useIncognito":false,"closePage":false},"parameters":{"提示":"使用探索工具，打开百度"},"outputs_schema":[{"name":"agent_message","type":"string","description":"探索任务结束后的文字输出"}],"triggers":[{"type":"定时触发器","trigger_type":"date","expression":"${formatted_timef}","is_active":true}],"created_by":"current_user","created_at":"${formatted_timec}"}    200    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Set Global Variable    ${plan_id}    ${content["data"]}
    Set Global Variable    ${formatted_timec}    ${formatted_timec}
    Set Global Variable    ${formatted_timef}    ${formatted_timef}

反例-不传入token
    [Tags]    E
    create session    URI    ${URL}
    ${timestamp}    Get Time    epoch
    ${plan_name}    Catenate    SEPARATOR=    接口测试    ${timestamp}
    ${current_time}    Get Current Date
    ${future_time}    Add Time To Date    ${current_time}    10 seconds
    ${formatted_time}    Convert Date    ${future_time}    result_format=%Y-%m-%dT%H:%M:%S
    ${content}    POST请求结果    ${path}    {"name":"${plan_name}","description":"1","is_active":true,"ability_id":-1,"executor_type":"client","dispatch_type":"immediate","extensions":{"skipError":false,"useIncognito":false,"closePage":false},"parameters":{"提示":"使用探索工具，打开百度"},"outputs_schema":[{"name":"agent_message","type":"string","description":"探索任务结束后的文字输出"}],"triggers":[{"type":"定时触发器","trigger_type":"date","expression":"${formatted_timef}","is_active":true}],"created_by":"current_user","created_at":"${formatted_timec}"}    401    ${EMPTY}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    401

反例-传入空白token
    [Tags]    E
    create session    URI    ${URL}
    ${timestamp}    Get Time    epoch
    ${plan_name}    Catenate    SEPARATOR=    接口测试    ${timestamp}
    ${current_time}    Get Current Date
    ${future_time}    Add Time To Date    ${current_time}    10 seconds
    ${formatted_time}    Convert Date    ${future_time}    result_format=%Y-%m-%dT%H:%M:%S
    ${content}    POST请求结果    ${path}    {"name":"${plan_name}","description":"1","is_active":true,"ability_id":-1,"executor_type":"client","dispatch_type":"immediate","extensions":{"skipError":false,"useIncognito":false,"closePage":false},"parameters":{"提示":"使用探索工具，打开百度"},"outputs_schema":[{"name":"agent_message","type":"string","description":"探索任务结束后的文字输出"}],"triggers":[{"type":"定时触发器","trigger_type":"date","expression":"${formatted_timef}","is_active":true}],"created_by":"current_user","created_at":"${formatted_timec}"}    401    {}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    401

反例-不传入name参数
    [Tags]    E
    create session    URI    ${URL}
    ${current_time}    Get Current Date
    ${future_time}    Add Time To Date    ${current_time}    10 seconds
    ${formatted_time}    Convert Date    ${future_time}    result_format=%Y-%m-%dT%H:%M:%S
    ${content}    POST请求结果    ${path}    {"description":"1","is_active":true,"ability_id":-1,"executor_type":"client","dispatch_type":"immediate","extensions":{"skipError":false,"useIncognito":false,"closePage":false},"parameters":{"提示":"使用探索工具，打开百度"},"outputs_schema":[{"name":"agent_message","type":"string","description":"探索任务结束后的文字输出"}],"triggers":[{"type":"定时触发器","trigger_type":"date","expression":"${formatted_timef}","is_active":true}],"created_by":"current_user","created_at":"${formatted_timec}"}    422    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["detail"][0]["type"]}    missing

反例-不传入ability_id参数
    [Tags]    E
    create session    URI    ${URL}
    ${timestamp}    Get Time    epoch
    ${plan_name}    Catenate    SEPARATOR=    接口测试    ${timestamp}
    ${current_time}    Get Current Date
    ${future_time}    Add Time To Date    ${current_time}    10 seconds
    ${formatted_time}    Convert Date    ${future_time}    result_format=%Y-%m-%dT%H:%M:%S
    ${content}    POST请求结果    ${path}    {"name":"${plan_name}","description":"1","is_active":true,"executor_type":"client","dispatch_type":"immediate","extensions":{"skipError":false,"useIncognito":false,"closePage":false},"parameters":{"提示":"使用探索工具，打开百度"},"outputs_schema":[{"name":"agent_message","type":"string","description":"探索任务结束后的文字输出"}],"triggers":[{"type":"定时触发器","trigger_type":"date","expression":"${formatted_timef}","is_active":true}],"created_by":"current_user","created_at":"${formatted_timec}"}    422    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["detail"][0]["type"]}    missing

反例-不传入executor_type参数
    [Tags]    E
    create session    URI    ${URL}
    ${timestamp}    Get Time    epoch
    ${plan_name}    Catenate    SEPARATOR=    接口测试    ${timestamp}
    ${current_time}    Get Current Date
    ${future_time}    Add Time To Date    ${current_time}    10 seconds
    ${formatted_time}    Convert Date    ${future_time}    result_format=%Y-%m-%dT%H:%M:%S
    ${content}    POST请求结果    ${path}    {"name":"${plan_name}","description":"1","is_active":true,"ability_id":-1,"dispatch_type":"immediate","extensions":{"skipError":false,"useIncognito":false,"closePage":false},"parameters":{"提示":"使用探索工具，打开百度"},"outputs_schema":[{"name":"agent_message","type":"string","description":"探索任务结束后的文字输出"}],"triggers":[{"type":"定时触发器","trigger_type":"date","expression":"${formatted_timef}","is_active":true}],"created_by":"current_user","created_at":"${formatted_timec}"}    422    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["detail"][0]["type"]}    missing

反例-不传入dispatch_type参数
    [Tags]    E
    create session    URI    ${URL}
    ${timestamp}    Get Time    epoch
    ${plan_name}    Catenate    SEPARATOR=    接口测试    ${timestamp}
    ${current_time}    Get Current Date
    ${future_time}    Add Time To Date    ${current_time}    10 seconds
    ${formatted_time}    Convert Date    ${future_time}    result_format=%Y-%m-%dT%H:%M:%S
    ${content}    POST请求结果    ${path}    {"name":"${plan_name}","description":"1","is_active":true,"ability_id":-1,"executor_type":"client","extensions":{"skipError":false,"useIncognito":false,"closePage":false},"parameters":{"提示":"使用探索工具，打开百度"},"outputs_schema":[{"name":"agent_message","type":"string","description":"探索任务结束后的文字输出"}],"triggers":[{"type":"定时触发器","trigger_type":"date","expression":"${formatted_timef}","is_active":true}],"created_by":"current_user","created_at":"${formatted_timec}"}    422    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["detail"][0]["type"]}    missing
