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:
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [x] 🐹 Trivial/Minor

## Issue(s)
<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->

#671 

## Test Plan

<!-- How will this be tested prior to merging.-->

- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2022-09-02 09:52:00 -07:00 committed by GitHub
parent af9dfe6654
commit 21c2e4af14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 35 deletions

View File

@ -176,11 +176,11 @@ func (pb Builder) withPrefix(elements ...string) *Builder {
return res 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 // 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 // elements of the path such as the tenant ID, user ID, service, and service
// category. // 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 { if err := pb.verifyPrefix(tenant, user); err != nil {
return nil, err return nil, err
} }
@ -194,28 +194,7 @@ func (pb Builder) ToDataLayerExchangeMailFolder(tenant, user string) (Path, erro
), ),
service: ExchangeService, service: ExchangeService,
category: EmailCategory, category: EmailCategory,
}, nil hasItem: isItem,
}
// 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,
}, nil }, nil
} }

View File

@ -49,7 +49,7 @@ var (
modes = []struct { modes = []struct {
name string name string
builderFunc func(b path.Builder, tenant, user string) (path.Path, error) isItem bool
expectedFolder string expectedFolder string
expectedItem string expectedItem string
expectedService path.ServiceType expectedService path.ServiceType
@ -57,7 +57,7 @@ var (
}{ }{
{ {
name: "ExchangeMailFolder", name: "ExchangeMailFolder",
builderFunc: path.Builder.ToDataLayerExchangeMailFolder, isItem: false,
expectedFolder: strings.Join(rest, "/"), expectedFolder: strings.Join(rest, "/"),
expectedItem: "", expectedItem: "",
expectedService: path.ExchangeService, expectedService: path.ExchangeService,
@ -65,7 +65,7 @@ var (
}, },
{ {
name: "ExchangeMailItem", name: "ExchangeMailItem",
builderFunc: path.Builder.ToDataLayerExchangeMailItem, isItem: true,
expectedFolder: strings.Join(rest[0:len(rest)-1], "/"), expectedFolder: strings.Join(rest[0:len(rest)-1], "/"),
expectedItem: rest[len(rest)-1], expectedItem: rest[len(rest)-1],
expectedService: path.ExchangeService, expectedService: path.ExchangeService,
@ -89,7 +89,7 @@ func (suite *DataLayerResourcePath) TestMissingInfoErrors() {
tOuter.Run(test.name, func(t *testing.T) { tOuter.Run(test.name, func(t *testing.T) {
b := path.Builder{}.Append(test.rest...) 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) assert.Error(t, err)
}) })
} }
@ -102,7 +102,7 @@ func (suite *DataLayerResourcePath) TestMailItemNoFolder() {
item := "item" item := "item"
b := path.Builder{}.Append(item) b := path.Builder{}.Append(item)
p, err := b.ToDataLayerExchangeMailItem(testTenant, testUser) p, err := b.ToDataLayerExchangeMailPath(testTenant, testUser, true)
require.NoError(t, err) require.NoError(t, err)
assert.Empty(t, p.Folder()) assert.Empty(t, p.Folder())
@ -125,7 +125,7 @@ func (suite *PopulatedDataLayerResourcePath) SetupSuite() {
func (suite *PopulatedDataLayerResourcePath) TestTenant() { func (suite *PopulatedDataLayerResourcePath) TestTenant() {
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t *testing.T) { 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) require.NoError(t, err)
assert.Equal(t, testTenant, p.Tenant()) assert.Equal(t, testTenant, p.Tenant())
@ -136,7 +136,7 @@ func (suite *PopulatedDataLayerResourcePath) TestTenant() {
func (suite *PopulatedDataLayerResourcePath) TestService() { func (suite *PopulatedDataLayerResourcePath) TestService() {
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t *testing.T) { 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) require.NoError(t, err)
assert.Equal(t, m.expectedService, p.Service()) assert.Equal(t, m.expectedService, p.Service())
@ -147,7 +147,7 @@ func (suite *PopulatedDataLayerResourcePath) TestService() {
func (suite *PopulatedDataLayerResourcePath) TestCategory() { func (suite *PopulatedDataLayerResourcePath) TestCategory() {
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t *testing.T) { 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) require.NoError(t, err)
assert.Equal(t, m.expectedCategory, p.Category()) assert.Equal(t, m.expectedCategory, p.Category())
@ -158,7 +158,7 @@ func (suite *PopulatedDataLayerResourcePath) TestCategory() {
func (suite *PopulatedDataLayerResourcePath) TestResourceOwner() { func (suite *PopulatedDataLayerResourcePath) TestResourceOwner() {
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t *testing.T) { 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) require.NoError(t, err)
assert.Equal(t, testUser, p.ResourceOwner()) assert.Equal(t, testUser, p.ResourceOwner())
@ -169,7 +169,7 @@ func (suite *PopulatedDataLayerResourcePath) TestResourceOwner() {
func (suite *PopulatedDataLayerResourcePath) TestFolder() { func (suite *PopulatedDataLayerResourcePath) TestFolder() {
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t *testing.T) { 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) require.NoError(t, err)
assert.Equal(t, m.expectedFolder, p.Folder()) assert.Equal(t, m.expectedFolder, p.Folder())
@ -180,7 +180,7 @@ func (suite *PopulatedDataLayerResourcePath) TestFolder() {
func (suite *PopulatedDataLayerResourcePath) TestItem() { func (suite *PopulatedDataLayerResourcePath) TestItem() {
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t *testing.T) { 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) require.NoError(t, err)
assert.Equal(t, m.expectedItem, p.Item()) assert.Equal(t, m.expectedItem, p.Item())