courses_controller_test.rb 1.31 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
Zac Wood's avatar
Zac Wood committed
6
    assert_response :success
Zac Wood's avatar
Zac Wood committed
7

8
    courses_returned = JSON.parse @response.body
9
    courses_count = Course.all.count
10
    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")
15
16
17
    assert_response :success

    courses_returned = JSON.parse @response.body
18
    courses_count = Course.where(subject: "CS").count
19
20
21
22
23

    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")
25
26
27
    assert_response :success

    courses_returned = JSON.parse @response.body
28
    courses_count = Course.where(subject: "CS", course_number: "112").count
29
30
31
32
33
34

    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)
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