Created
May 7, 2019 02:28
-
-
Save barbaromatrix/4d674f6c361e39b3493baeec80645742 to your computer and use it in GitHub Desktop.
Artillery processor help functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const httpErrorCodes = [400, 500, 501, 504] | |
module.exports.checkForRequestError = (requestData, errorList = httpErrorCodes) => | |
requestData.statusCode && errorList.indexOf(requestData.statusCode > -1) | |
module.exports.setupCouponActivationData = (requestParams, context, ee, next) => { | |
const coupons = context.vars.coupon_v2 | |
const filteredCoupons = coupons.find(coupon => !coupon.active) | |
context.vars.coupon_v2 = filteredCoupons ? filteredCoupons : coupons[0] | |
return next() | |
} | |
module.exports.isCouponAllowedToActivate = (context) => { | |
if (exports.checkForRequestError(context.coupon_v2)) { | |
return false | |
} | |
const coupons = context.coupon_v2 || [] | |
return coupons.filter(coupon => coupon.active === false).length > 0 | |
} | |
module.exports.writeLogFile = (filename, content) => | |
fs.writeFile(`${__dirname}/${filename}`, content, { flag: 'a+' }, (err) => { | |
if (err) console.error('Error when logging: ', err) | |
}) | |
module.exports.logResponse = ({ url, method, json }, { body }, context, ee, next) => { | |
const logData = { | |
request: { | |
url, | |
method | |
}, | |
response: body | |
} | |
exports.writeLogFile('stress_log.log', `${JSON.stringify(logData)}\n ====== \n`) | |
return next() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment