This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GC: Add Service to
graph/betasdk
package (#2298)
## Description Creates Beta Service for betasdk package. Abstraction loosely complies with the methods found in `graph.Servicer()`. Will aid when Sharepoint functionality is supported in v1.0 and `betasdk` package is removed. <!-- Insert PR description--> ## Does this PR need a docs update or release note? - [x] ⛔ No ## 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. --> - related to * #2174<issue> ## Test Plan <!-- How will this be tested prior to merging.--> - [x] 💪 Manual
- Loading branch information
Danny
authored
Jan 31, 2023
1 parent
c270536
commit 013eeab
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/alcionai/corso/src/internal/connector/graph/betasdk" | ||
absser "github.com/microsoft/kiota-abstractions-go/serialization" | ||
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// Service wraps BetaClient's functionality. | ||
// Abstraction created to comply loosely with graph.Servicer | ||
// methods for ease of switching between v1.0 and beta connnectors | ||
type Service struct { | ||
client *betasdk.BetaClient | ||
} | ||
|
||
func (s Service) Client() *betasdk.BetaClient { | ||
return s.client | ||
} | ||
|
||
func NewBetaService(adpt *msgraphsdk.GraphRequestAdapter) *Service { | ||
return &Service{ | ||
client: betasdk.NewBetaClient(adpt), | ||
} | ||
} | ||
|
||
// Seraialize writes an M365 parsable object into a byte array using the built-in | ||
// application/json writer within the adapter. | ||
func (s Service) Serialize(object absser.Parsable) ([]byte, error) { | ||
writer, err := s.client.Adapter(). | ||
GetSerializationWriterFactory(). | ||
GetSerializationWriter("application/json") | ||
if err != nil || writer == nil { | ||
return nil, errors.Wrap(err, "creating json serialization writer") | ||
} | ||
|
||
err = writer.WriteObjectValue("", object) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "writeObjecValue serialization") | ||
} | ||
|
||
return writer.GetSerializedContent() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package api | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/alcionai/corso/src/internal/connector/graph" | ||
"github.com/alcionai/corso/src/internal/connector/graph/betasdk/models" | ||
"github.com/alcionai/corso/src/internal/tester" | ||
) | ||
|
||
type BetaUnitSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func TestBetaUnitSuite(t *testing.T) { | ||
suite.Run(t, new(BetaUnitSuite)) | ||
} | ||
|
||
func (suite *BetaUnitSuite) TestBetaService_Adapter() { | ||
t := suite.T() | ||
a := tester.NewM365Account(t) | ||
m365, err := a.M365Config() | ||
require.NoError(t, err) | ||
|
||
adpt, err := graph.CreateAdapter( | ||
m365.AzureTenantID, | ||
m365.AzureClientID, | ||
m365.AzureClientSecret, | ||
) | ||
require.NoError(t, err) | ||
|
||
service := NewBetaService(adpt) | ||
require.NotNil(t, service) | ||
|
||
testPage := models.NewSitePage() | ||
name := "testFile" | ||
desc := "working with parsing" | ||
|
||
testPage.SetName(&name) | ||
testPage.SetDescription(&desc) | ||
|
||
byteArray, err := service.Serialize(testPage) | ||
assert.NotEmpty(t, byteArray) | ||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters