course_sections_controller_test.rb 1.13 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 6
    get api_course_sections_url(course_id: courses(:cs112).id,
                                semester_id: semesters(:fall2018).id)
Zac Wood's avatar
Zac Wood committed
7

Zac Wood's avatar
Zac Wood committed
8
    assert_response :success
Zac Wood's avatar
Zac Wood committed
9

10
    sections_returned = JSON.parse @response.body
11
    num_sections = CourseSection
Zac Wood's avatar
Zac Wood committed
12 13
                   .where(course_id: courses(:cs112).id)
                   .where(semester: semesters(:fall2018)).count
14 15

    assert_equal num_sections, sections_returned.count
Zac Wood's avatar
Zac Wood committed
16
  end
17 18

  test 'should filter by crn' do
19
    get api_course_sections_url crn: course_sections(:cs112001).crn, semester_id: semesters(:fall2018).id
20 21 22 23 24
    assert_response :success

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

  test 'should filter by professor' do
27
    get api_course_sections_url instructor: "king", semester_id: semesters(:fall2018).id
28 29 30 31 32
    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
33
end