From 70d9c2ed153c7e533b91512004637a7b90ae6910 Mon Sep 17 00:00:00 2001 From: Danny Date: Mon, 7 Nov 2022 08:46:31 -0500 Subject: [PATCH] Sharepoint Feature: details.Sharepoint implementation (#1454) ## Description Creates Sharepoint Info within the details package. SharepointInfo constructor and test package included ## Type of change - [x] :sunflower: Feature ## Test Plan - [x] :zap: Unit test --- src/internal/connector/sharepoint/listInfo.go | 42 ++++++++++++++ .../connector/sharepoint/listInfo_test.go | 55 +++++++++++++++++++ src/pkg/backup/details/details.go | 8 ++- 3 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 src/internal/connector/sharepoint/listInfo.go create mode 100644 src/internal/connector/sharepoint/listInfo_test.go diff --git a/src/internal/connector/sharepoint/listInfo.go b/src/internal/connector/sharepoint/listInfo.go new file mode 100644 index 000000000..984b8a7c3 --- /dev/null +++ b/src/internal/connector/sharepoint/listInfo.go @@ -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, + } +} diff --git a/src/internal/connector/sharepoint/listInfo_test.go b/src/internal/connector/sharepoint/listInfo_test.go new file mode 100644 index 000000000..1ffbd1bb9 --- /dev/null +++ b/src/internal/connector/sharepoint/listInfo_test.go @@ -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) + }) + } +} diff --git a/src/pkg/backup/details/details.go b/src/pkg/backup/details/details.go index bc3e96a83..965dbc5f3 100644 --- a/src/pkg/backup/details/details.go +++ b/src/pkg/backup/details/details.go @@ -345,10 +345,12 @@ func (i ExchangeInfo) Values() []string { } // SharepointInfo describes a sharepoint item -// TODO: Implement this. This is currently here -// just to illustrate usage 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