GODT-1205: "RCPT TO" does not contain all addressed from "CC"

This commit is contained in:
Alexander Bilyak
2021-09-06 21:13:37 +00:00
committed by Jakub Cuth
parent 91dcb2f773
commit 22d2bcc21d
11 changed files with 236 additions and 91 deletions

View File

@ -37,6 +37,7 @@ func APIChecksFeatureContext(s *godog.Suite) {
s.Step(`^API endpoint "([^"]*)" is not called$`, apiIsNotCalled)
s.Step(`^API endpoint "([^"]*)" is not called with$`, apiIsNotCalledWith)
s.Step(`^message is sent with API call$`, messageIsSentWithAPICall)
s.Step(`^packages are sent with API call$`, packagesAreSentWithAPICall)
s.Step(`^API mailbox "([^"]*)" for "([^"]*)" has (\d+) message(?:s)?$`, apiMailboxForUserHasNumberOfMessages)
s.Step(`^API mailbox "([^"]*)" for address "([^"]*)" of "([^"]*)" has (\d+) message(?:s)?$`, apiMailboxForAddressOfUserHasNumberOfMessages)
s.Step(`^API mailbox "([^"]*)" for "([^"]*)" has messages$`, apiMailboxForUserHasMessages)
@ -58,6 +59,17 @@ func apiIsCalledWith(endpoint string, data *gherkin.DocString) error {
return nil
}
func apiIsCalledWithRegex(endpoint string, data *gherkin.DocString) error {
match, err := apiIsCalledWithHelperRegex(endpoint, data.Content)
if err != nil {
return err
}
if !match {
return fmt.Errorf("%s was not called with %s", endpoint, data.Content)
}
return nil
}
func apiIsNotCalled(endpoint string) error {
if apiIsCalledWithHelper(endpoint, "") {
return fmt.Errorf("%s was called", endpoint)
@ -80,6 +92,14 @@ func apiIsCalledWithHelper(endpoint string, content string) bool {
return ctx.GetPMAPIController().WasCalled(method, path, request)
}
func apiIsCalledWithHelperRegex(endpoint string, content string) (bool, error) {
split := strings.Split(endpoint, " ")
method := split[0]
path := split[1]
request := []byte(content)
return ctx.GetPMAPIController().WasCalledRegex(method, path, request)
}
func messageIsSentWithAPICall(data *gherkin.DocString) error {
endpoint := "POST /mail/v4/messages"
if err := apiIsCalledWith(endpoint, data); err != nil {
@ -94,6 +114,20 @@ func messageIsSentWithAPICall(data *gherkin.DocString) error {
return nil
}
func packagesAreSentWithAPICall(data *gherkin.DocString) error {
endpoint := "POST /mail/v4/messages/.+$"
if err := apiIsCalledWithRegex(endpoint, data); err != nil {
return err
}
for _, request := range ctx.GetPMAPIController().GetCalls("POST", "/mail/v4/messages") {
if !checkAllRequiredFieldsForSendingMessage(request) {
return fmt.Errorf("%s was not called with all required fields: %s", endpoint, request)
}
}
return nil
}
func checkAllRequiredFieldsForSendingMessage(request []byte) bool {
if matches := regexp.MustCompile(`"Subject":`).Match(request); !matches {
return false