courses_controller_test.rb 1.46 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::CoursesControllerTest < ActionDispatch::IntegrationTest
4
  test '#index should return all courses' do
5
    get api_courses_url 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
    courses_returned = JSON.parse @response.body
    courses_count = Course.all.count
    assert_equal courses_count, courses_returned.count
Zac Wood's avatar
Zac Wood committed
11
  end
12

13
  test '#index should return filtered by subject case insensitive' do
14
    get api_courses_url subject: "Cs", semester_id: semesters(:fall2018).id
15
16
17
18
19
20
21
22
23
    assert_response :success

    courses_returned = JSON.parse @response.body
    courses_count = Course.where(subject: "CS").count

    assert_equal courses_count, courses_returned.count
  end

  test '#index should return filtered by subject and course number' do
24
    get api_courses_url subject: "CS", course_number: "112", semester_id: semesters(:fall2018).id
25
26
27
28
29
30
31
32
33
34
    assert_response :success

    courses_returned = JSON.parse @response.body
    courses_count = Course.where(subject: "CS", course_number: "112").count

    assert_equal courses_count, courses_returned.count
  end

  test '#show should return course_sections for course' do
    cs_112_id = courses(:cs112).id
Zac Wood's avatar
Zac Wood committed
35

36
    get api_course_url id: cs_112_id, semester_id: semesters(:fall2018).id
37
38
39
40
41
42
43
    assert_response :success

    sections_returned = JSON.parse @response.body
    cs_112_sections = CourseSection.where(course_id: cs_112_id)

    assert_equal cs_112_sections.count, sections_returned.count
  end
Zac Wood's avatar
Zac Wood committed
44
end