Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Issue #359: create folder enhancement added.
Browse files Browse the repository at this point in the history
  • Loading branch information
dadams39 committed Jul 20, 2022
1 parent 1a31a07 commit cb29592
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/internal/connector/graph_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion src/internal/connector/graph_connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,20 @@ func (suite *GraphConnectorIntegrationSuite) TestGraphConnector_restoreMessages(
assert.NoError(suite.T(), err)
}

// ---------------------------------------------------------------------------
func (suite *GraphConnectorIntegrationSuite) TestGraphConnector_createDeleteFolder() {
user := "[email protected]"
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
}
Expand Down

0 comments on commit cb29592

Please sign in to comment.