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

*** Variables ***
${path}           /api/chat/read

*** Test Cases ***
正例-正常读取消息
    [Tags]    F
    Sleep    60
    Comment    Sleep    10    性能测试时，这个接口只睡眠10秒不够后端处理
    ${resp}    Get ExpId    ${URL}/${path}    ${sessionId}    ${ex_streamId}    ${token}
    log    ${resp}
    Comment    Should Contain    ${resp["sessionId"]}    P_TSK
    Set Global Variable    ${expId}    ${resp["sessionId"]}
    Comment    ${content}    GET请求结果    /api/chat/retry    {"sessionId":"${expId}","workerId":"${clientId}"}    200    ${token}
    Comment    Set Global Variable    ${streamId}    ${content["data"]}
    Comment    ${resp1}    Get ExpId    ${URL}/${path}    ${expId}    ${streamId}    ${token}
    Comment    log    ${resp1}

正例-正常读取对话消息
    [Tags]    F
    ${resp}    Get Message    ${URL}/${path}    ${sessionId}    ${text_streamId}    ${token}
    log    ${resp}
    Should Contain    ${resp}[0]    你好
    Should Contain    ${resp}[-1]    关闭

反例-传入错误的token
    [Tags]    E
    create session    URI    ${URL}
    &{header}    Create Dictionary    Authorization=test666
    ${params}    Create Dictionary    sessionId=${sessionId}    streamId=${text_streamId}
    ${resp}    Get On Session    URI    ${PATH}    params=${params}    headers=${header}    expected_status=401
    Should Be Equal As Strings    ${resp.json()["code"]}    401

反例-传入空白token
    [Tags]    E
    create session    URI    ${URL}
    &{header}    Create Dictionary    Authorization=${EMPTY}
    ${params}    Create Dictionary    sessionId=${sessionId}    streamId=${text_streamId}
    ${resp}    Get On Session    URI    ${PATH}    params=${params}    headers=${header}    expected_status=401
    Should Be Equal As Strings    ${resp.json()["code"]}    401

反例-不传入sessionId参数
    [Tags]    E
    create session    URI    ${URL}
    &{header}    Create Dictionary    Authorization=${token}
    ${params}    Create Dictionary    streamId=${text_streamId}
    ${resp}    Get On Session    URI    ${PATH}    params=${params}    headers=${header}    expected_status=422
    Should Be Equal As Strings    ${resp.json()["detail"][0]["msg"]}    Field required

反例-不传入streamId参数
    [Tags]    E
    create session    URI    ${URL}
    &{header}    Create Dictionary    Authorization=${token}
    ${params}    Create Dictionary    sessionId=${sessionId}
    ${resp}    Get On Session    URI    ${PATH}    params=${params}    headers=${header}    expected_status=422
    Should Be Equal As Strings    ${resp.json()["detail"][0]["msg"]}    Field required
