Skip to content

Commit 33a53f7

Browse files
committed
chore: fix scorm test in case username contains a .
1 parent c858f69 commit 33a53f7

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

test/api/scorm_api_test.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ def app
99
Rails.application
1010
end
1111

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+
1216
def test_serve_scorm_content
1317
unit = FactoryBot.create(:unit)
1418
user = unit.projects.first.student
@@ -40,42 +44,42 @@ def test_serve_scorm_content
4044
td.save!
4145

4246
# 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')
4448
assert_equal 404, last_response.status
4549

4650
td.add_scorm_data(test_file_path('numbas.zip'), copy: true)
4751
td.save!
4852

4953
# 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')
5155
assert_equal 404, last_response.status
5256

5357
# 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')
5559
assert_equal 200, last_response.status
5660
assert_equal 'text/html', last_response.content_type
5761

5862
# 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)
6064
assert_equal 419, last_response.status
6165

62-
get "/api/scorm/#{td.id}/#{user.username}/#{auth_token(user, :login)}/index.html"
66+
get scorm_path(td, user, 'index.html', :login)
6367
assert_equal 419, last_response.status
6468

6569
# 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')
6771
assert_equal 200, last_response.status
6872
assert_equal 'text/css', last_response.content_type
6973

7074
# 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')
7276
assert_equal 200, last_response.status
7377
assert_equal 'text/javascript', last_response.content_type
7478

7579
tutor = FactoryBot.create(:user, :tutor, username: :test_tutor)
7680

7781
# 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')
7983
assert_equal 403, last_response.status
8084

8185
tutor.destroy!

0 commit comments

Comments
 (0)