*** Settings ***
Resource          flow_zmx.resource
Resource          res_zmx.resource
Library           get_expId.py

*** Variables ***
${path}           /api/explore/create

*** Test Cases ***
正例-正常创建探索会话
    [Tags]    F
    create session    URI    ${URL}
    ${content}    POST请求结果_params    ${path}    {"workerId":"${clientId}"}    200    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Set Global Variable    ${EXPsessionId}    ${content["data"]["sessionId"]}

反例-传入无效的token
    [Tags]    E
    create session    URI    ${URL}
    ${content}    POST请求结果_params    ${path}    {"workerId":"${clientId}"}    401    {}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    401

反例-不传入workerId
    [Tags]    E
    create session    URI    ${URL}
    ${content}    POST请求结果_params    ${path}    {}    422    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["detail"][0]["msg"]}    Field required

反例-传入空白token
    [Tags]    E
    create session    URI    ${URL}
    ${content}    POST请求结果_params    ${path}    {"workerId":"${clientId}"}    401    ${EMPTY}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    401

正例-发送探索消息，并获取返回消息
    [Tags]    F
    Sleep    10
    create session    URI    ${URL}
    ${content}    POST请求结果_data    /api/chat/write    {"sessionId":"${EXPsessionId}","text":"打开百度","workerId":"${clientId}"}    200    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Set Global Variable    ${EXP_streamId}    ${content["data"]}
    Sleep    60
    Comment    Sleep    10    性能测试时，这个接口只睡眠10秒不够后端处理
    ${resp}    Get ExpId    ${URL}/api/chat/read    ${EXPsessionId}    ${EXP_streamId}    ${token}
    log    ${resp}
    Should Contain    ${resp["sessionId"]}    P_EXP
    Set Global Variable    ${expId_EXP}    ${resp["sessionId"]}
