From ad2c17876fa2f4195c4ef7fbaa287fd48c6aa8ee Mon Sep 17 00:00:00 2001 From: Danny Date: Wed, 17 Aug 2022 09:47:27 -0400 Subject: [PATCH] ContactInfo added to exchange package (#574) ContactInfo created for models.Contactable. ContactInfo test suite created. --- src/internal/connector/exchange/contact.go | 20 ++++++++ .../connector/exchange/contact_test.go | 46 +++++++++++++++++++ src/pkg/backup/details/details.go | 7 +-- 3 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 src/internal/connector/exchange/contact.go create mode 100644 src/internal/connector/exchange/contact_test.go diff --git a/src/internal/connector/exchange/contact.go b/src/internal/connector/exchange/contact.go new file mode 100644 index 000000000..c51cda98f --- /dev/null +++ b/src/internal/connector/exchange/contact.go @@ -0,0 +1,20 @@ +package exchange + +import ( + "github.com/microsoftgraph/msgraph-sdk-go/models" + + "github.com/alcionai/corso/pkg/backup/details" +) + +// ContactInfo translate models.Contactable metadata into searchable content +func ContactInfo(contact models.Contactable) *details.ExchangeInfo { + name := "" + + if contact.GetDisplayName() != nil { + name = *contact.GetDisplayName() + } + + return &details.ExchangeInfo{ + ContactName: name, + } +} diff --git a/src/internal/connector/exchange/contact_test.go b/src/internal/connector/exchange/contact_test.go new file mode 100644 index 000000000..468229419 --- /dev/null +++ b/src/internal/connector/exchange/contact_test.go @@ -0,0 +1,46 @@ +package exchange + +import ( + "testing" + + "github.com/microsoftgraph/msgraph-sdk-go/models" + "github.com/stretchr/testify/suite" + + "github.com/alcionai/corso/pkg/backup/details" +) + +type ContactSuite struct { + suite.Suite +} + +func TestContactSuite(t *testing.T) { + suite.Run(t, &ContactSuite{}) +} + +func (suite *ContactSuite) TestContactInfo() { + tests := []struct { + name string + contactAndRP func() (models.Contactable, *details.ExchangeInfo) + }{ + { + name: "Empty Contact", + contactAndRP: func() (models.Contactable, *details.ExchangeInfo) { + return models.NewContact(), &details.ExchangeInfo{} + }, + }, { + name: "Only Name", + contactAndRP: func() (models.Contactable, *details.ExchangeInfo) { + aPerson := "Whole Person" + contact := models.NewContact() + contact.SetDisplayName(&aPerson) + return contact, &details.ExchangeInfo{ContactName: aPerson} + }, + }, + } + for _, test := range tests { + suite.T().Run(test.name, func(t *testing.T) { + contact, expected := test.contactAndRP() + suite.Equal(expected, ContactInfo(contact)) + }) + } +} diff --git a/src/pkg/backup/details/details.go b/src/pkg/backup/details/details.go index c43341dff..00eabe1dc 100644 --- a/src/pkg/backup/details/details.go +++ b/src/pkg/backup/details/details.go @@ -81,9 +81,10 @@ type ItemInfo struct { // ExchangeInfo describes an exchange item type ExchangeInfo struct { - Sender string `json:"sender"` - Subject string `json:"subject"` - Received time.Time `json:"received"` + Sender string `json:"sender,omitempty"` + Subject string `json:"subject,omitempty"` + Received time.Time `json:"received,omitempty"` + ContactName string `json:"contactName,omitempty"` } // Headers returns the human-readable names of properties in an ExchangeInfo