Issue 1020 (#1021)
## Description CI tests are showing a consistent panic when adding attendees to events with zero content. ## Type of change - [x] 🐛 Bugfix ## Issue(s) * #1020 ## Test Plan - [x] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
03bb63f52d
commit
7fa86824e9
@ -424,12 +424,16 @@ func ToEventSimplified(orig models.Eventable) models.Eventable {
|
||||
return orig
|
||||
}
|
||||
|
||||
type getContenter interface {
|
||||
GetContent() *string
|
||||
GetContentType() *models.BodyType
|
||||
}
|
||||
|
||||
// insertStringToBody helper function to insert text into models.bodyable
|
||||
// @returns string containing the content string of altered body.
|
||||
func insertStringToBody(body models.ItemBodyable, newContent string) string {
|
||||
var prefix, suffix string
|
||||
|
||||
func insertStringToBody(body getContenter, newContent string) string {
|
||||
if body.GetContent() == nil ||
|
||||
len(*body.GetContent()) == 0 ||
|
||||
body.GetContentType() == nil {
|
||||
return ""
|
||||
}
|
||||
@ -439,14 +443,28 @@ func insertStringToBody(body models.ItemBodyable, newContent string) string {
|
||||
switch *body.GetContentType() {
|
||||
case models.TEXT_BODYTYPE:
|
||||
return newContent + content
|
||||
|
||||
case models.HTML_BODYTYPE:
|
||||
array := strings.Split(content, "<body>")
|
||||
prefix = array[0] + "<body>"
|
||||
interior := array[1]
|
||||
bodyArray := strings.Split(interior, ">")
|
||||
prefix += bodyArray[0] + ">"
|
||||
suffix = strings.Join(bodyArray[1:], ">")
|
||||
arr := strings.Split(content, "<body>")
|
||||
if len(arr) < 2 {
|
||||
// malformed html; can't be sure where to insert attendees.
|
||||
return newContent + content
|
||||
}
|
||||
|
||||
prefix := arr[0] + "<body>"
|
||||
interior := arr[1]
|
||||
splitOnCloseAngle := strings.Split(interior, ">")
|
||||
|
||||
if len(splitOnCloseAngle) < 3 {
|
||||
// no inner elements in body, just insert the new content
|
||||
return prefix + newContent + strings.Join(arr[1:], "")
|
||||
}
|
||||
|
||||
prefix += splitOnCloseAngle[0] + ">"
|
||||
suffix := strings.Join(splitOnCloseAngle[1:], ">")
|
||||
|
||||
return prefix + newContent + suffix
|
||||
}
|
||||
|
||||
return newContent + content
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package support
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
@ -50,3 +51,97 @@ func (suite *SupportTestSuite) TestToEventSimplified() {
|
||||
assert.Contains(t, *event.GetBody().GetContent(), *member.GetEmailAddress().GetAddress())
|
||||
}
|
||||
}
|
||||
|
||||
type mockContenter struct {
|
||||
content *string
|
||||
contentType *models.BodyType
|
||||
}
|
||||
|
||||
func (mc mockContenter) GetContent() *string {
|
||||
return mc.content
|
||||
}
|
||||
|
||||
func (mc mockContenter) GetContentType() *models.BodyType {
|
||||
return mc.contentType
|
||||
}
|
||||
|
||||
func makeMockContent(c string, ct models.BodyType) mockContenter {
|
||||
return mockContenter{&c, &ct}
|
||||
}
|
||||
|
||||
func (suite *SupportTestSuite) TestInsertStringToBody() {
|
||||
nilTextContent := makeMockContent("", models.TEXT_BODYTYPE)
|
||||
nilTextContent.content = nil
|
||||
nilHTMLContent := makeMockContent("", models.HTML_BODYTYPE)
|
||||
nilHTMLContent.content = nil
|
||||
nilContentType := makeMockContent("brawnhilda", models.TEXT_BODYTYPE)
|
||||
nilContentType.contentType = nil
|
||||
|
||||
table := []struct {
|
||||
name string
|
||||
input mockContenter
|
||||
content string
|
||||
expect string
|
||||
}{
|
||||
{
|
||||
name: "nil text content",
|
||||
input: nilTextContent,
|
||||
content: "nil",
|
||||
expect: "",
|
||||
},
|
||||
{
|
||||
name: "nil html content",
|
||||
input: nilHTMLContent,
|
||||
content: "nil",
|
||||
expect: "",
|
||||
},
|
||||
{
|
||||
name: "nil content type",
|
||||
input: nilContentType,
|
||||
content: "nil",
|
||||
expect: "",
|
||||
},
|
||||
{
|
||||
name: "text",
|
||||
input: makeMockContent("_text", models.TEXT_BODYTYPE),
|
||||
content: "new",
|
||||
expect: "new_text",
|
||||
},
|
||||
{
|
||||
name: "empty text",
|
||||
input: makeMockContent("", models.TEXT_BODYTYPE),
|
||||
content: "new",
|
||||
expect: "",
|
||||
},
|
||||
{
|
||||
name: "expected html",
|
||||
input: makeMockContent("_<body><div>_text</div></body>_", models.HTML_BODYTYPE),
|
||||
content: "foo",
|
||||
expect: "_<body><div>foo_text</div></body>_",
|
||||
},
|
||||
{
|
||||
name: "no div html",
|
||||
input: makeMockContent("_<body>_text</body>_", models.HTML_BODYTYPE),
|
||||
content: "bar",
|
||||
expect: "_<body>bar_text</body>_",
|
||||
},
|
||||
{
|
||||
name: "no body html",
|
||||
input: makeMockContent("_text", models.HTML_BODYTYPE),
|
||||
content: "baz",
|
||||
expect: "baz_text",
|
||||
},
|
||||
{
|
||||
name: "empty html",
|
||||
input: makeMockContent("", models.HTML_BODYTYPE),
|
||||
content: "fnords",
|
||||
expect: "",
|
||||
},
|
||||
}
|
||||
for _, test := range table {
|
||||
suite.T().Run(test.name, func(t *testing.T) {
|
||||
result := insertStringToBody(test.input, test.content)
|
||||
assert.Equal(t, test.expect, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,7 +257,6 @@ func (op *RestoreOperation) persistResults(
|
||||
ctx,
|
||||
events.RestoreEnd,
|
||||
map[string]any{
|
||||
// TODO: RestoreID
|
||||
events.BackupID: op.BackupID,
|
||||
events.DataRetrieved: op.Results.BytesRead,
|
||||
events.Duration: op.Results.CompletedAt.Sub(op.Results.StartedAt),
|
||||
@ -269,7 +268,6 @@ func (op *RestoreOperation) persistResults(
|
||||
events.Service: op.Selectors.Service.String(),
|
||||
events.StartTime: op.Results.StartedAt,
|
||||
events.Status: op.Status,
|
||||
// TODO: events.ExchangeDataObserved: <amount of data retrieved>,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user