test(GODT-3162): Add step definition for checking KB article suggestions

* Add a step definition that takes input from a possible problem report description, and gets the suggested knowledge base articles
* Also, has input of what those knowledge base articles should be, just their title and url, and compares these two values.
* A sample integration test is added
This commit is contained in:
Gjorgji Slamkov
2023-12-15 09:53:49 +00:00
parent 8f5bd37aee
commit 3ac59d6943
3 changed files with 49 additions and 0 deletions

View File

@ -31,6 +31,7 @@ import (
"github.com/Masterminds/semver/v3"
"github.com/ProtonMail/proton-bridge/v3/internal/bridge"
"github.com/ProtonMail/proton-bridge/v3/internal/events"
"github.com/ProtonMail/proton-bridge/v3/internal/kb"
"github.com/ProtonMail/proton-bridge/v3/internal/vault"
"github.com/cucumber/godog"
"github.com/golang/mock/gomock"
@ -236,6 +237,30 @@ func (s *scenario) theUserReportsABugWithDetails(value *godog.DocString) error {
return bugReport.report()
}
func (s *scenario) theDescriptionInputProvidesKnowledgeBaseArticles(description string, value *godog.DocString) error {
var wantSuggestions kb.ArticleList
if err := json.Unmarshal([]byte(value.Content), &wantSuggestions); err != nil {
return fmt.Errorf("Cannot parse wanted suggestions: %w", err)
}
haveSuggestions, err := s.t.bridge.GetKnowledgeBaseSuggestions(description)
if err != nil {
return err
}
for i := 0; i < len(wantSuggestions); i++ {
if haveSuggestions[i].URL != wantSuggestions[i].URL {
return fmt.Errorf("Description \"%v\" has URL: \"%v\", want: \"%v\"", description, haveSuggestions[i].URL, wantSuggestions[i].URL)
}
if haveSuggestions[i].Title != wantSuggestions[i].Title {
return fmt.Errorf("Description \"%v\" has Title: \"%v\", want: \"%v\"", description, haveSuggestions[i].Title, wantSuggestions[i].Title)
}
}
return nil
}
func (s *scenario) bridgeSendsAConnectionUpEvent() error {
if event := s.t.events.await(events.ConnStatusUp{}, 30*time.Second); event == nil {
return errors.New("expected connection up event, got none")