Exchange service functions (#454)
`exchange`.service_actions.go created. Create/Delete Mail folder functions inherited. Test suite updated accordingly.
This commit is contained in:
parent
2f56a849c9
commit
bd559f690e
24
src/internal/connector/exchange/service_functions.go
Normal file
24
src/internal/connector/exchange/service_functions.go
Normal file
@ -0,0 +1,24 @@
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
|
||||
"github.com/alcionai/corso/internal/connector/graph"
|
||||
)
|
||||
|
||||
// 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(gs graph.Service, user, folder string) (models.MailFolderable, error) {
|
||||
requestBody := models.NewMailFolder()
|
||||
requestBody.SetDisplayName(&folder)
|
||||
isHidden := false
|
||||
requestBody.SetIsHidden(&isHidden)
|
||||
|
||||
return gs.Client().UsersById(user).MailFolders().Post(requestBody)
|
||||
}
|
||||
|
||||
// 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(gs graph.Service, user, folderID string) error {
|
||||
return gs.Client().UsersById(user).MailFoldersById(folderID).Delete()
|
||||
}
|
||||
@ -104,21 +104,6 @@ func (gs *graphService) EnableFailFast() {
|
||||
gs.failFast = true
|
||||
}
|
||||
|
||||
// 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 the 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
|
||||
|
||||
@ -4,12 +4,14 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/alcionai/corso/internal/common"
|
||||
"github.com/alcionai/corso/internal/connector/exchange"
|
||||
"github.com/alcionai/corso/internal/connector/mockconnector"
|
||||
"github.com/alcionai/corso/internal/connector/support"
|
||||
"github.com/alcionai/corso/internal/data"
|
||||
@ -93,13 +95,14 @@ func (suite *GraphConnectorIntegrationSuite) TestGraphConnector_restoreMessages(
|
||||
assert.NoError(suite.T(), err)
|
||||
}
|
||||
|
||||
func (suite *GraphConnectorIntegrationSuite) TestGraphConnector_createDeleteFolder() {
|
||||
func (suite *GraphConnectorIntegrationSuite) TestGraphConnector_CreateAndDeleteFolder() {
|
||||
user := "lidiah@8qzvrj.onmicrosoft.com"
|
||||
folderName := uuid.NewString() // todo - replace with danny's fix #391
|
||||
aFolder, err := createMailFolder(suite.connector.graphService, user, folderName)
|
||||
now := time.Now()
|
||||
folderName := "TestFolder: " + common.FormatSimpleDateTime(now)
|
||||
aFolder, err := exchange.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())
|
||||
err = exchange.DeleteMailFolder(&suite.connector.graphService, user, *aFolder.GetId())
|
||||
assert.NoError(suite.T(), err)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user