From 21c2e4af145723c1f7c822e2971d766d8b1d740a Mon Sep 17 00:00:00 2001 From: ashmrtn <3891298+ashmrtn@users.noreply.github.com> Date: Fri, 2 Sep 2022 09:52:00 -0700 Subject: [PATCH] Make exchange mail path ctor a bit easier to use (#735) ## Description Turn into single constructor with bool instead of separate item and folder constructors. ## Type of change Please check the type of change your PR introduces: - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [x] :hamster: Trivial/Minor ## Issue(s) #671 ## Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/path/path.go | 27 +++---------------------- src/internal/path/resource_path_test.go | 22 ++++++++++---------- 2 files changed, 14 insertions(+), 35 deletions(-) diff --git a/src/internal/path/path.go b/src/internal/path/path.go index 297a22347..276d84ed3 100644 --- a/src/internal/path/path.go +++ b/src/internal/path/path.go @@ -176,11 +176,11 @@ func (pb Builder) withPrefix(elements ...string) *Builder { return res } -// ToDataLayerExchangeMailFolder returns a Path for an Exchange mail folder +// ToDataLayerExchangeMailFolder returns a Path for an Exchange mail folder or item // resource with information useful to the data layer. This includes prefix // elements of the path such as the tenant ID, user ID, service, and service // category. -func (pb Builder) ToDataLayerExchangeMailFolder(tenant, user string) (Path, error) { +func (pb Builder) ToDataLayerExchangeMailPath(tenant, user string, isItem bool) (Path, error) { if err := pb.verifyPrefix(tenant, user); err != nil { return nil, err } @@ -194,28 +194,7 @@ func (pb Builder) ToDataLayerExchangeMailFolder(tenant, user string) (Path, erro ), service: ExchangeService, category: EmailCategory, - }, nil -} - -// ToDataLayerExchangeMailFolder returns a Path for an Exchange mail item -// resource with information useful to the data layer. This includes prefix -// elements of the path such as the tenant ID, user ID, service, and service -// category. -func (pb Builder) ToDataLayerExchangeMailItem(tenant, user string) (Path, error) { - if err := pb.verifyPrefix(tenant, user); err != nil { - return nil, err - } - - return &dataLayerResourcePath{ - Builder: *pb.withPrefix( - tenant, - ExchangeService.String(), - user, - EmailCategory.String(), - ), - service: ExchangeService, - category: EmailCategory, - hasItem: true, + hasItem: isItem, }, nil } diff --git a/src/internal/path/resource_path_test.go b/src/internal/path/resource_path_test.go index 8e735df95..a77e5745c 100644 --- a/src/internal/path/resource_path_test.go +++ b/src/internal/path/resource_path_test.go @@ -49,7 +49,7 @@ var ( modes = []struct { name string - builderFunc func(b path.Builder, tenant, user string) (path.Path, error) + isItem bool expectedFolder string expectedItem string expectedService path.ServiceType @@ -57,7 +57,7 @@ var ( }{ { name: "ExchangeMailFolder", - builderFunc: path.Builder.ToDataLayerExchangeMailFolder, + isItem: false, expectedFolder: strings.Join(rest, "/"), expectedItem: "", expectedService: path.ExchangeService, @@ -65,7 +65,7 @@ var ( }, { name: "ExchangeMailItem", - builderFunc: path.Builder.ToDataLayerExchangeMailItem, + isItem: true, expectedFolder: strings.Join(rest[0:len(rest)-1], "/"), expectedItem: rest[len(rest)-1], expectedService: path.ExchangeService, @@ -89,7 +89,7 @@ func (suite *DataLayerResourcePath) TestMissingInfoErrors() { tOuter.Run(test.name, func(t *testing.T) { b := path.Builder{}.Append(test.rest...) - _, err := m.builderFunc(*b, test.tenant, test.user) + _, err := b.ToDataLayerExchangeMailPath(test.tenant, test.user, m.isItem) assert.Error(t, err) }) } @@ -102,7 +102,7 @@ func (suite *DataLayerResourcePath) TestMailItemNoFolder() { item := "item" b := path.Builder{}.Append(item) - p, err := b.ToDataLayerExchangeMailItem(testTenant, testUser) + p, err := b.ToDataLayerExchangeMailPath(testTenant, testUser, true) require.NoError(t, err) assert.Empty(t, p.Folder()) @@ -125,7 +125,7 @@ func (suite *PopulatedDataLayerResourcePath) SetupSuite() { func (suite *PopulatedDataLayerResourcePath) TestTenant() { for _, m := range modes { suite.T().Run(m.name, func(t *testing.T) { - p, err := m.builderFunc(*suite.b, testTenant, testUser) + p, err := suite.b.ToDataLayerExchangeMailPath(testTenant, testUser, m.isItem) require.NoError(t, err) assert.Equal(t, testTenant, p.Tenant()) @@ -136,7 +136,7 @@ func (suite *PopulatedDataLayerResourcePath) TestTenant() { func (suite *PopulatedDataLayerResourcePath) TestService() { for _, m := range modes { suite.T().Run(m.name, func(t *testing.T) { - p, err := m.builderFunc(*suite.b, testTenant, testUser) + p, err := suite.b.ToDataLayerExchangeMailPath(testTenant, testUser, m.isItem) require.NoError(t, err) assert.Equal(t, m.expectedService, p.Service()) @@ -147,7 +147,7 @@ func (suite *PopulatedDataLayerResourcePath) TestService() { func (suite *PopulatedDataLayerResourcePath) TestCategory() { for _, m := range modes { suite.T().Run(m.name, func(t *testing.T) { - p, err := m.builderFunc(*suite.b, testTenant, testUser) + p, err := suite.b.ToDataLayerExchangeMailPath(testTenant, testUser, m.isItem) require.NoError(t, err) assert.Equal(t, m.expectedCategory, p.Category()) @@ -158,7 +158,7 @@ func (suite *PopulatedDataLayerResourcePath) TestCategory() { func (suite *PopulatedDataLayerResourcePath) TestResourceOwner() { for _, m := range modes { suite.T().Run(m.name, func(t *testing.T) { - p, err := m.builderFunc(*suite.b, testTenant, testUser) + p, err := suite.b.ToDataLayerExchangeMailPath(testTenant, testUser, m.isItem) require.NoError(t, err) assert.Equal(t, testUser, p.ResourceOwner()) @@ -169,7 +169,7 @@ func (suite *PopulatedDataLayerResourcePath) TestResourceOwner() { func (suite *PopulatedDataLayerResourcePath) TestFolder() { for _, m := range modes { suite.T().Run(m.name, func(t *testing.T) { - p, err := m.builderFunc(*suite.b, testTenant, testUser) + p, err := suite.b.ToDataLayerExchangeMailPath(testTenant, testUser, m.isItem) require.NoError(t, err) assert.Equal(t, m.expectedFolder, p.Folder()) @@ -180,7 +180,7 @@ func (suite *PopulatedDataLayerResourcePath) TestFolder() { func (suite *PopulatedDataLayerResourcePath) TestItem() { for _, m := range modes { suite.T().Run(m.name, func(t *testing.T) { - p, err := m.builderFunc(*suite.b, testTenant, testUser) + p, err := suite.b.ToDataLayerExchangeMailPath(testTenant, testUser, m.isItem) require.NoError(t, err) assert.Equal(t, m.expectedItem, p.Item())