Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin Stats hotfix #139

Merged
merged 4 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/app/feedback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ func TestFeedbackHandler(t *testing.T) {

handleFeedbackLastWeek(session, feedbackStorage)

if len(session.Job.Output) != 11 {
t.Errorf("Expected 11 feedback items, got %d", len(session.Job.Output))
if len(session.Job.Output) != 5 {
t.Errorf("Expected 5 feedback items, got %d", len(session.Job.Output))
}
if session.Job.Output[6].TextID != "\nTest feedback\n" {
t.Errorf("Expected Test feedback, got %s", session.Job.Output[0].TextID)
if session.Job.Output[3].TextID != "John Doe:\nTest feedback\n" {
t.Errorf("Expected Test feedback, got %s", session.Job.Output[3].TextID)
}
if session.Job.Output[10].TextID != "\nTest feedback 2\n" {
t.Errorf("Expected Test feedback 2, got %s", session.Job.Output[0].TextID)
if session.Job.Output[4].TextID != "John Doe:\nTest feedback 2\n" {
t.Errorf("Expected Test feedback 2, got %s", session.Job.Output[4].TextID)
}
}
2 changes: 1 addition & 1 deletion internal/app/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestStatsHandler(t *testing.T) {

handleStats(session, adminStorage, feedbackStorage)

if session.Job.Output[0].TextID != "The total number of users is 100\nThe total number of active users is 75\nThe total number of notes is 999\n\nFeedback from last week 📈\n\nJohn \nDoe\n:\n\nTest feedback\n\nJohn \nDoe\n:\n\nTest feedback 2\n\n" {
if session.Job.Output[0].TextID != "The total number of users is 100\nThe total number of active users is 75\nThe total number of notes is 999\n\nFeedback from last week 📈\n\nJohn Doe:\nTest feedback\n\nJohn Doe:\nTest feedback 2\n\n" {
t.Error("Wrong result, got", session.Job.Output[0].TextID)
}
}
15 changes: 6 additions & 9 deletions internal/helpers/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,16 @@ func PrepareFeedback(ctx *context.Context, locale translator.Locale, feedbackSto
array = append(array, "")

for _, f := range feedback {
var hasName bool
var name string

if f.User.FirstName != nil {
array = append(array, *f.User.FirstName+" ")
hasName = true
name += *f.User.FirstName + " "
}
if f.User.LastName != nil {
array = append(array, *f.User.LastName)
hasName = true
}
if hasName {
array = append(array, ":")
name += *f.User.LastName
}
array = append(array, "\n"+f.Feedback.Text+"\n")
name = name + ":"
array = append(array, name+"\n"+f.Feedback.Text+"\n")
}

return array
Expand Down
12 changes: 6 additions & 6 deletions internal/helpers/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func TestGetStats(t *testing.T) {
context := context.Background()
stats := GetStats(&context, translator.EN, adminStorage, feedbackStorage)

if len(stats) != 14 {
t.Error("Expected 14 stats, got", len(stats))
if len(stats) != 8 {
t.Error("Expected 8 stats, got", len(stats))
}

if stats[0] != "The total number of users is 100" {
Expand All @@ -31,11 +31,11 @@ func TestGetStats(t *testing.T) {
t.Error("Expected The total number of notes is 999, got", stats[2])
}

if stats[9] != "\nTest feedback\n" {
t.Error("Expected Test feedback, got", stats[9])
if stats[6] != "John Doe:\nTest feedback\n" {
t.Error("Expected feedback, got", stats[6])
}

if stats[13] != "\nTest feedback 2\n" {
t.Error("Expected Test feedback 2, got", stats[9])
if stats[7] != "John Doe:\nTest feedback 2\n" {
t.Error("Expected feedback, got", stats[7])
}
}
2 changes: 1 addition & 1 deletion internal/scheduler/admin_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestAdminStats(t *testing.T) {

response := prepareAdminStats(&context, locale, adminStorage, feedbackStorage)

if *response != "The total number of users is 100\nThe total number of active users is 75\nThe total number of notes is 999\n\nFeedback from last week 📈\n\nJohn \nDoe\n:\n\nTest feedback\n\nJohn \nDoe\n:\n\nTest feedback 2\n\n" {
if *response != "The total number of users is 100\nThe total number of active users is 75\nThe total number of notes is 999\n\nFeedback from last week 📈\n\nJohn Doe:\nTest feedback\n\nJohn Doe:\nTest feedback 2\n\n" {
t.Errorf("Expected valid response, got %s", *response)
}
}
Loading