551 mockdata contacts (#553)
Creation of mock data for Contact M365 objects. CreateContactFromBytes function added to support package
This commit is contained in:
parent
be7b778769
commit
2f7d8420ae
@ -102,3 +102,11 @@ func GetMockMessageBytes(subject string) []byte {
|
||||
|
||||
return []byte(message)
|
||||
}
|
||||
|
||||
func GetMockContactBytes(middleName string) []byte {
|
||||
//nolint:lll
|
||||
contact := "{\"id\":\"AAMkAGZmNjNlYjI3LWJlZWYtNGI4Mi04YjMyLTIxYThkNGQ4NmY1MwBGAAAAAADCNgjhM9QmQYWNcI7hCpPrBwDSEBNbUIB9RL6ePDeF3FIYAAAAAAEOAADSEBNbUIB9RL6ePDeF3FIYAABS7DZnAAA=\",\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users('foobar%408qzvrj.onmicrosoft.com')/contacts/$entity\",\"@odata.etag\":\"W/\\\"EQAAABYAAADSEBNbUIB9RL6ePDeF3FIYAABSx4Tr\\\"\",\"categories\":[],\"changeKey\":\"EQAAABYAAADSEBNbUIB9RL6ePDeF3FIYAABSx4Tr\",\"createdDateTime\":\"2019-08-04T06:55:33Z\",\"lastModifiedDateTime\":\"2019-08-04T06:55:33Z\",\"businessAddress\":{},\"businessPhones\":[],\"children\":[],\"displayName\":\"Santiago Quail\",\"emailAddresses\":[],\"fileAs\":\"Quail, Santiago\"," +
|
||||
//nolint:lll
|
||||
"\"givenName\":\"Santiago " + middleName + "\",\"homeAddress\":{},\"homePhones\":[],\"imAddresses\":[],\"otherAddress\":{},\"parentFolderId\":\"AAMkAGZmNjNlYjI3LWJlZWYtNGI4Mi04YjMyLTIxYThkNGQ4NmY1MwAuAAAAAADCNgjhM9FIYAAAAAAEOAAA=\",\"personalNotes\":\"\",\"surname\":\"Quail\"}"
|
||||
return []byte(contact)
|
||||
}
|
||||
|
||||
@ -30,3 +30,14 @@ func CreateMessageFromBytes(bytes []byte) (models.Messageable, error) {
|
||||
message := aMessage.(models.Messageable)
|
||||
return message, nil
|
||||
}
|
||||
|
||||
// CreateContactFromBytes function to transform bytes into Contactable object
|
||||
// Error returned if ParsableFactory function does not accept given bytes
|
||||
func CreateContactFromBytes(bytes []byte) (models.Contactable, error) {
|
||||
parsable, err := CreateFromBytes(bytes, models.CreateContactFromDiscriminatorValue)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
contact := parsable.(models.Contactable)
|
||||
return contact, nil
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
package support
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/alcionai/corso/internal/connector/mockconnector"
|
||||
"github.com/alcionai/corso/internal/tester"
|
||||
)
|
||||
|
||||
@ -22,12 +22,9 @@ func TestDataSupportSuite(t *testing.T) {
|
||||
suite.Run(t, new(DataSupportSuite))
|
||||
}
|
||||
|
||||
// TestCreateMessageFromBytes verifies approved mockdata bytes can
|
||||
// be successfully transformed into M365 Message data.
|
||||
func (suite *DataSupportSuite) TestCreateMessageFromBytes() {
|
||||
bytes, err := tester.LoadAFile(os.Getenv(tester.CorsoGraphConnectorTestSupportFile))
|
||||
if err != nil {
|
||||
suite.T().Errorf("Failed with %v\n", err)
|
||||
}
|
||||
|
||||
table := []struct {
|
||||
name string
|
||||
byteArray []byte
|
||||
@ -42,14 +39,53 @@ func (suite *DataSupportSuite) TestCreateMessageFromBytes() {
|
||||
},
|
||||
{
|
||||
name: "aMessage bytes",
|
||||
byteArray: bytes,
|
||||
byteArray: mockconnector.GetMockMessageBytes("m365 mail support test"),
|
||||
checkError: assert.NoError,
|
||||
checkObject: assert.NotNil,
|
||||
},
|
||||
}
|
||||
for _, test := range table {
|
||||
result, err := CreateMessageFromBytes(test.byteArray)
|
||||
test.checkError(suite.T(), err)
|
||||
test.checkObject(suite.T(), result)
|
||||
suite.T().Run(test.name, func(t *testing.T) {
|
||||
result, err := CreateMessageFromBytes(test.byteArray)
|
||||
test.checkError(t, err)
|
||||
test.checkObject(t, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestCreateContactFromBytes verifies behavior of CreateContactFromBytes
|
||||
// by ensuring correct error and object output.
|
||||
func (suite *DataSupportSuite) TestCreateContactFromBytes() {
|
||||
table := []struct {
|
||||
name string
|
||||
byteArray []byte
|
||||
checkError assert.ErrorAssertionFunc
|
||||
isNil assert.ValueAssertionFunc
|
||||
}{
|
||||
{
|
||||
name: "Empty Bytes",
|
||||
byteArray: make([]byte, 0),
|
||||
checkError: assert.Error,
|
||||
isNil: assert.Nil,
|
||||
},
|
||||
{
|
||||
name: "Invalid Bytes",
|
||||
byteArray: []byte("A random sentence doesn't make an object"),
|
||||
checkError: assert.Error,
|
||||
isNil: assert.Nil,
|
||||
},
|
||||
{
|
||||
name: "Valid Contact",
|
||||
byteArray: mockconnector.GetMockContactBytes("Support Test"),
|
||||
checkError: assert.NoError,
|
||||
isNil: assert.NotNil,
|
||||
},
|
||||
}
|
||||
for _, test := range table {
|
||||
suite.T().Run(test.name, func(t *testing.T) {
|
||||
result, err := CreateContactFromBytes(test.byteArray)
|
||||
test.checkError(t, err)
|
||||
test.isNil(t, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user