ContactInfo added to exchange package (#574)

ContactInfo created for models.Contactable. ContactInfo test suite created.
This commit is contained in:
Danny 2022-08-17 09:47:27 -04:00 committed by GitHub
parent 41f22ad9a4
commit ad2c17876f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 3 deletions

View File

@ -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,
}
}

View File

@ -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))
})
}
}

View File

@ -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