     conn = get conn, student_path(conn, :new)
     assert html_response(conn, 200) =~ "New student"
   end
+
+  test "gets empty list when student has no course assigned" do
+    {:ok, student} = Students.new(@valid_attrs, "whatever")
+    assert Students.courses(student.id) == []
+  end
+
+  test "gets list of courses when student has assigned courses" do
+    course = create_course("english")
+    term = create_term("FALL",
+                       %Ecto.Date{day: 1, month: 1, year: 2017},
+                       %Ecto.Date{day: 1, month: 6, year: 2017},
+                       course)
+    {:ok, student} = Students.new(@valid_attrs, "whatever")
+    create_offered_course(term, course, [student])
+    student_courses = Students.courses(student.id)
+
+    assert course.id == List.first(student_courses).course.id
+    assert term.id == List.first(student_courses).term.id
+  end
+
+  test "gets list of courses ordered descendingly by term starting_date when student has multiple courses assigned to" do
+    course = create_course("english")
+    term1 = create_term("FALL",
+                       %Ecto.Date{day: 1, month: 1, year: 2017},
+                       %Ecto.Date{day: 1, month: 6, year: 2017},
+                       course)
+    {:ok, student} = Students.new(@valid_attrs, "whatever")
+    term2 = create_term("FALL",
+                       %Ecto.Date{day: 1, month: 1, year: 2018},
+                       %Ecto.Date{day: 1, month: 6, year: 2018},
+                       course)
+    create_offered_course(term1, course, [student])
+    create_offered_course(term2, course, [student])
+    student_courses = Students.courses(student.id)
+
+    assert course.id == List.first(student_courses).course.id
+    assert term2.id == List.first(student_courses).term.id
+    assert course.id == List.last(student_courses).course.id
+    assert term1.id == List.last(student_courses).term.id
+  end
 end

    email: "testuser@example.com",
    password: "secret",
    password_confirmation: "secret"}

  setup do
    conn =

defmodule CoursePlanner.StudentControllerTest do
  use CoursePlanner.ConnCase

  alias CoursePlanner.{Course, OfferedCourse, Repo, User, Students}
  alias CoursePlanner.Terms.Term

  @valid_attrs %{name: "some content", email: "valid@email"}
  @invalid_attrs %{}
