I am trying to iterate through an array of functions that return an object with a boolean property used to stop iteration through the array (if false) and return the reason.
However I cannot get my claimCheck to fail even when I make each function return allowed : false ??
Am I calling these properly in claimTests.forEach ?? Not sure what I'm doing wrong??
TEST FUNCTIONS
async function allowedArea() {
let allowed = false
if (allowed == false) {
return { allowed: false, reason: "Area blocked" }
}
return { allowed: true, reason: "pass" }
}
async function validSubscription() {
let allowed = false // will be an await in the future
if (allowed == false) {
return { allowed: false, reason: "Bad Subscription" }
}
return { allowed: true, reason: "pass" }
}
Iterate through array containing the test functions
const claimCheck = async (user, claimCoords) => {
let result
let claimTests = [allowedArea, validSubscription]
claimTests.forEach(function (func) {
result = func() // run your function
if (result.allowed == false) {
return { allowed: false, reason: result.reason }
}
})
// If ALL functions pass (allowed: true)
return { allowed: true }
}
// calling in another file
module.exports = claimCheck