Skip to content

Commit

Permalink
fixed testcase failures
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Oct 10, 2023
1 parent 1f9d61a commit 980ba68
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
1 change: 1 addition & 0 deletions server/api/tumdev/campus_backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ message News {
string title = 2;
string text = 3;
string link = 4;
// where a news thumbnail is stored. empty string means no image is available
string image_url = 5;
string source = 6;
// when the news item was created in OUR database
Expand Down
2 changes: 1 addition & 1 deletion server/backend/movie.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *CampusServer) ListMovies(ctx context.Context, req *pb.ListMoviesRequest
Actors: movie.Actors,
ImdbRating: movie.ImdbRating,
Description: movie.Description,
CoverUrl: fmt.Sprintf("https://api.tum.app/files/%s/%s", movie.File.Path, movie.File.Name),
CoverUrl: fmt.Sprintf("https://api.tum.app/files/%s%s", movie.File.Path, movie.File.Name),
CoverId: movie.File.File,
Link: movie.Link,
})
Expand Down
12 changes: 5 additions & 7 deletions server/backend/movie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ var (
Actors: "Tom Cruise, Jeremy Renner, Simon Pegg, Paula Patton",
ImdbRating: "7.4",
Description: "The IMF is shut down when it's implicated in the bombing of the Kremlin, causing Ethan Hunt and his new team to go rogue to clear their organization's name.",
CoverName: "mission_impossible_4.jpg",
CoverPath: "movie/mission_impossible_4.jpg",
CoverUrl: "https://api.tum.app/files/movie/mission_impossible_4.jpg",
CoverId: 1,
Link: "https://www.imdb.com/title/tt1229238/",
}
Expand All @@ -70,8 +69,7 @@ var (
Actors: "Tom Cruise, Jeremy Renner, Simon Pegg, Rebecca Ferguson",
ImdbRating: "7.4",
Description: "Ethan and his team take on their most impossible mission yet when they have to eradicate an international rogue organization as highly skilled as they are and committed to destroying the IMF.",
CoverName: "mission_impossible_5.jpg",
CoverPath: "movie/mission_impossible_5.jpg",
CoverUrl: "https://api.tum.app/files/movie/mission_impossible_5.jpg",
CoverId: 2,
Link: "https://www.imdb.com/title/tt2381249/",
}
Expand All @@ -82,8 +80,8 @@ func (s *MovieSuite) Test_ListMoviesAll() {
s.mock.ExpectQuery("SELECT `kino`.`kino`,`kino`.`date`,`kino`.`created`,`kino`.`title`,`kino`.`year`,`kino`.`runtime`,`kino`.`genre`,`kino`.`director`,`kino`.`actors`,`kino`.`rating`,`kino`.`description`,`kino`.`trailer`,`kino`.`cover`,`kino`.`link`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded` FROM `kino` LEFT JOIN `files` `File` ON `kino`.`cover` = `File`.`file` WHERE kino > ?").
WithArgs(-1).
WillReturnRows(sqlmock.NewRows([]string{"kino", "date", "created", "title", "year", "runtime", "genre", "director", "actors", "rating", "description", "trailer", "cover", "link", "File__file", "File__name", "File__path", "File__downloads", "File__url", "File__downloaded"}).
AddRow(movie2.MovieId, movie2.Date.AsTime(), movie2.Created.AsTime(), movie2.Title, movie2.ReleaseYear, movie2.Runtime, movie2.Genre, movie2.Director, movie2.Actors, movie2.ImdbRating, movie2.Description, nil, movie2.CoverId, movie2.Link, movie2.CoverId, movie2.CoverName, movie2.CoverPath, 1, "", 1).
AddRow(movie1.MovieId, movie1.Date.AsTime(), movie1.Created.AsTime(), movie1.Title, movie1.ReleaseYear, movie1.Runtime, movie1.Genre, movie1.Director, movie1.Actors, movie1.ImdbRating, movie1.Description, nil, movie1.CoverId, movie1.Link, movie1.CoverId, movie1.CoverName, movie1.CoverPath, 1, "", 1))
AddRow(movie2.MovieId, movie2.Date.AsTime(), movie2.Created.AsTime(), movie2.Title, movie2.ReleaseYear, movie2.Runtime, movie2.Genre, movie2.Director, movie2.Actors, movie2.ImdbRating, movie2.Description, nil, movie2.CoverId, movie2.Link, movie2.CoverId, "mission_impossible_5.jpg", "movie/", 1, "", 1).
AddRow(movie1.MovieId, movie1.Date.AsTime(), movie1.Created.AsTime(), movie1.Title, movie1.ReleaseYear, movie1.Runtime, movie1.Genre, movie1.Director, movie1.Actors, movie1.ImdbRating, movie1.Description, nil, movie1.CoverId, movie1.Link, movie1.CoverId, "mission_impossible_4.jpg", "movie/", 1, "", 1))
response, err := server.ListMovies(context.Background(), &pb.ListMoviesRequest{LastId: -1})
require.NoError(s.T(), err)
require.Equal(s.T(), &pb.ListMoviesReply{Movies: []*pb.Movie{&movie2, &movie1}}, response)
Expand All @@ -94,7 +92,7 @@ func (s *MovieSuite) Test_ListMoviesOne() {
s.mock.ExpectQuery("SELECT `kino`.`kino`,`kino`.`date`,`kino`.`created`,`kino`.`title`,`kino`.`year`,`kino`.`runtime`,`kino`.`genre`,`kino`.`director`,`kino`.`actors`,`kino`.`rating`,`kino`.`description`,`kino`.`trailer`,`kino`.`cover`,`kino`.`link`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded` FROM `kino` LEFT JOIN `files` `File` ON `kino`.`cover` = `File`.`file` WHERE kino > ?").
WithArgs(1).
WillReturnRows(sqlmock.NewRows([]string{"kino", "date", "created", "title", "year", "runtime", "genre", "director", "actors", "rating", "description", "trailer", "cover", "link", "File__file", "File__name", "File__path", "File__downloads", "File__url", "File__downloaded"}).
AddRow(movie1.MovieId, movie1.Date.AsTime(), movie1.Created.AsTime(), movie1.Title, movie1.ReleaseYear, movie1.Runtime, movie1.Genre, movie1.Director, movie1.Actors, movie1.ImdbRating, movie1.Description, nil, movie1.CoverId, movie1.Link, movie1.CoverId, movie1.CoverName, movie1.CoverPath, 1, "", 1))
AddRow(movie1.MovieId, movie1.Date.AsTime(), movie1.Created.AsTime(), movie1.Title, movie1.ReleaseYear, movie1.Runtime, movie1.Genre, movie1.Director, movie1.Actors, movie1.ImdbRating, movie1.Description, nil, movie1.CoverId, movie1.Link, movie1.CoverId, "mission_impossible_4.jpg", "movie/", 1, "", 1))
response, err := server.ListMovies(context.Background(), &pb.ListMoviesRequest{LastId: 1})
require.NoError(s.T(), err)
require.Equal(s.T(), &pb.ListMoviesReply{Movies: []*pb.Movie{&movie1}}, response)
Expand Down
10 changes: 7 additions & 3 deletions server/backend/news.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s *CampusServer) ListNewsSources(ctx context.Context, _ *pb.ListNewsSource
resp = append(resp, &pb.NewsSource{
Source: fmt.Sprintf("%d", source.Source),
Title: source.Title,
IconUrl: fmt.Sprintf("https://api.tum.app/files/%s/%s", source.File.Path, source.File.Name),
IconUrl: fmt.Sprintf("https://api.tum.app/files/%s%s", source.File.Path, source.File.Name),
})
}
return &pb.ListNewsSourcesReply{Sources: resp}, nil
Expand Down Expand Up @@ -63,12 +63,16 @@ func (s *CampusServer) ListNews(ctx context.Context, req *pb.ListNewsRequest) (*
resp := make([]*pb.News, len(newsEntries))
for i, item := range newsEntries {
log.WithField("title", item.Title).Trace("sending news")
imgUrl := ""
if item.File != nil {
imgUrl = fmt.Sprintf("https://api.tum.app/files/%s%s", item.File.Path, item.File.Name)
}
resp[i] = &pb.News{
Id: item.News,
Title: item.Title,
Text: item.Description,
Link: item.Link,
ImageUrl: fmt.Sprintf("https://api.tum.app/files/%s/%s", item.File.Path, item.File.Name),
ImageUrl: imgUrl,
Source: fmt.Sprintf("%d", item.Src),
Created: timestamppb.New(item.Created),
Date: timestamppb.New(item.Date),
Expand Down Expand Up @@ -97,7 +101,7 @@ func (s *CampusServer) ListNewsAlerts(ctx context.Context, req *pb.ListNewsAlert
var alerts []*pb.NewsAlert
for _, alert := range res {
alerts = append(alerts, &pb.NewsAlert{
ImageUrl: fmt.Sprintf("https://api.tum.app/files/%s/%s", alert.File.Path, alert.File.Name),
ImageUrl: fmt.Sprintf("https://api.tum.app/files/%s%s", alert.File.Path, alert.File.Name),
Link: alert.Link.String,
Created: timestamppb.New(alert.Created),
From: timestamppb.New(alert.From),
Expand Down
24 changes: 12 additions & 12 deletions server/backend/news_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func newsFile(id int64) *model.File {
return &model.File{
File: id,
Name: fmt.Sprintf("src_%d.png", id),
Path: "news/sources",
Path: "news/sources/",
Downloads: 1,
URL: null.String{},
Downloaded: null.BoolFrom(true),
Expand All @@ -68,8 +68,8 @@ func source1() *model.NewsSource {
Source: 1,
Title: "Amazing News 1",
URL: null.StringFrom("https://example.com/amazing1"),
FileID: newsFile(2).File,
File: *newsFile(2),
FileID: newsFile(1).File,
File: *newsFile(1),
Hook: null.StringFrom(""),
}
}
Expand Down Expand Up @@ -99,8 +99,8 @@ func (s *NewsSuite) Test_ListNewsSourcesMultiple() {
require.NoError(s.T(), err)
expectedResp := &pb.ListNewsSourcesReply{
Sources: []*pb.NewsSource{
{Source: fmt.Sprintf("%d", source1().Source), Title: source1().Title, Icon: source1().File.URL.String},
{Source: fmt.Sprintf("%d", source2().Source), Title: source2().Title, Icon: source2().File.URL.String},
{Source: fmt.Sprintf("%d", source1().Source), Title: source1().Title, IconUrl: "https://api.tum.app/files/news/sources/src_1.png"},
{Source: fmt.Sprintf("%d", source2().Source), Title: source2().Title, IconUrl: "https://api.tum.app/files/news/sources/src_2.png"},
},
}
require.Equal(s.T(), expectedResp, response)
Expand Down Expand Up @@ -183,8 +183,8 @@ func (s *NewsSuite) Test_ListNewsMultiple() {
require.NoError(s.T(), err)
expectedResp := &pb.ListNewsReply{
News: []*pb.News{
{Id: n1.News, Title: n1.Title, Text: n1.Description, Link: n1.Link, ImageUrl: n1.Image.String, Source: fmt.Sprintf("%d", n1.Src), Created: timestamppb.New(n1.Created), Date: timestamppb.New(n1.Date)},
{Id: n2.News, Title: n2.Title, Text: n2.Description, Link: n2.Link, ImageUrl: n2.Image.String, Source: fmt.Sprintf("%d", n2.Src), Created: timestamppb.New(n2.Created), Date: timestamppb.New(n2.Date)},
{Id: n1.News, Title: n1.Title, Text: n1.Description, Link: n1.Link, ImageUrl: "https://api.tum.app/files/news/sources/src_1.png", Source: fmt.Sprintf("%d", n1.Src), Created: timestamppb.New(n1.Created), Date: timestamppb.New(n1.Date)},
{Id: n2.News, Title: n2.Title, Text: n2.Description, Link: n2.Link, ImageUrl: "", Source: fmt.Sprintf("%d", n2.Src), Created: timestamppb.New(n2.Created), Date: timestamppb.New(n2.Date)},
},
}
require.Equal(s.T(), expectedResp, response)
Expand All @@ -194,7 +194,7 @@ func newsAlertFile(id int64) *model.File {
return &model.File{
File: id,
Name: fmt.Sprintf("src_%d.png", id),
Path: "news/sources",
Path: "news/sources/",
Downloads: 1,
URL: null.String{},
Downloaded: null.BoolFrom(true),
Expand All @@ -216,8 +216,8 @@ func alert1() *model.NewsAlert {
func alert2() *model.NewsAlert {
return &model.NewsAlert{
NewsAlert: 2,
FileID: newsAlertFile(1).File,
File: *newsAlertFile(1),
FileID: newsAlertFile(2).File,
File: *newsAlertFile(2),
Name: null.String{},
Link: null.String{},
Created: time.Time.Add(time.Now(), time.Hour),
Expand Down Expand Up @@ -266,8 +266,8 @@ func (s *NewsSuite) Test_ListNewsAlertsMultiple() {
require.NoError(s.T(), err)
expectedResp := &pb.ListNewsAlertsReply{
Alerts: []*pb.NewsAlert{
{ImageUrl: a1.File.URL.String, Link: a1.Link.String, Created: timestamppb.New(a1.Created), From: timestamppb.New(a1.From), To: timestamppb.New(a1.To)},
{ImageUrl: a2.File.URL.String, Link: a2.Link.String, Created: timestamppb.New(a2.Created), From: timestamppb.New(a2.From), To: timestamppb.New(a2.To)},
{ImageUrl: "https://api.tum.app/files/news/sources/src_1.png", Link: a1.Link.String, Created: timestamppb.New(a1.Created), From: timestamppb.New(a1.From), To: timestamppb.New(a1.To)},
{ImageUrl: "https://api.tum.app/files/news/sources/src_2.png", Link: a2.Link.String, Created: timestamppb.New(a2.Created), From: timestamppb.New(a2.From), To: timestamppb.New(a2.To)},
}}
require.Equal(s.T(), expectedResp, response)
}
Expand Down

0 comments on commit 980ba68

Please sign in to comment.