Skip to content

Commit a988473

Browse files
committed
test: fix test attempt model checks
1 parent a46fb7f commit a988473

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

test/api/test_attempts_test.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ def test_get_task_attempts
7575

7676
add_auth_header_for(user: user)
7777

78+
response_keys = %w[id task_id terminated completion_status success_status score_scaled cmi_datamodel]
79+
7880
# When attempts exists
7981
get "api/projects/#{project.id}/task_def_id/#{td.id}/test_attempts"
8082
assert_equal 200, last_response.status
81-
assert_json_equal last_response_body, [attempt]
83+
assert_equal 1, last_response_body.size
84+
assert_json_matches_model attempt, last_response_body.first, response_keys
8285

8386
user1 = FactoryBot.create(:user, :student)
8487

@@ -137,17 +140,19 @@ def test_get_latest
137140

138141
add_auth_header_for(user: user)
139142

143+
response_keys = %w[id task_id terminated completion_status success_status score_scaled cmi_datamodel]
144+
140145
# When attempts exist
141146
get "api/projects/#{project.id}/task_def_id/#{td.id}/test_attempts/latest"
142147
assert_equal 200, last_response.status
143-
assert_json_equal last_response_body, attempt1
148+
assert_json_matches_model attempt1, last_response_body, response_keys
144149

145150
add_auth_header_for(user: user)
146151

147152
# Get completed latest
148153
get "api/projects/#{project.id}/task_def_id/#{td.id}/test_attempts/latest?completed=true"
149154
assert_equal 200, last_response.status
150-
assert_json_equal last_response_body, attempt
155+
assert_json_matches_model attempt, last_response_body, response_keys
151156

152157
user1 = FactoryBot.create(:user, :student)
153158

@@ -233,7 +238,8 @@ def test_review_attempt
233238
attempt.review
234239
attempt.save!
235240

236-
assert_json_equal last_response_body, attempt
241+
response_keys = %w[id task_id terminated completion_status success_status score_scaled cmi_datamodel]
242+
assert_json_matches_model attempt, last_response_body, response_keys
237243

238244
tutor = project.tutor_for(td)
239245

@@ -242,7 +248,7 @@ def test_review_attempt
242248
# When user is tutor
243249
get "api/test_attempts/#{attempt.id}/review"
244250
assert_equal 200, last_response.status
245-
assert_json_equal last_response_body, attempt
251+
assert_json_matches_model attempt, last_response_body, response_keys
246252

247253
user1 = FactoryBot.create(:user, :student)
248254

0 commit comments

Comments
 (0)