course_sections_controller_test.rb 1.15 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
    sections_returned = JSON.parse @response.body
9
10
11
12
    num_sections = CourseSection
                   .joins(course: :semester)
                   .where('semesters.id = ?', semesters(:fall2018).id)
                   .where(course_id: courses(:cs112).id).count
13
14

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

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

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

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