MCPcopy Create free account
hub / github.com/PrairieLearn/PrairieLearn / getQuestionSubmitInfo

Function getQuestionSubmitInfo

tools/load-test.js:158–186  ·  view source on GitHub ↗
(questionUrl)

Source from the content-addressed store, hash-verified

156}
157
158async function getQuestionSubmitInfo(questionUrl) {
159 const body = await request({uri: questionUrl, jar: cookies});
160 const $ = cheerio.load(body);
161
162 const elemList = $('.question-form input[name="__csrf_token"]');
163 assert(elemList.length == 1);
164 const csrf_token = elemList[0].attribs.value;
165
166 const questionSubmitInfo = {questionUrl, csrf_token};
167
168 if (argv.type == 'v2') {
169 const elemList = $('.question-data');
170 assert(elemList.length == 1);
171 assert(elemList[0].children != null);
172 assert(elemList[0].children.length == 1);
173 assert(elemList[0].children[0].data != null);
174 const questionData = JSON.parse(decodeURIComponent(Buffer.from(elemList[0].children[0].data, 'base64').toString()));
175 assert(questionData.variant != null);
176 questionSubmitInfo.variant = questionData.variant;
177 } else if (argv.type == 'v3') {
178 const elemList = $('.question-form input[name="__variant_id"]');
179 assert(elemList.length == 1);
180 questionSubmitInfo.variant_id = Number.parseInt(elemList[0].attribs.value);
181 } else {
182 throw new Error(`unknown type: ${argv.type}`);
183 }
184
185 return questionSubmitInfo;
186}
187
188async function postQuestionAnswer(questionSubmitInfo) {
189 let form;

Callers 1

singleRequestFunction · 0.85

Calls 2

assertFunction · 0.85
$Function · 0.50

Tested by

no test coverage detected