EasyMock例子

使用easyMock高級(jí)語(yǔ)法,測(cè)試響應(yīng)式數(shù)據(jù)

{
  "data": {
    default: 'hhh',
    //_req:用來(lái)接收用戶(hù)傳入的參數(shù)
    _req: function({
      _req
    }) {
      return _req
    },

    name: function({
      _req,
      Mock
    }) {
      if (_req.query.name === 'nk') {
        return _req.query.name + '_' + Mock.mock('@name')
      } else {
        return this.default
      }
    },


    result: function({
      _req,
      Mock
    }) {
      const arr = [{
        id: '1',
        name: '小明',
        age: 18,
        gende: 'male'
      }, {
        id: '2',
        name: '小芳',
        age: 16,
        gende: 'female'
      }];
      var newArr = [];
      //根據(jù)年齡查詢(xún)數(shù)據(jù)
      for (let i = 0; i < arr.length; i++) {
        //age:規(guī)定用戶(hù)調(diào)用該接口的時(shí)候需要傳入的參數(shù)
        if (arr[i].age == _req.query.age) {
          newArr.push(arr[i])
        }
      }
      return newArr
    }
  }
}

此模擬接口的目的為獲取競(jìng)品報(bào)告,返回店鋪診斷結(jié)果,競(jìng)品診斷結(jié)果,報(bào)告描述,根據(jù)傳進(jìn)的goodId返回相應(yīng)的goodId,其他信息不變;
請(qǐng)求參數(shù)
參數(shù)名 必選 類(lèi)型 說(shuō)明
shopId 是 Long 當(dāng)前店鋪id
reportId 否 Long 工單報(bào)告id
goodsCommentCount 否 String 商品評(píng)價(jià)數(shù),如[{“goodsId”:1,”competitive”:false}]

{
  "code": 0,
  "msg": "我是返回碼信息",
  "data": function({
    _req,
    Mock
  }) {

    let new_data = {
      "shopGoodsDiagnosisResult": null,
      "competitiveGoodsDiagnosisResult": [],
      "reportDescribe": [{
        "type": 1,
        "content": "我是優(yōu)劣勢(shì)分析"
      }, {
        "type": 2,
        "content": "我是優(yōu)化建議"
      }],

    }

    let init_obj;

    try {
      /* code */
      let goodsCommentCount = JSON.parse(_req.query.goodsCommentCount);


      for (let i = 0; i < goodsCommentCount.length; i++) {
        if (goodsCommentCount[i].competitive) {
          init_obj = {
            "goodsName": "我是商品標(biāo)題",
            "picUrl": "我是商品圖片",
            "sales": 100,
            "commentCount": 100,
            "totalScore": 6,
            "naturalPvScore": 5,
            "naturalPvIsExcellent": false,
            "excellentWordsIsExcellent": false,
            "excellentWords": [
              "關(guān)鍵詞1",
              "關(guān)鍵詞2",
              "關(guān)鍵詞3"
            ],
            "titleLength": 55,
            "illicitWords": [
              "關(guān)鍵詞1",
              "關(guān)鍵詞2",
              "關(guān)鍵詞3"
            ],
            "specialSymbols": [
              "-",
              "_"
            ]
          }
          init_obj.goodsId = Number(goodsCommentCount[i].goodsId);
          new_data.competitiveGoodsDiagnosisResult.push(init_obj);
        } else {
          init_obj = {
            "goodsName": "我是商品標(biāo)題",
            "picUrl": "我是商品圖片",
            "sales": 100,
            "commentCount": 100,
            "totalScore": 6,
            "naturalPvScore": 5,
            "naturalPvIsExcellent": false,
            "excellentWordsIsExcellent": false,
            "excellentWords": [
              "關(guān)鍵詞1",
              "關(guān)鍵詞2",
              "關(guān)鍵詞3"
            ],
            "titleLength": 55,
            "illicitWords": [
              "關(guān)鍵詞1",
              "關(guān)鍵詞2",
              "關(guān)鍵詞3"
            ],
            "specialSymbols": [
              "-",
              "_"
            ]
          }
          init_obj.goodsId = Number(goodsCommentCount[i].goodsId);
          new_data.shopGoodsDiagnosisResult = init_obj;
        }
      }

    } catch (e) {
      return e.message;
    }

    if (new_data.competitiveGoodsDiagnosisResult.length < 0) {
      new_data.competitiveGoodsDiagnosisResult = null;
    }


    return new_data;

  },
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • # 一度蜜v3.0協(xié)議 --- # 交互協(xié)議 [TOC] ## 協(xié)議說(shuō)明 ### 請(qǐng)求參數(shù) 下表列出了v3.0版協(xié)...
    c5e350bc5b40閱讀 745評(píng)論 0 0
  • 官網(wǎng) 中文版本 好的網(wǎng)站 Content-type: text/htmlBASH Section: User ...
    不排版閱讀 4,737評(píng)論 0 5
  • 從網(wǎng)上復(fù)制的,看別人的比較全面,自己搬過(guò)來(lái),方便以后查找。原鏈接:https://www.cnblogs.com/...
    lxtyp閱讀 1,442評(píng)論 0 9
  • 1、面向?qū)ο蟮奶卣饔心男┓矫? 答:面向?qū)ο蟮奶卣髦饕幸韵聨讉€(gè)方面: 1)抽象:抽象是將一類(lèi)對(duì)象的共同特征總結(jié)出...
    yshenhn閱讀 1,283評(píng)論 0 8
  • JAVA面試題 1、作用域public,private,protected,以及不寫(xiě)時(shí)的區(qū)別答:區(qū)別如下:作用域 ...
    JA尐白閱讀 1,272評(píng)論 1 0

友情鏈接更多精彩內(nèi)容