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
This commit is contained in:
parent
c270536f73
commit
013eeab7cb
43
src/internal/connector/discovery/api/beta_service.go
Normal file
43
src/internal/connector/discovery/api/beta_service.go
Normal file
@ -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()
|
||||||
|
}
|
||||||
49
src/internal/connector/discovery/api/beta_service_test.go
Normal file
49
src/internal/connector/discovery/api/beta_service_test.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
@ -84,3 +84,8 @@ func (m *BetaClient) SitesById(id string) *i1a3c1a5501c5e41b7fd169f2d4c768dce9b0
|
|||||||
}
|
}
|
||||||
return i1a3c1a5501c5e41b7fd169f2d4c768dce9b096ac28fb5431bf02afcc57295411.NewSiteItemRequestBuilderInternal(urlTplParams, m.requestAdapter)
|
return i1a3c1a5501c5e41b7fd169f2d4c768dce9b096ac28fb5431bf02afcc57295411.NewSiteItemRequestBuilderInternal(urlTplParams, m.requestAdapter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adapter() helper method to export Adapter for iterating
|
||||||
|
func (m *BetaClient) Adapter() *msgraphsdk.GraphRequestAdapter {
|
||||||
|
return m.requestAdapter
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user