fix: Fixed current course lookups not working, and added a test to prevent it

This commit is contained in:
Nicholas Novak 2023-11-23 00:33:05 -08:00
parent 91d11dedc0
commit 6de2ce9815
2 changed files with 32 additions and 1 deletions

View File

@ -29,7 +29,10 @@ type Schedule struct {
// //
// If no course is found, the error will be of type `ErrNoCurrentCourse` // If no course is found, the error will be of type `ErrNoCurrentCourse`
func (s Schedule) CurrentCourse() (string, error) { func (s Schedule) CurrentCourse() (string, error) {
currentTime := time.Now() currentTime, err := time.Parse(time.Kitchen, time.Now().Format(time.Kitchen))
if err != nil {
return "", err
}
for courseName, courseInfo := range s.Courses { for courseName, courseInfo := range s.Courses {
startTime, err := time.Parse(time.Kitchen, courseInfo.StartTime) startTime, err := time.Parse(time.Kitchen, courseInfo.StartTime)

28
schedule_test.go Normal file
View File

@ -0,0 +1,28 @@
package coursed
import (
"testing"
"time"
)
func TestSingleCourse(t *testing.T) {
testSch := Schedule{
Courses: map[string]CourseConfig{
"ubw101": CourseConfig{
StartTime: time.Now().Add(time.Minute * -5).Format(time.Kitchen),
EndTime: time.Now().Add(time.Minute * 10).Format(time.Kitchen),
Days: "MWF",
},
},
}
// TODO: Fix this
cur, err := testSch.CurrentCourse()
if err != nil {
t.Errorf("Error getting current course: %v", err)
}
if cur != "ubw101" {
t.Errorf("Expected current course to be ubw101, got %s", cur)
}
}