Troubleshooting.
This commit is contained in:
parent
88e494987a
commit
55d2d6c9ad
@ -38,6 +38,16 @@ func (mau *mailAttachmentUploader) getItemID() string {
|
||||
}
|
||||
|
||||
func (mau *mailAttachmentUploader) uploadSmallAttachment(ctx context.Context, attach models.Attachmentable) error {
|
||||
wtr := js.NewJsonSerializationWriter()
|
||||
err := wtr.WriteObjectValue(attach)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
byteArray, err := wtr.GetSerializedContent()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := mau.service.Client().
|
||||
UsersById(mau.userID).
|
||||
MailFoldersById(mau.folderID).
|
||||
|
||||
110
src/internal/connector/exchange/attachment_uploadable_test.go
Normal file
110
src/internal/connector/exchange/attachment_uploadable_test.go
Normal file
@ -0,0 +1,110 @@
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/alcionai/corso/src/internal/common"
|
||||
"github.com/alcionai/corso/src/internal/connector/exchange/api"
|
||||
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||
"github.com/alcionai/corso/src/internal/connector/mockconnector"
|
||||
"github.com/alcionai/corso/src/internal/connector/support"
|
||||
"github.com/alcionai/corso/src/internal/tester"
|
||||
"github.com/alcionai/corso/src/pkg/account"
|
||||
"github.com/alcionai/corso/src/pkg/control"
|
||||
"github.com/alcionai/corso/src/pkg/path"
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
type ExchangeRestoreAttachmentSuite struct {
|
||||
suite.Suite
|
||||
gs graph.Servicer
|
||||
credentials account.M365Config
|
||||
ac api.Client
|
||||
}
|
||||
|
||||
func TestExchangeRestoreAttachmentSuite(t *testing.T) {
|
||||
tester.RunOnAny(
|
||||
t,
|
||||
tester.CorsoCITests,
|
||||
tester.CorsoConnectorRestoreExchangeCollectionTests,
|
||||
)
|
||||
|
||||
suite.Run(t, new(ExchangeRestoreAttachmentSuite))
|
||||
}
|
||||
|
||||
func (suite *ExchangeRestoreAttachmentSuite) SetupSuite() {
|
||||
t := suite.T()
|
||||
tester.MustGetEnvSets(t, tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
|
||||
|
||||
a := tester.NewM365Account(t)
|
||||
m365, err := a.M365Config()
|
||||
require.NoError(t, err)
|
||||
|
||||
suite.credentials = m365
|
||||
suite.ac, err = api.NewClient(m365)
|
||||
require.NoError(t, err)
|
||||
|
||||
adpt, err := graph.CreateAdapter(m365.AzureTenantID, m365.AzureClientID, m365.AzureClientSecret)
|
||||
require.NoError(t, err)
|
||||
|
||||
suite.gs = graph.NewService(adpt)
|
||||
|
||||
require.NoError(suite.T(), err)
|
||||
}
|
||||
|
||||
// TestAttachmentUploads verifies that various attachnments can be uploaded
|
||||
// to certain base objects.
|
||||
func (suite *ExchangeRestoreAttachmentSuite) TestAttachmentUploadsMail() {
|
||||
ctx, flush := tester.NewContext()
|
||||
defer flush()
|
||||
|
||||
// base message --> outlookable ??
|
||||
// attachment -->
|
||||
t := suite.T()
|
||||
//userID := tester.M365UserID(suite.T())
|
||||
|
||||
userID := "dustina@8qzvrj.onmicrosoft.com"
|
||||
service, err := createService(suite.ac.Credentials)
|
||||
require.NoError(t, err)
|
||||
|
||||
now := time.Now()
|
||||
folderName := "TestRestoreMailwithLargeAttachment: " + common.FormatSimpleDateTime(now)
|
||||
folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName)
|
||||
require.NoError(t, err)
|
||||
|
||||
folderID := *folder.GetId()
|
||||
byteArray := mockconnector.GetMockMessageBytes("Base Message")
|
||||
|
||||
deets, err := RestoreExchangeObject(ctx, byteArray, path.EmailCategory, control.Copy, service, folderID, userID)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, deets)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
getAttachment func(t *testing.T) models.Attachmentable
|
||||
}{
|
||||
{
|
||||
name: "Reference Attachment",
|
||||
getAttachment: func(t *testing.T) models.Attachmentable {
|
||||
byteArray := mockconnector.GetMockAttachmentReference()
|
||||
|
||||
attach, err := support.CreateAttachmentFromBytes(byteArray)
|
||||
require.NoError(t, err)
|
||||
|
||||
return attach
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Log("Test compiled fine")
|
||||
})
|
||||
}
|
||||
// attach to upload
|
||||
|
||||
}
|
||||
@ -71,3 +71,14 @@ func CreateListFromBytes(bytes []byte) (models.Listable, error) {
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func CreateAttachmentFromBytes(bytes []byte) (models.Attachmentable, error) {
|
||||
parsable, err := CreateFromBytes(bytes, models.CreateAttachmentFromDiscriminatorValue)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "creating m365 attachment object from provided bytes")
|
||||
}
|
||||
|
||||
attach := parsable.(models.Attachmentable)
|
||||
|
||||
return attach, nil
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package support
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
js "github.com/microsoft/kiota-serialization-json-go"
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -32,6 +34,19 @@ func (suite *SupportTestSuite) TestToMessage() {
|
||||
suite.NotEqual(message.GetId(), clone.GetId())
|
||||
}
|
||||
|
||||
func (suite *SupportTestSuite) TestToM() {
|
||||
bytes := mockconnector.GetMockMessageBytes("m365 mail support test")
|
||||
message, err := CreateMessageFromBytes(bytes)
|
||||
require.NoError(suite.T(), err)
|
||||
|
||||
clone := ToMessage(message)
|
||||
suite.Equal(message.GetBccRecipients(), clone.GetBccRecipients())
|
||||
suite.Equal(message.GetSubject(), clone.GetSubject())
|
||||
suite.Equal(message.GetSender(), clone.GetSender())
|
||||
suite.Equal(message.GetSentDateTime(), clone.GetSentDateTime())
|
||||
suite.NotEqual(message.GetId(), clone.GetId())
|
||||
}
|
||||
|
||||
func (suite *SupportTestSuite) TestToEventSimplified() {
|
||||
t := suite.T()
|
||||
bytes := mockconnector.GetMockEventWithAttendeesBytes("M365 Event Support Test")
|
||||
@ -40,6 +55,13 @@ func (suite *SupportTestSuite) TestToEventSimplified() {
|
||||
|
||||
attendees := event.GetAttendees()
|
||||
newEvent := ToEventSimplified(event)
|
||||
newEvent.SetIsOrganizer(nil)
|
||||
wtr := js.NewJsonSerializationWriter()
|
||||
err = wtr.WriteObjectValue("", newEvent)
|
||||
require.NoError(t, err)
|
||||
byteArray, err := wtr.GetSerializedContent()
|
||||
require.NoError(t, err)
|
||||
fmt.Printf("newEvent %+v\n", string(byteArray))
|
||||
|
||||
assert.Empty(t, newEvent.GetHideAttendees())
|
||||
assert.Equal(t, *event.GetBody().GetContentType(), *newEvent.GetBody().GetContentType())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user