(action, fileEditContents, url, expectedToFindResults, expectedToFindChoice, expectedDiskContents)
| 432 | } |
| 433 | |
| 434 | function editPost(action, fileEditContents, url, expectedToFindResults, expectedToFindChoice, expectedDiskContents) { |
| 435 | describe(`POST to edit url with action ${action}`, function() { |
| 436 | it('should load successfully', function(callback) { |
| 437 | let form = { |
| 438 | __action: action, |
| 439 | __csrf_token: locals.__csrf_token, |
| 440 | file_edit_contents: b64EncodeUnicode(fileEditContents), |
| 441 | file_edit_user_id: locals.file_edit_user_id, |
| 442 | file_edit_course_id: locals.file_edit_course_id, |
| 443 | file_edit_dir_name: locals.file_edit_dir_name, |
| 444 | file_edit_file_name: locals.file_edit_file_name, |
| 445 | file_edit_orig_hash: locals.file_edit_orig_hash, |
| 446 | }; |
| 447 | locals.preEndTime = Date.now(); |
| 448 | request.post({url: url, form: form, followAllRedirects: true}, function (error, response, body) { |
| 449 | if (error) { |
| 450 | return callback(error); |
| 451 | } |
| 452 | locals.postEndTime = Date.now(); |
| 453 | if (response.statusCode != 200) { |
| 454 | return callback(new Error('bad status: ' + response.statusCode + '\n' + body)); |
| 455 | } |
| 456 | page = body; |
| 457 | callback(null); |
| 458 | }); |
| 459 | }); |
| 460 | it('should parse', function() { |
| 461 | locals.$ = cheerio.load(page); |
| 462 | }); |
| 463 | if ((action == 'save_and_sync') || (action == 'pull_and_save_and_sync')) { |
| 464 | verifyEdit(expectedToFindResults, expectedToFindChoice, fileEditContents, expectedDiskContents); |
| 465 | } |
| 466 | }); |
| 467 | } |
| 468 | |
| 469 | function jsonToContents(json) { |
| 470 | return JSON.stringify(json, null, 4) + '\n'; |
no test coverage detected