You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
890 B
26 lines
890 B
const fs = require('fs');
|
|
const rules = require('./conditional-rules.js');
|
|
|
|
const answers = {};
|
|
|
|
const questions = JSON.parse(fs.readFileSync('api_questions.json', 'utf8'));
|
|
const context = { age: 25, gender: 'male' };
|
|
|
|
for (const q of questions) {
|
|
const mapped = {
|
|
id: q.id,
|
|
type: q.type,
|
|
title: q.title,
|
|
required: q.is_required !== undefined ? q.is_required : q.required,
|
|
baseRequired: q.required,
|
|
isVisible: q.is_visible,
|
|
conditionalRule: q.conditional_rule || q.visibility || q.logic || undefined,
|
|
visibility: q.visibility || q.conditional_rule || undefined,
|
|
logic: q.logic || undefined,
|
|
requiredWhen: q.required_when || undefined
|
|
};
|
|
|
|
const isVis = rules.isQuestionVisible(mapped, answers, context);
|
|
const isReq = rules.isQuestionRequired(mapped, answers, context);
|
|
console.log(`Q: ${q.id} | Visible: ${isVis} | Required: ${isReq}`);
|
|
}
|