diff --git a/src/internal/connector/graph_connector.go b/src/internal/connector/graph_connector.go index 855a095957..8378aca031 100644 --- a/src/internal/connector/graph_connector.go +++ b/src/internal/connector/graph_connector.go @@ -98,6 +98,21 @@ func (gc *GraphConnector) createService() (*graphService, error) { return &connector, err } +// createMailFolder will create a mail folder iff a folder of the same name does not exit +func createMailFolder(gc graphService, user, folder string) (models.MailFolderable, error) { + requestBody := models.NewMailFolder() + requestBody.SetDisplayName(&folder) + isHidden := false + requestBody.SetIsHidden(&isHidden) + + return gc.client.UsersById(user).MailFolders().Post(requestBody) +} + +// deleteMailFolder removes mail folder from the user's M365 Exchange account +func deleteMailFolder(gc graphService, user, folderID string) error { + return gc.client.UsersById(user).MailFoldersById(folderID).Delete() +} + // setTenantUsers queries the M365 to identify the users in the // workspace. The users field is updated during this method // iff the return value is true diff --git a/src/internal/connector/graph_connector_test.go b/src/internal/connector/graph_connector_test.go index 70472f0bec..3df2f7080c 100644 --- a/src/internal/connector/graph_connector_test.go +++ b/src/internal/connector/graph_connector_test.go @@ -91,8 +91,20 @@ func (suite *GraphConnectorIntegrationSuite) TestGraphConnector_restoreMessages( assert.NoError(suite.T(), err) } -// --------------------------------------------------------------------------- +func (suite *GraphConnectorIntegrationSuite) TestGraphConnector_createDeleteFolder() { + user := "lidiah@8qzvrj.onmicrosoft.com" + folderName := "createdForTest" + aFolder, err := createMailFolder(suite.connector.graphService, user, folderName) + assert.NoError(suite.T(), err, support.ConnectorStackErrorTrace(err)) + if aFolder != nil { + err = deleteMailFolder(suite.connector.graphService, user, *aFolder.GetId()) + assert.NoError(suite.T(), err) + } +} +// --------------------------------------------------------------- +// Disconnected Test Section +// ------------------------- type DisconnectedGraphConnectorSuite struct { suite.Suite }