(questionSubmitInfo)
| 186 | } |
| 187 | |
| 188 | async 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 | |
| 218 | async function singleRequest() { |
| 219 | const totalStartMS = Date.now(); |
no test coverage detected