Sharepoint Feature: details.Sharepoint implementation (#1454)
## Description Creates Sharepoint Info within the details package. SharepointInfo constructor and test package included <!-- Insert PR description--> ## Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🌻 Feature ## Test Plan - [x] ⚡ Unit test
This commit is contained in:
parent
5089f9d949
commit
70d9c2ed15
42
src/internal/connector/sharepoint/listInfo.go
Normal file
42
src/internal/connector/sharepoint/listInfo.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package sharepoint
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||||
|
|
||||||
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
|
)
|
||||||
|
|
||||||
|
// sharepointListInfo translates models.Listable metadata into searchable content
|
||||||
|
// List Details: https://learn.microsoft.com/en-us/graph/api/resources/list?view=graph-rest-1.0
|
||||||
|
func sharepointListInfo(lst models.Listable) *details.SharepointInfo {
|
||||||
|
var (
|
||||||
|
name, webURL string
|
||||||
|
created, modified time.Time
|
||||||
|
)
|
||||||
|
|
||||||
|
if lst.GetDisplayName() != nil {
|
||||||
|
name = *lst.GetDisplayName()
|
||||||
|
}
|
||||||
|
|
||||||
|
if lst.GetWebUrl() != nil {
|
||||||
|
webURL = *lst.GetWebUrl()
|
||||||
|
}
|
||||||
|
|
||||||
|
if lst.GetCreatedDateTime() != nil {
|
||||||
|
created = *lst.GetCreatedDateTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
if lst.GetLastModifiedDateTime() != nil {
|
||||||
|
modified = *lst.GetLastModifiedDateTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
return &details.SharepointInfo{
|
||||||
|
ItemType: details.SharepointItem,
|
||||||
|
ItemName: name,
|
||||||
|
Created: created,
|
||||||
|
Modified: modified,
|
||||||
|
WebURL: webURL,
|
||||||
|
}
|
||||||
|
}
|
||||||
55
src/internal/connector/sharepoint/listInfo_test.go
Normal file
55
src/internal/connector/sharepoint/listInfo_test.go
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package sharepoint
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SharePointInfoSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSharePointInfoSuite(t *testing.T) {
|
||||||
|
suite.Run(t, new(SharePointInfoSuite))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *SharePointInfoSuite) TestSharePointInfo() {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
listAndRP func() (models.Listable, *details.SharepointInfo)
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Empty List",
|
||||||
|
listAndRP: func() (models.Listable, *details.SharepointInfo) {
|
||||||
|
i := &details.SharepointInfo{ItemType: details.SharepointItem}
|
||||||
|
return models.NewList(), i
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
name: "Only Name",
|
||||||
|
listAndRP: func() (models.Listable, *details.SharepointInfo) {
|
||||||
|
aTitle := "Whole List"
|
||||||
|
listing := models.NewList()
|
||||||
|
listing.SetDisplayName(&aTitle)
|
||||||
|
i := &details.SharepointInfo{
|
||||||
|
ItemType: details.SharepointItem,
|
||||||
|
ItemName: aTitle,
|
||||||
|
}
|
||||||
|
return listing, i
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
|
list, expected := test.listAndRP()
|
||||||
|
info := sharepointListInfo(list)
|
||||||
|
assert.Equal(t, expected.ItemType, info.ItemType)
|
||||||
|
assert.Equal(t, expected.ItemName, info.ItemName)
|
||||||
|
assert.Equal(t, expected.WebURL, info.WebURL)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -345,10 +345,12 @@ func (i ExchangeInfo) Values() []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SharepointInfo describes a sharepoint item
|
// SharepointInfo describes a sharepoint item
|
||||||
// TODO: Implement this. This is currently here
|
|
||||||
// just to illustrate usage
|
|
||||||
type SharepointInfo struct {
|
type SharepointInfo struct {
|
||||||
ItemType ItemType `json:"itemType,omitempty"`
|
ItemType ItemType `json:"itemType,omitempty"`
|
||||||
|
ItemName string `json:"itemName,omitempty"`
|
||||||
|
Created time.Time `json:"created,omitempty"`
|
||||||
|
Modified time.Time `josn:"modified,omitempty"`
|
||||||
|
WebURL string `json:"webUrl,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Headers returns the human-readable names of properties in a SharepointInfo
|
// Headers returns the human-readable names of properties in a SharepointInfo
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user