diff --git a/src/internal/connector/exchange/service_functions.go b/src/internal/connector/exchange/service_functions.go index 5d8a60332..1b3f945c8 100644 --- a/src/internal/connector/exchange/service_functions.go +++ b/src/internal/connector/exchange/service_functions.go @@ -68,15 +68,31 @@ func createService(credentials account.M365Config, shouldFailFast bool) (*exchan // CreateMailFolder makes a mail folder iff a folder of the same name does not exist // Reference: https://docs.microsoft.com/en-us/graph/api/user-post-mailfolders?view=graph-rest-1.0&tabs=http func CreateMailFolder(ctx context.Context, gs graph.Service, user, folder string) (models.MailFolderable, error) { + isHidden := false requestBody := models.NewMailFolder() requestBody.SetDisplayName(&folder) - - isHidden := false requestBody.SetIsHidden(&isHidden) return gs.Client().UsersById(user).MailFolders().Post(ctx, requestBody, nil) } +func CreateMailFolderWithParent( + ctx context.Context, + gs graph.Service, + user, folder, parentID string, +) (models.MailFolderable, error) { + isHidden := false + requestBody := models.NewMailFolder() + requestBody.SetDisplayName(&folder) + requestBody.SetIsHidden(&isHidden) + + return gs.Client(). + UsersById(user). + MailFoldersById(parentID). + ChildFolders(). + Post(ctx, requestBody, nil) +} + // DeleteMailFolder removes a mail folder with the corresponding M365 ID from the user's M365 Exchange account // Reference: https://docs.microsoft.com/en-us/graph/api/mailfolder-delete?view=graph-rest-1.0&tabs=http func DeleteMailFolder(ctx context.Context, gs graph.Service, user, folderID string) error { diff --git a/src/internal/connector/graph_connector_test.go b/src/internal/connector/graph_connector_test.go index 4a7c6acac..fd3cf8625 100644 --- a/src/internal/connector/graph_connector_test.go +++ b/src/internal/connector/graph_connector_test.go @@ -309,17 +309,28 @@ func (suite *GraphConnectorIntegrationSuite) TestAccessOfInboxAllUsers() { // to create and remove folders within the tenant func (suite *GraphConnectorIntegrationSuite) TestCreateAndDeleteMailFolder() { ctx := context.Background() + t := suite.T() now := time.Now() folderName := "TestFolder: " + common.FormatSimpleDateTime(now) aFolder, err := exchange.CreateMailFolder(ctx, suite.connector.Service(), suite.user, folderName) - assert.NoError(suite.T(), err, support.ConnectorStackErrorTrace(err)) + assert.NoError(t, err, support.ConnectorStackErrorTrace(err)) if aFolder != nil { + secondFolder, err := exchange.CreateMailFolderWithParent( + ctx, + suite.connector.Service(), + suite.user, + "SubFolder", + *aFolder.GetId(), + ) + assert.NoError(t, err) + assert.True(t, *secondFolder.GetParentFolderId() == *aFolder.GetId()) + err = exchange.DeleteMailFolder(ctx, suite.connector.Service(), suite.user, *aFolder.GetId()) - assert.NoError(suite.T(), err) + assert.NoError(t, err) if err != nil { - suite.T().Log(support.ConnectorStackErrorTrace(err)) + t.Log(support.ConnectorStackErrorTrace(err)) } } }