pass location to attachment only if value present

This commit is contained in:
neha-Gupta1 2023-06-01 14:12:37 +05:30
parent 8d68bacfb7
commit eb3b9a88c8
3 changed files with 49 additions and 41 deletions

View File

@ -227,36 +227,38 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
return ptr.Val(folder.GetId())
},
},
{
name: "Test Mail: Hydrated Item Attachment Mail",
bytes: exchMock.MessageWithNestedItemAttachmentMail(t,
exchMock.MessageBytes("Basic Item Attachment"),
"Mail Item Attachment",
),
category: path.EmailCategory,
destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreDestination("mailbasicattch").ContainerName
folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName)
require.NoError(t, err, clues.ToCore(err))
return ptr.Val(folder.GetId())
},
},
{
name: "Test Mail: Hydrated Item Attachment Mail One Attach",
bytes: exchMock.MessageWithNestedItemAttachmentMail(t,
exchMock.MessageWithDirectAttachment("Item Attachment Included"),
"Mail Item Attachment",
),
category: path.EmailCategory,
destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreDestination("mailnestattch").ContainerName
folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName)
require.NoError(t, err, clues.ToCore(err))
//TODO: Neha complete as part of https://github.com/alcionai/corso/issues/2428
// {
// name: "Test Mail: Hydrated Item Attachment Mail",
// bytes: exchMock.MessageWithNestedItemAttachmentMail(t,
// exchMock.MessageBytes("Basic Item Attachment"),
// "Mail Item Attachment",
// ),
// category: path.EmailCategory,
// destination: func(t *testing.T, ctx context.Context) string {
// folderName := tester.DefaultTestRestoreDestination("mailbasicattch").ContainerName
// folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName)
// require.NoError(t, err, clues.ToCore(err))
return ptr.Val(folder.GetId())
},
},
// return ptr.Val(folder.GetId())
// },
// },
// {
// name: "Test Mail: Hydrated Item Attachment Mail One Attach",
// bytes: exchMock.MessageWithNestedItemAttachmentMail(t,
// exchMock.MessageWithDirectAttachment("Item Attachment Included"),
// "Mail Item Attachment",
// ),
// category: path.EmailCategory,
// destination: func(t *testing.T, ctx context.Context) string {
// folderName := tester.DefaultTestRestoreDestination("mailnestattch").ContainerName
// folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName)
// require.NoError(t, err, clues.ToCore(err))
// return ptr.Val(folder.GetId())
// },
// },
{
name: "Test Mail: Item Attachment_Contact",
bytes: exchMock.MessageWithNestedItemAttachmentContact(t,

View File

@ -228,18 +228,6 @@ func RestoreMessage(
ptr.Val(item.GetId()),
a)
if err != nil {
// FIXME: I don't know why we're swallowing this error case.
// It needs investigation: https://github.com/alcionai/corso/issues/3498
if ptr.Val(a.GetOdataType()) == "#microsoft.graph.itemAttachment" {
name := ptr.Val(a.GetName())
logger.CtxErr(ctx, err).
With("attachment_name", name).
Info("mail upload failed")
continue
}
el.AddRecoverable(clues.Wrap(err, "uploading mail attachment"))
}
}

View File

@ -2,6 +2,7 @@ package exchange
import (
"fmt"
"reflect"
"strings"
"github.com/alcionai/clues"
@ -264,7 +265,11 @@ func sanitizeEvent(orig models.Eventable) (models.Eventable, error) {
newEvent.SetImportance(orig.GetImportance())
newEvent.SetIsAllDay(orig.GetIsAllDay())
newEvent.SetIsOnlineMeeting(orig.GetIsOnlineMeeting())
newEvent.SetLocation(orig.GetLocation())
if !isNil(orig.GetLocation()) {
newEvent.SetLocation(orig.GetLocation())
}
newEvent.SetLocations(orig.GetLocations())
newEvent.SetSensitivity(orig.GetSensitivity())
newEvent.SetReminderMinutesBeforeStart(orig.GetReminderMinutesBeforeStart())
@ -292,6 +297,19 @@ func sanitizeEvent(orig models.Eventable) (models.Eventable, error) {
return newEvent, nil
}
func isNil(i interface{}) bool {
if i == nil {
return true
}
switch reflect.TypeOf(i).Kind() {
case reflect.Ptr, reflect.Map, reflect.Array, reflect.Chan, reflect.Slice:
return reflect.ValueOf(i).IsNil()
}
return false
}
func sanitizeMessage(orig models.Messageable) (models.Messageable, error) {
message := toMessage(orig)