|
9 | 9 | Rails.application |
10 | 10 | end |
11 | 11 |
|
| 12 | + def scorm_path(task_def, user, file, token_type = :scorm) |
| 13 | + "/api/scorm/#{task_def.id}/#{user.username.gsub('.', '%2e')}/#{auth_token(user, token_type)}/#{file}" |
| 14 | + end |
| 15 | + |
12 | 16 | def test_serve_scorm_content |
13 | 17 | unit = FactoryBot.create(:unit) |
14 | 18 | user = unit.projects.first.student |
@@ -40,42 +44,42 @@ def test_serve_scorm_content |
40 | 44 | td.save! |
41 | 45 |
|
42 | 46 | # When the task def does not have SCORM data |
43 | | - get "/api/scorm/#{td.id}/#{user.username}/#{auth_token(user, :scorm)}/index.html" |
| 47 | + get scorm_path(td, user, 'index.html') |
44 | 48 | assert_equal 404, last_response.status |
45 | 49 |
|
46 | 50 | td.add_scorm_data(test_file_path('numbas.zip'), copy: true) |
47 | 51 | td.save! |
48 | 52 |
|
49 | 53 | # When the file is missing |
50 | | - get "/api/scorm/#{td.id}/#{user.username}/#{auth_token(user, :scorm)}/index1.html" |
| 54 | + get scorm_path(td, user, 'index1.html') |
51 | 55 | assert_equal 404, last_response.status |
52 | 56 |
|
53 | 57 | # When the file is present - html |
54 | | - get "/api/scorm/#{td.id}/#{user.username}/#{auth_token(user, :scorm)}/index.html" |
| 58 | + get scorm_path(td, user, 'index.html') |
55 | 59 | assert_equal 200, last_response.status |
56 | 60 | assert_equal 'text/html', last_response.content_type |
57 | 61 |
|
58 | 62 | # Cannot access with the wrong token type |
59 | | - get "/api/scorm/#{td.id}/#{user.username}/#{auth_token(user, :general)}/index.html" |
| 63 | + get scorm_path(td, user, 'index.html', :general) |
60 | 64 | assert_equal 419, last_response.status |
61 | 65 |
|
62 | | - get "/api/scorm/#{td.id}/#{user.username}/#{auth_token(user, :login)}/index.html" |
| 66 | + get scorm_path(td, user, 'index.html', :login) |
63 | 67 | assert_equal 419, last_response.status |
64 | 68 |
|
65 | 69 | # When the file is present - css |
66 | | - get "/api/scorm/#{td.id}/#{user.username}/#{auth_token(user, :scorm)}/styles.css" |
| 70 | + get scorm_path(td, user, 'styles.css') |
67 | 71 | assert_equal 200, last_response.status |
68 | 72 | assert_equal 'text/css', last_response.content_type |
69 | 73 |
|
70 | 74 | # When the file is present - js |
71 | | - get "/api/scorm/#{td.id}/#{user.username}/#{auth_token(user, :scorm)}/scripts.js" |
| 75 | + get scorm_path(td, user, 'scripts.js') |
72 | 76 | assert_equal 200, last_response.status |
73 | 77 | assert_equal 'text/javascript', last_response.content_type |
74 | 78 |
|
75 | 79 | tutor = FactoryBot.create(:user, :tutor, username: :test_tutor) |
76 | 80 |
|
77 | 81 | # When the user is unauthorised |
78 | | - get "/api/scorm/#{td.id}/#{tutor.username}/#{auth_token(tutor, :scorm)}/index.html" |
| 82 | + get scorm_path(td, tutor, 'index.html') |
79 | 83 | assert_equal 403, last_response.status |
80 | 84 |
|
81 | 85 | tutor.destroy! |
|
0 commit comments