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

Function postQuestionAnswer

tools/load-test.js:188–216  ·  view source on GitHub ↗
(questionSubmitInfo)

Source from the content-addressed store, hash-verified

186}
187
188async function postQuestionAnswer(questionSubmitInfo) {
189 let form;
190
191 if (argv.type == 'v2') {
192 const submittedAnswer = {
193 wx: Math.floor(Math.random() * 10),
194 wy: Math.floor(Math.random() * 10),
195 };
196 form = {
197 __action: 'grade',
198 __csrf_token: questionSubmitInfo.csrf_token,
199 postData: JSON.stringify({variant: questionSubmitInfo.variant, submittedAnswer}),
200 };
201 } else if (argv.type == 'v3') {
202 form = {
203 __action: 'grade',
204 __csrf_token: questionSubmitInfo.csrf_token,
205 __variant_id: questionSubmitInfo.variant_id,
206 c: Math.floor(Math.random() * 10),
207 };
208 } else {
209 throw new Error(`unknown type: ${argv.type}`);
210 }
211
212 const body = await request.post({uri: questionSubmitInfo.questionUrl, jar: cookies, form, followAllRedirects: true});
213 const $ = cheerio.load(body);
214 const elemListVariantId = $('.question-form input[name="__csrf_token"]');
215 assert(elemListVariantId.length == 1);
216}
217
218async function singleRequest() {
219 const totalStartMS = Date.now();

Callers 1

singleRequestFunction · 0.85

Calls 2

assertFunction · 0.85
$Function · 0.50

Tested by

no test coverage detected