Skip to content

Commit

Permalink
fix update station and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
borod108 committed Dec 7, 2023
1 parent 1f50247 commit 462674b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
17 changes: 6 additions & 11 deletions integration_tests/mada_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)))
}

Expand All @@ -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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion pkg/api/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 462674b

Please sign in to comment.