diff --git a/integration_tests/mada_test.go b/integration_tests/mada_test.go index cddad59..9225256 100644 --- a/integration_tests/mada_test.go +++ b/integration_tests/mada_test.go @@ -63,10 +63,10 @@ func teardown(db *gorm.DB) { return } // Perform teardown tasks here - //err := db.Migrator().DropTable(&api.User{}, &api.Station{}, &api.StationStatus{}, &api.StationSchedule{}) - //if err != nil { - // log.Fatal(err) - //} + err := db.Migrator().DropTable(&api.User{}, &api.Station{}, &api.StationStatus{}, &api.StationSchedule{}) + if err != nil { + log.Fatal(err) + } scraper.CloseDbConnection(db) } @@ -143,8 +143,7 @@ func TestScrapeMada(t *testing.T) { t.Fatal("no yesterday dates should be present in schedule") } todaySchedule := schedule.FilterByDate(today) - fmt.Println("todaySchedule", todaySchedule) - if len(todaySchedule) != 6 { + if len(todaySchedule) != 5 { t.Fatal(fmt.Sprintf("today should have 5 schedule points, has: %d", len(todaySchedule))) } @@ -168,12 +167,10 @@ func TestScrapeMada(t *testing.T) { } // make a put call to station - updateRequest := api.UpdateStationRequestObject{ Id: station.Id, Body: &api.UpdateStationJSONRequestBody{IsOpen: false}, } - fmt.Println("station.id", station.Id) _, err = srv.UpdateStation(context.TODO(), updateRequest) if err != nil { t.Fatal(err) @@ -187,11 +184,9 @@ func TestScrapeMada(t *testing.T) { for _, sc := range todaySchedule { if sc.StationName == "TestName" { - if sc.LastStatus == false { + if sc.LastStatus != false { t.Fatal("TestName should be closed") } } } } - -// check that schedule is updated diff --git a/pkg/api/api.gen.go b/pkg/api/api.gen.go index 13b0068..3257711 100644 --- a/pkg/api/api.gen.go +++ b/pkg/api/api.gen.go @@ -1,6 +1,6 @@ // Package api provides primitives to interact with the openapi HTTP API. // -// Code generated by github.com/deepmap/oapi-codegen/v2 version v2.0.0 DO NOT EDIT. +// Code generated by github.com/deepmap/oapi-codegen version v1.15.0 DO NOT EDIT. package api import ( diff --git a/server/server.go b/server/server.go index 70b7710..d59be41 100644 --- a/server/server.go +++ b/server/server.go @@ -47,8 +47,7 @@ func (s StrictBloodInfoServer) GetStations(ctx context.Context, request api.GetS // UpdateStation updates station func (s StrictBloodInfoServer) UpdateStation(ctx context.Context, request api.UpdateStationRequestObject) (api.UpdateStationResponseObject, error) { var sc api.StationSchedule - fmt.Println(">>>>>>>>>>>>>>>>>>>>> here I ammmmmmmm") - tx := s.Db.Where("station_id = ? and date = ?", request.Id, time.Now().Format(dateFormat)).First(&sc) + tx := s.Db.Where("station_id = ? and DATE(date) = ?", request.Id, time.Now().Format(dateFormat)).First(&sc) if tx.Error != nil { if errors.Is(tx.Error, gorm.ErrRecordNotFound) { // Handle the case when no record is found @@ -59,10 +58,13 @@ func (s StrictBloodInfoServer) UpdateStation(ctx context.Context, request api.Up } } + // TODO: get real user id // add a status to a schedule point + var userId int64 = 1 stationStatus := api.StationStatus{ StationScheduleId: *sc.Id, IsOpen: request.Body.IsOpen, + UserId: &userId, } tx = s.Db.Create(&stationStatus) if tx.Error != nil {