fix response header (Link) for all_quizzes api

flag=none

closes QUIZ-7487

test plan:
- create a course with more than 2 quizzes (new or old)
- open dev tool of chrome
- make a request to /api/v1/courses/:id/all_quizzes?per_page=2
- there should be response Link header, with correct current and
  next urls

Change-Id: Ic58ba11e8eed4e24a37004cc45c20be67944b35c
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/228813
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Stephen Kacsmark <skacsmark@instructure.com>
QA-Review: Mark McDermott <mmcdermott@instructure.com>
Product-Review: Han Yan <hyan@instructure.com>
This commit is contained in:
Han Yan 2020-03-04 07:26:08 -06:00
parent 37a489d083
commit 7399ebcf44
2 changed files with 26 additions and 1 deletions

View File

@ -43,7 +43,7 @@ class QuizzesNext::QuizzesApiController < ApplicationController
].cache_key
value = Rails.cache.fetch(cache_key) do
api_route = api_v1_course_quizzes_url(@context)
api_route = api_v1_course_all_quizzes_url(@context)
@quizzes = Api.paginate(all_quizzes, self, api_route)
{

View File

@ -152,6 +152,31 @@ describe QuizzesNext::QuizzesApiController, type: :request do
end
end
end
context 'when there are multiple data pages' do
subject do
api_call(
:get,
"/api/v1/courses/#{@course.id}/all_quizzes?per_page=2",
controller: "quizzes_next/quizzes_api",
action: "index",
format: "json",
course_id: @course.id.to_s,
per_page: 2
)
end
it "include a response header Link" do
subject
link_header = response.headers['Link']
expect(link_header).to eq(
"<http://www.example.com/api/v1/courses/#{@course.id}/all_quizzes?page=1&per_page=2>; rel=\"current\","\
"<http://www.example.com/api/v1/courses/#{@course.id}/all_quizzes?page=2&per_page=2>; rel=\"next\","\
"<http://www.example.com/api/v1/courses/#{@course.id}/all_quizzes?page=1&per_page=2>; rel=\"first\","\
"<http://www.example.com/api/v1/courses/#{@course.id}/all_quizzes?page=4&per_page=2>; rel=\"last\""
)
end
end
end
context 'as a student' do