course_sections_controller_test.rb 1.02 KB
Newer Older
Zac Wood's avatar
Zac Wood committed
1 2
require 'test_helper'

Zac Wood's avatar
Zac Wood committed
3
class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
Zac Wood's avatar
Zac Wood committed
4
  test 'should get index' do
5
    get api_course_sections_url course_id: courses(:cs112).id, semester_id: semesters(:fall2018).id
Zac Wood's avatar
Zac Wood committed
6
    assert_response :success
Zac Wood's avatar
Zac Wood committed
7

8 9 10 11
    sections_returned = JSON.parse @response.body
    num_sections = CourseSection.where(course_id: courses(:cs112).id).count

    assert_equal num_sections, sections_returned.count
Zac Wood's avatar
Zac Wood committed
12
  end
13 14

  test 'should filter by crn' do
15
    get api_course_sections_url crn: course_sections(:cs112001).crn, semester_id: semesters(:fall2018).id
16 17 18 19 20
    assert_response :success

    sections_returned = JSON.parse @response.body
    assert_equal course_sections(:cs112001).name, sections_returned[0]["name"]
  end
21 22

  test 'should filter by professor' do
23
    get api_course_sections_url instructor: "king", semester_id: semesters(:fall2018).id
24 25 26 27 28
    assert_response :success

    sections_returned = JSON.parse @response.body
    assert_equal course_sections(:cs112001).id, sections_returned[0]["id"]
  end
Zac Wood's avatar
Zac Wood committed
29
end