Created
May 13, 2019 17:58
-
-
Save barbaromatrix/7a29fa3b1ab810f60befa0f94ccbdc5f to your computer and use it in GitHub Desktop.
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.setupData = (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.isDataAllowedToBeUsed = (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