In spec/services/canvas/client/conversations_spec.rb, the "when API returns empty array" test stubs the /api/v1/conversations endpoint to return []:
context 'when API returns empty array' do
it 'returns empty array' do
stubs.get('/api/v1/conversations') do
[200, {}, []]
end
# ...
end
endBut Conversations#list always passes include_all_conversation_ids: true, which changes the Canvas response format from an array to a Hash:
response = http_client.get(
ENDPOINT,
include_all_conversation_ids: true,
**params,
)Canvas's conversations_controller.rb wraps the response when include_all_conversation_ids is set:
if params[:include_all_conversation_ids]
@conversations_json = {
conversations: @conversations_json,
conversation_ids: @conversations_scope.conversation_ids
}
endSo the real empty response is:
{ "conversations": [], "conversation_ids": [] }Not [].
Our own shared context (spec/support/shared_examples/service_responses/canvas_conversations.rb) correctly uses a Hash for the successful case — the empty case should match.
Change the stub to return the actual response shape:
context 'when API returns empty conversations' do
it 'returns empty array' do
stubs.get('/api/v1/conversations') do
[200, {}, { 'conversations' => [], 'conversation_ids' => [] }]
end
result = conversations_client.list(scope:)
expect(result).to eq []
end
endThe individual conversation stubs in that test can also be removed since conversation_ids is empty — no individual fetches will be made.