GC: Restore: Mail: Create Subfolder Feature (#1055)
## Description The feature allows for the subFolders to be created. Test Suite Expanded. <!-- Insert PR description--> ## Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🌻 Feature ## Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> *Closes Issue #1054<issue> ## Test Plan - [x] ⚡ Unit test
This commit is contained in:
parent
f4556288a5
commit
7843787cd3
@ -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 {
|
||||
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user