Skip to content

Commit a1b1360

Browse files
committed
test: ensure inbox returns tasks for tutors students only
1 parent 4f3439a commit a1b1360

File tree

1 file changed

+91
-8
lines changed

1 file changed

+91
-8
lines changed

test/api/units/feedback_test.rb

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,109 @@ def test_get_awaiting_feedback
3333
end
3434

3535
def test_tasks_for_task_inbox
36-
unit = FactoryBot.create(:unit, perform_submissions: true, unenrolled_student_count: 0, part_enrolled_student_count: 0, tutorials: 2, staff_count: 2)
37-
38-
expected_count = unit.tasks.where(task_status: [TaskStatus.ready_for_feedback, TaskStatus.need_help]).count
39-
40-
unit.teaching_staff.each do |user|
41-
expected_response = unit.tasks_for_task_inbox(user)
42-
36+
unit = FactoryBot.create(:unit, perform_submissions: true, unenrolled_student_count: 0, part_enrolled_student_count: 0, tutorials: 2, staff_count: 2, student_count: 2, task_count: 0)
37+
38+
td1 = TaskDefinition.create!({
39+
unit_id: unit.id,
40+
tutorial_stream: unit.tutorial_streams.first,
41+
name: 'Code task',
42+
description: 'Code task',
43+
weighting: 4,
44+
target_grade: 0,
45+
start_date: Time.zone.now - 2.weeks,
46+
target_date: Time.zone.now + 1.week,
47+
abbreviation: 'CodeTask',
48+
restrict_status_updates: false,
49+
upload_requirements: [{ "key" => 'file0', "name" => 'Shape Class', "type" => 'code' }],
50+
plagiarism_warn_pct: 0.8,
51+
is_graded: true,
52+
max_quality_pts: 0
53+
})
54+
55+
td2 = TaskDefinition.create!({
56+
unit_id: unit.id,
57+
tutorial_stream: unit.tutorial_streams.first,
58+
name: 'Code task2',
59+
description: 'Code task2',
60+
weighting: 4,
61+
target_grade: 0,
62+
start_date: Time.zone.now - 2.weeks,
63+
target_date: Time.zone.now + 1.week,
64+
abbreviation: 'CodeTask2',
65+
restrict_status_updates: false,
66+
upload_requirements: [{ "key" => 'file0', "name" => 'Shape Class', "type" => 'code' }],
67+
plagiarism_warn_pct: 0.8,
68+
is_graded: true,
69+
max_quality_pts: 0
70+
})
71+
72+
student1 = unit.active_projects.first
73+
student2 = unit.active_projects.second
74+
tutor1 = unit.tutors.first
75+
tutor2 = unit.tutors.second
76+
77+
tutorial1 = unit.tutorials.first
78+
tutorial2 = unit.tutorials.second
79+
80+
assert_not_nil student1
81+
assert_not_nil student2
82+
assert_not_nil tutor1
83+
assert_not_nil tutor2
84+
assert_not_nil tutorial1
85+
assert_not_nil tutorial2
86+
87+
unit.employ_staff(tutor1, Role.tutor)
88+
unit.employ_staff(tutor2, Role.tutor)
89+
90+
tutorial1.assign_tutor(tutor1)
91+
tutorial2.assign_tutor(tutor2)
92+
93+
student1.enrol_in(tutorial1)
94+
student2.enrol_in(tutorial2)
95+
96+
# Submit tasks ready for feedback
97+
student1_task1 = student1.task_for_task_definition(td1)
98+
student2_task1 = student2.task_for_task_definition(td1)
99+
DatabasePopulator.assess_task(student1, student1_task1, tutor1, TaskStatus.ready_for_feedback, Time.zone.now)
100+
DatabasePopulator.assess_task(student2, student2_task1, tutor2, TaskStatus.ready_for_feedback, Time.zone.now)
101+
102+
# Add comments to unsubmitted task
103+
student1_task2 = student1.task_for_task_definition(td2)
104+
student2_task2 = student2.task_for_task_definition(td2)
105+
comment1 = student1_task2.add_text_comment(student1.user, "Test 1")
106+
comment2 = student2_task2.add_text_comment(student2.user, "Test 1")
107+
assert_not_nil comment1
108+
assert_not_nil comment2
109+
110+
[tutor1, tutor2].each do |user|
43111
# Add auth_token and username to header
44112
add_auth_header_for(user: user)
45113

114+
# Defaults inbox?my_students_only = false
46115
get "/api/units/#{unit.id}/tasks/inbox"
47116

117+
# 2 submissions ready for feedback + 2 tasks with unread comments = 4 total
48118
assert_equal 200, last_response.status, last_response_body
49-
assert_equal expected_count, last_response_body.count, last_response_body
119+
assert_equal 4, last_response_body.count, last_response_body
50120

51121
# check each is the same
122+
expected_response = unit.tasks_for_task_inbox(user)
52123
last_response_body.zip(expected_response).each do |response, expected|
53124
assert_json_matches_model expected, response, ['id']
54125
end
55126

127+
get "/api/units/#{unit.id}/tasks/inbox?my_students_only=true"
128+
129+
# 1 submission ready for feedback + 1 task with unread comments = 2 total
130+
assert_equal 200, last_response.status, last_response_body
131+
assert_equal 2, last_response_body.count, last_response_body
132+
133+
# check each is the same
134+
expected_response2 = unit.tasks_for_task_inbox(user, true)
135+
last_response_body.zip(expected_response2).each do |response, expected|
136+
assert_json_matches_model expected, response, ['id']
137+
end
138+
56139
# Test task explorer
57140
get "/api/units/#{unit.id}/task_definitions/#{unit.task_definitions.first.id}/tasks"
58141

0 commit comments

Comments
 (0)