File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,9 @@ def self.with_users(current_user)
5353 end
5454
5555 def with_user ( current_user )
56+ # students cannot call the Profile API so do not even try
57+ return [ self , nil ] if current_user &.student?
58+
5659 school = School . find_by ( id : school_id )
5760 students = SchoolStudent ::List . call ( school :, token : current_user . token ,
5861 student_ids : [ user_id ] ) [ :school_students ] || [ ]
Original file line number Diff line number Diff line change 274274 expect ( pair ) . to eq ( [ project , user ] )
275275 end
276276
277+ it 'calls the Profile API to fetch the user' do
278+ project = create ( :project , user_id : student . id , school_id : school . id )
279+
280+ allow ( SchoolStudent ::List ) . to receive ( :call ) . and_call_original
281+
282+ project . with_user ( teacher )
283+
284+ expect ( SchoolStudent ::List ) . to have_received ( :call ) . with (
285+ school :,
286+ token : teacher . token ,
287+ student_ids : [ student . id ]
288+ )
289+ end
290+
277291 it 'returns a nil value if the member has no profile account' do
278292 user_id = SecureRandom . uuid
279293 project = create ( :project , user_id :)
280294
281295 pair = project . with_user ( teacher )
282296 expect ( pair ) . to eq ( [ project , nil ] )
283297 end
298+
299+ context 'when current_user is a student' do
300+ it 'returns the project with nil user without calling Profile API' do
301+ project = create ( :project , user_id : student . id , school_id : school . id )
302+
303+ allow ( SchoolStudent ::List ) . to receive ( :call )
304+
305+ pair = project . with_user ( student )
306+
307+ expect ( pair ) . to eq ( [ project , nil ] )
308+ expect ( SchoolStudent ::List ) . not_to have_received ( :call )
309+ end
310+ end
284311 end
285312
286313 describe '#last_edited_at' do
You can’t perform that action at this time.
0 commit comments