add contact generation to the factory script (#1202)
## Type of change - [x] 🤖 Test ## Issue(s) * #902 ## Test Plan - [x] 💪 Manual - [x] 💚 E2E
This commit is contained in:
parent
e3c16e1793
commit
f57b0f1f7e
@ -63,7 +63,7 @@ func handleExchangeEmailFactory(cmd *cobra.Command, args []string) error {
|
|||||||
func(id, now, subject, body string) []byte {
|
func(id, now, subject, body string) []byte {
|
||||||
return mockconnector.GetMockMessageWith(
|
return mockconnector.GetMockMessageWith(
|
||||||
user, user, user,
|
user, user, user,
|
||||||
subject, body,
|
subject, body, body,
|
||||||
now, now, now, now)
|
now, now, now, now)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -116,13 +116,45 @@ func handleExchangeCalendarEventFactory(cmd *cobra.Command, args []string) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleExchangeContactFactory(cmd *cobra.Command, args []string) error {
|
func handleExchangeContactFactory(cmd *cobra.Command, args []string) error {
|
||||||
Err(cmd.Context(), ErrNotYetImplemeted)
|
var (
|
||||||
|
ctx = cmd.Context()
|
||||||
|
service = path.ExchangeService
|
||||||
|
category = path.ContactsCategory
|
||||||
|
)
|
||||||
|
|
||||||
if utils.HasNoFlagsAndShownHelp(cmd) {
|
if utils.HasNoFlagsAndShownHelp(cmd) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate mocked contacts
|
gc, tenantID, err := getGCAndVerifyUser(ctx, user)
|
||||||
|
if err != nil {
|
||||||
|
return Only(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
deets, err := generateAndRestoreItems(
|
||||||
|
ctx,
|
||||||
|
gc,
|
||||||
|
service,
|
||||||
|
category,
|
||||||
|
selectors.NewExchangeRestore().Selector,
|
||||||
|
tenantID, user, destination,
|
||||||
|
count,
|
||||||
|
func(id, now, subject, body string) []byte {
|
||||||
|
given, mid, sur := id[:8], id[9:13], id[len(id)-12:]
|
||||||
|
|
||||||
|
return mockconnector.GetMockContactBytesWith(
|
||||||
|
given+" "+sur,
|
||||||
|
sur+", "+given,
|
||||||
|
given, mid, sur,
|
||||||
|
"123-456-7890",
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return Only(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
deets.PrintEntries(ctx)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@ -179,7 +180,13 @@ func getGCAndVerifyUser(ctx context.Context, userID string) (*connector.GraphCon
|
|||||||
return nil, "", errors.Wrap(err, "connecting to graph api")
|
return nil, "", errors.Wrap(err, "connecting to graph api")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := gc.Users[user]; !ok {
|
normUsers := map[string]struct{}{}
|
||||||
|
|
||||||
|
for k := range gc.Users {
|
||||||
|
normUsers[strings.ToLower(k)] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := normUsers[strings.ToLower(user)]; !ok {
|
||||||
return nil, "", errors.New("user not found within tenant")
|
return nil, "", errors.New("user not found within tenant")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -475,6 +475,7 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() {
|
|||||||
data: mockconnector.GetMockMessageWithBodyBytes(
|
data: mockconnector.GetMockMessageWithBodyBytes(
|
||||||
subjectText+"-1",
|
subjectText+"-1",
|
||||||
bodyText+" 1.",
|
bodyText+" 1.",
|
||||||
|
bodyText+" 1.",
|
||||||
),
|
),
|
||||||
lookupKey: subjectText + "-1",
|
lookupKey: subjectText + "-1",
|
||||||
},
|
},
|
||||||
@ -489,6 +490,7 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() {
|
|||||||
data: mockconnector.GetMockMessageWithBodyBytes(
|
data: mockconnector.GetMockMessageWithBodyBytes(
|
||||||
subjectText+"-2",
|
subjectText+"-2",
|
||||||
bodyText+" 2.",
|
bodyText+" 2.",
|
||||||
|
bodyText+" 2.",
|
||||||
),
|
),
|
||||||
lookupKey: subjectText + "-2",
|
lookupKey: subjectText + "-2",
|
||||||
},
|
},
|
||||||
@ -497,6 +499,7 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() {
|
|||||||
data: mockconnector.GetMockMessageWithBodyBytes(
|
data: mockconnector.GetMockMessageWithBodyBytes(
|
||||||
subjectText+"-3",
|
subjectText+"-3",
|
||||||
bodyText+" 3.",
|
bodyText+" 3.",
|
||||||
|
bodyText+" 3.",
|
||||||
),
|
),
|
||||||
lookupKey: subjectText + "-3",
|
lookupKey: subjectText + "-3",
|
||||||
},
|
},
|
||||||
|
|||||||
75
src/internal/connector/mockconnector/mock_data_contact.go
Normal file
75
src/internal/connector/mockconnector/mock_data_contact.go
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package mockconnector
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Order of fields to fill in:
|
||||||
|
// 1. displayName
|
||||||
|
// 2. fileAsName
|
||||||
|
// 3. phone
|
||||||
|
// 4. givenName
|
||||||
|
// 5. middleName
|
||||||
|
// 6. surname
|
||||||
|
//nolint:lll
|
||||||
|
contactTmpl = `{
|
||||||
|
"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":"%s",
|
||||||
|
"emailAddresses":[],
|
||||||
|
"fileAs":"%s",
|
||||||
|
"mobilePhone":"%s",
|
||||||
|
"givenName":"%s",
|
||||||
|
"homeAddress":{},
|
||||||
|
"homePhones":[],
|
||||||
|
"imAddresses":[],
|
||||||
|
"otherAddress":{},
|
||||||
|
"parentFolderId":"AAMkAGZmNjNlYjI3LWJlZWYtNGI4Mi04YjMyLTIxYThkNGQ4NmY1MwAuAAAAAADCNgjhM9FIYAAAAAAEOAAA=",
|
||||||
|
"personalNotes":"",
|
||||||
|
"middleName":"%s",
|
||||||
|
"surname":"%s"
|
||||||
|
}`
|
||||||
|
|
||||||
|
defaultContactDisplayName = "Santiago Quail"
|
||||||
|
defaultContactFileAsName = "Quail, Santiago"
|
||||||
|
defaultContactGivenName = "Santiago"
|
||||||
|
defaultContactSurname = "Quail"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetMockContactBytes returns bytes for Contactable item.
|
||||||
|
// When hydrated: contact.GetGivenName() shows differences
|
||||||
|
func GetMockContactBytes(middleName string) []byte {
|
||||||
|
phone := generatePhoneNumber()
|
||||||
|
|
||||||
|
return GetMockContactBytesWith(
|
||||||
|
defaultContactDisplayName,
|
||||||
|
defaultContactFileAsName,
|
||||||
|
defaultContactGivenName,
|
||||||
|
middleName,
|
||||||
|
defaultContactSurname,
|
||||||
|
phone,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMockContactBytesWith(
|
||||||
|
displayName, fileAsName,
|
||||||
|
givenName, middleName, surname,
|
||||||
|
phone string,
|
||||||
|
) []byte {
|
||||||
|
return []byte(fmt.Sprintf(
|
||||||
|
contactTmpl,
|
||||||
|
displayName,
|
||||||
|
fileAsName,
|
||||||
|
phone,
|
||||||
|
givenName,
|
||||||
|
middleName,
|
||||||
|
surname,
|
||||||
|
))
|
||||||
|
}
|
||||||
@ -17,6 +17,14 @@ const (
|
|||||||
defaultMessagePreview = "Lidia,\\n\\nWe have not received any reports on the development during Q2. It is in our best interest to have a new TPS Report by next Thursday prior to the retreat. If you have any questions, please let me know so I can address them.\\n" +
|
defaultMessagePreview = "Lidia,\\n\\nWe have not received any reports on the development during Q2. It is in our best interest to have a new TPS Report by next Thursday prior to the retreat. If you have any questions, please let me know so I can address them.\\n" +
|
||||||
"\\nThanking you in adv"
|
"\\nThanking you in adv"
|
||||||
|
|
||||||
|
defaultMessageCreatedTime = "2022-09-26T23:15:50Z"
|
||||||
|
defaultMessageModifiedTime = "2022-09-26T23:15:51Z"
|
||||||
|
defaultMessageReceivedTime = "2022-09-26T23:15:50Z"
|
||||||
|
defaultMessageSentTime = "2022-09-26T23:15:46Z"
|
||||||
|
defaultMessageSender = "foobar@8qzvrj.onmicrosoft.com"
|
||||||
|
defaultMessageTo = "LidiaH@8qzvrj.onmicrosoft.com"
|
||||||
|
defaultMessageFrom = "foobar@8qzvrj.onmicrosoft.com"
|
||||||
|
|
||||||
// Order of fields to fill in:
|
// Order of fields to fill in:
|
||||||
// 1. created datetime
|
// 1. created datetime
|
||||||
// 2. modified datetime
|
// 2. modified datetime
|
||||||
@ -90,50 +98,27 @@ const (
|
|||||||
// GetMockMessageBytes returns bytes for a Messageable item.
|
// GetMockMessageBytes returns bytes for a Messageable item.
|
||||||
// Contents verified as working with sample data from kiota-serialization-json-go v0.5.5
|
// Contents verified as working with sample data from kiota-serialization-json-go v0.5.5
|
||||||
func GetMockMessageBytes(subject string) []byte {
|
func GetMockMessageBytes(subject string) []byte {
|
||||||
userID := "foobar@8qzvrj.onmicrosoft.com"
|
return GetMockMessageWithBodyBytes(
|
||||||
timestamp := " " + common.FormatNow(common.SimpleDateTime)
|
"TPS Report "+subject+" "+common.FormatNow(common.SimpleDateTime),
|
||||||
|
defaultMessageBody, defaultMessagePreview)
|
||||||
message := fmt.Sprintf(
|
|
||||||
messageTmpl,
|
|
||||||
"2022-09-26T23:15:50Z", // created
|
|
||||||
"2022-09-26T23:15:51Z", // modified
|
|
||||||
defaultMessageBody,
|
|
||||||
defaultMessagePreview,
|
|
||||||
userID,
|
|
||||||
"2022-09-26T23:15:50Z",
|
|
||||||
"foobar@8qzvrj.onmicrosoft.com",
|
|
||||||
"2022-09-26T23:15:46Z",
|
|
||||||
"TPS Report "+subject+timestamp,
|
|
||||||
"LidiaH@8qzvrj.onmicrosoft.com")
|
|
||||||
|
|
||||||
return []byte(message)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMockMessageBytes returns bytes for a Messageable item.
|
// GetMockMessageBytes returns bytes for a Messageable item.
|
||||||
// Contents verified as working with sample data from kiota-serialization-json-go v0.5.5
|
// Contents verified as working with sample data from kiota-serialization-json-go v0.5.5
|
||||||
// Body must contain a well-formatted string, consumable in a json payload. IE: no unescaped newlines.
|
// Body must contain a well-formatted string, consumable in a json payload. IE: no unescaped newlines.
|
||||||
func GetMockMessageWithBodyBytes(subject, body string) []byte {
|
func GetMockMessageWithBodyBytes(subject, body, preview string) []byte {
|
||||||
userID := "foobar@8qzvrj.onmicrosoft.com"
|
return GetMockMessageWith(
|
||||||
preview := body
|
defaultMessageTo,
|
||||||
|
defaultMessageFrom,
|
||||||
if len(preview) > 255 {
|
defaultMessageSender,
|
||||||
preview = preview[:256]
|
subject,
|
||||||
}
|
|
||||||
|
|
||||||
message := fmt.Sprintf(
|
|
||||||
messageTmpl,
|
|
||||||
"2022-09-26T23:15:50Z", // created
|
|
||||||
"2022-09-26T23:15:51Z", // modified
|
|
||||||
body,
|
body,
|
||||||
preview,
|
preview,
|
||||||
userID,
|
defaultMessageCreatedTime,
|
||||||
"2022-09-26T23:15:50Z",
|
defaultMessageModifiedTime,
|
||||||
"foobar@8qzvrj.onmicrosoft.com",
|
defaultMessageSentTime,
|
||||||
"2022-09-26T23:15:46Z",
|
defaultMessageReceivedTime,
|
||||||
subject,
|
)
|
||||||
"LidiaH@8qzvrj.onmicrosoft.com")
|
|
||||||
|
|
||||||
return []byte(message)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMockMessageWith returns bytes for a Messageable item.
|
// GetMockMessageWith returns bytes for a Messageable item.
|
||||||
@ -142,10 +127,12 @@ func GetMockMessageWithBodyBytes(subject, body string) []byte {
|
|||||||
// Body must contain a well-formatted string, consumable in a json payload. IE: no unescaped newlines.
|
// Body must contain a well-formatted string, consumable in a json payload. IE: no unescaped newlines.
|
||||||
func GetMockMessageWith(
|
func GetMockMessageWith(
|
||||||
to, from, sender, // user PNs
|
to, from, sender, // user PNs
|
||||||
subject, body, // arbitrary data
|
subject, body, preview, // arbitrary data
|
||||||
created, modified, sent, received string, // legacy datetimes
|
created, modified, sent, received string, // legacy datetimes
|
||||||
) []byte {
|
) []byte {
|
||||||
preview := body
|
if len(preview) == 0 {
|
||||||
|
preview = body
|
||||||
|
}
|
||||||
|
|
||||||
if len(preview) > 255 {
|
if len(preview) > 255 {
|
||||||
preview = preview[:256]
|
preview = preview[:256]
|
||||||
@ -302,16 +289,3 @@ func GetMockMessageWithTwoAttachments(subject string) []byte {
|
|||||||
|
|
||||||
return []byte(message)
|
return []byte(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMockContactBytes returns bytes for Contactable item.
|
|
||||||
// When hydrated: contact.GetGivenName() shows differences
|
|
||||||
func GetMockContactBytes(middleName string) []byte {
|
|
||||||
phone := generatePhoneNumber()
|
|
||||||
//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\",\"mobilePhone\": \"" + phone + "\"," +
|
|
||||||
"\"givenName\":\"Santiago\",\"homeAddress\":{},\"homePhones\":[],\"imAddresses\":[],\"otherAddress\":{},\"parentFolderId\":\"AAMkAGZmNjNlYjI3LWJlZWYtNGI4Mi04YjMyLTIxYThkNGQ4NmY1MwAuAAAAAADCNgjhM9FIYAAAAAAEOAAA=\",\"personalNotes\":\"\",\"middleName\":\"" + middleName + "\",\"surname\":\"Quail\"}"
|
|
||||||
|
|
||||||
return []byte(contact)
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user