Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const detectInputAfterTimerHasCompleted = function (data) {
const anomalyReports = []
const addToOutput = (...args) => anomalyReports.push(report(...args))
if (!RA.isPlainObj(data)) {
return
}
// For each question we need to check that the inputs were not
// received after the questionTimer completed
const markedAnswers = R.pathOr([], ['markedAnswers', 'answer'], data) // contains the question info
const audits = R.pathOr([], ['checkPayload', 'audit'], data)
markedAnswers.forEach(markedAnswer => {
const questionTimerEndEvent = getQuestionTimerEndEvent(
audits,
markedAnswer.questionNumber,
markedAnswer.factor1,
markedAnswer.factor2
)
if (!questionTimerEndEvent) {
const checkTookTooLong = function (data) {
if (!RA.isPlainObj(data)) {
throw new TypeError('data should be an object')
}
if (R.pathEq(['checkPayload', 'config', 'nextBetweenQuestions'], true, data)) {
// This calculation is meaningless as the user controls the total time of the check
return
}
if (hasRefresh(R.pathOr([], ['checkPayload', 'audit'], data))) {
// Hitting refresh is most likely going to take the check over the time-limit.
return
}
const markedAnswers = R.pathOr([], ['markedAnswers', 'answer'], data) // contains the question info
const config = R.pathOr({}, ['checkPayload', 'config'], data)
const numberOfQuestions = R.length(markedAnswers) || 0
},
checkPayload: {
config: {
loadingTime: 3,
questionTime: 6,
questionReader: true
},
audit: [
{ type: 'CheckStarted', clientTimestamp: '2019-05-31T14:20:04.100Z' },
{ type: 'CheckSubmissionPending', clientTimestamp: '2019-05-31T14:22:00.100Z' }
]
}
}
const r1 = detectCheckTookTooLong(data)
expect(r1).toBeDefined()
expect(RA.isPlainObj(r1)).toBe(true)
expect(r1.Message).toEqual('Check took too long')
expect(r1['Tested Value']).toBe(116)
expect(r1['Expected Value']).toBe(115)
})
},
{
type: 'QuestionTimerCancelled',
clientTimestamp: '2019-06-26T11:00:06.002Z',
data: {
sequenceNumber: 1,
question: '1x110'
}
}
]
}
}
const r = detectQuestionsAfterCutoff(data)
expect(r).toBeDefined()
expect(isArray(r)).toBe(true)
expect(isPlainObj(r[0])).toBe(true)
expect(r[0].Message).toBe('Answer after cutoff')
expect(r[0]['Tested Value']).toBe('2019-06-26T11:00:10.000Z')
})