Merge branch 'beta-library-service' into backup-page-flow

This commit is contained in:
Danny 2023-01-27 12:26:13 -05:00 committed by GitHub
commit 30ce9cafc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"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"
"github.com/alcionai/corso/src/pkg/account"
)
@ -78,3 +79,29 @@ func (suite *BetaClientSuite) TestBasicClientGetFunctionality() {
}
}
}
func (suite *BetaClientSuite) TestServiceRequirements() {
t := suite.T()
adpt, err := graph.CreateAdapter(
suite.credentials.AzureTenantID,
suite.credentials.AzureClientID,
suite.credentials.AzureClientSecret,
)
require.NoError(t, err)
service := NewService(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)
}

View File

@ -1,7 +1,9 @@
package betasdk
import (
absser "github.com/microsoft/kiota-abstractions-go/serialization"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
"github.com/pkg/errors"
)
// Service wraps BetaClient's functionality.
@ -18,3 +20,25 @@ func (s Service) Adapter() *msgraphsdk.GraphRequestAdapter {
func (s Service) Client() *BetaClient {
return s.client
}
func NewService(adpt *msgraphsdk.GraphRequestAdapter) *Service {
return &Service{
client: 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.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()
}