course_sections_controller_test.rb 929 Bytes
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
Zac Wood's avatar
Zac Wood committed
5
    get api_course_sections_url course_id: courses(:cs112).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
Zac Wood's avatar
Zac Wood committed
15
    get api_course_sections_url crn: course_sections(:cs112001).crn
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
Zac Wood's avatar
Zac Wood committed
23
    get api_course_sections_url instructor: "king"
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