(self.webpackChunk_postman_app_scratchpad=self.webpackChunk_postman_app_scratchpad||[]).push([[4],{8242:function(e,s,t){var r=t(530),n=t(527),a={validateRunscope:function(e){if("string"==typeof e&&(e=JSON.parse(e)),e.hasOwnProperty("name")&&e.hasOwnProperty("trigger_url"))return e;throw{message:"Not a runscope test"}},initCollection:function(e){return{id:n(),name:e.name,description:e.description,order:[],folders:[],requests:[],timestamp:(new Date).getTime()}},getPostmanHeadersFromRunscopeHeaders:function(e){var s="";for(var t in e)e.hasOwnProperty(t)&&(s+=t+":"+e[t]+"\n");return s},addRequest:function(e,s){e.order.push(s.id),s.collectionId=e.id,e.requests.push(s)},handleAuth:function(e,s){s.auth&&"basic"===s.auth.auth_type&&(e.currentHelper="basicAuth",e.helperAttributes={id:"basic",saveToRequest:!0,username:s.auth.username,password:s.auth.password})},handleData:function(e,s){if("string"==typeof s.body&&"{}"==JSON.stringify(s.form))e.dataMode="raw",e.data=s.body;else if(s.form){e.dataMode="urlencoded";var t=[];for(var r in s.form)s.form.hasOwnProperty(r)&&t.push({key:r,value:s.form[r][0]});e.data=t}},handleScripts:function(e,s){s.before_scripts||(s.before_scripts=[]),e.preRequestScript="";var t=s.before_scripts.join("\n");t=t.replace(/\n/g,"\n//"),r.isEmpty(t)||(e.preRequestScript="//==== You will need to convert this to a Postman-compliant script ====\n//==== (Select text and use Ctrl + / (Win) or Cmd + / (Mac) to uncomment ====\n//"+t),s.scripts||(s.scripts=[]);var n=s.scripts.join("\n");n=n.replace(/\n/g,"\n//"),r.isEmpty(n)||(e.tests+="//==== You will need to convert this to a Postman-compliant script ====\n//==== (Select text and use Ctrl + / (Win) or Cmd + / (Mac) to uncomment ====\n//"+n)},getRHSFromComparisonAndOperands:function(e,s,t){switch(e){case"equal_number":case"equal":return s+" == "+t;case"not_equal":return s+"!="+t;case"empty":return"_.isEmpty("+s+")";case"not_empty":return"!_.isEmpty("+s+")";case"contains":return"_.contains("+s+")";case"does_not_contain":return"!_.contains("+s+")";case"is_a_number":return"!isNaN("+s+")";case"is_less_than":return s+" < "+t;case"is_less_than_or_equal":return s+" <= "+t;case"is_greater_than":return s+" > "+t;case"is_greater_than_or_equal":return s+" >= "+t;case"has_key":return s+".hasOwnProperty("+t+")";case"has_value":return"_.contains(_.values("+s+"), "+t+")";default:return"<comparison here>"}},handleAssertions:function(e,s){var t="",n=this;r.each(s.assertions,function(e){var s="",r=null,a="'"+e.value+"'",o="";switch(e.source){case"response_status":s+="Status Code is correct",r="responseCode.code";break;case"response_headers":s+="'"+e.property+"' Response Header is correct",r="postman.getResponseHeader('"+e.property+"')";break;case"response_json":e.property?(s+="Response."+e.property+" is correct",r="JSON.parse(responseBody)."+e.property):(s+="JSON Response is correct",r="JSON.parse(responseBody)");break;case"response_size":s+="//";break;case"response_text":s+="Response text is correct",r="responseBody";break;case"response_time":s+="Response time is correct",r="responseTime"}r&&((o='tests["'+s+'"] = '+n.getRHSFromComparisonAndOperands(e.comparison,r,a)+";").indexOf("JSON.parse")>-1&&(o="try {\n\t"+o+'\n}\ncatch(e) {\n\ttests["'+s+'"] = false;\n\tconsole.log("Could not parse JSON");\n}'),t+=o+"\n\n")}),r.isEmpty(t)||(e.tests+="//==== This section is Postman-compliant ====\n"+t+"\n")},getRequestFromStep:function(e){var s=this,t={id:n(),url:e.url,headers:s.getPostmanHeadersFromRunscopeHeaders(e.headers),pathVariables:{},method:e.method,name:e.url,description:e.note,tests:""};return s.handleData(t,e),s.handleAuth(t,e),s.handleAssertions(t,e),s.handleScripts(t,e),t},convert:function(e){var s=this;e=this.validateRunscope(e);var t=this.initCollection(e);return r.each(e.steps,function(e){s.addRequest(t,s.getRequestFromStep(e))}),t}};e.exports=a}}]);