-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provision to post and delete lists or list items #4853
Conversation
Current Aviator status
This PR was merged manually (without Aviator). Merging manually can negatively impact the performance of the queue. Consider using Aviator next time. See the real-time status of this PR on the Aviator webapp. Use the Aviator Chrome Extension to see the status of your PR within GitHub.
|
|
||
func (suite *ListsUnitSuite) TestLegacyColumnsAreNotSet() { | ||
listName := "test-list" | ||
contentTypeColumnName := "ContentType" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: turn these values into constants. Use those consts as both the keys in your list structure maps, as well as here in the tests.
src/pkg/services/m365/api/lists.go
Outdated
|
||
oldList, err := BytesToListable(oldListByteArray) | ||
if err != nil { | ||
return nil, clues.WrapWC(ctx, err, "creating old list") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, clues.WrapWC(ctx, err, "creating old list") | |
return nil, clues.WrapWC(ctx, err, "generating list from stored bytes") |
if name, ok := ptr.ValOK(oldList.GetDisplayName()); ok { | ||
nameParts := strings.Split(listName, "_") | ||
if len(nameParts) > 0 { | ||
nameParts[len(nameParts)-1] = name | ||
newListName = strings.Join(nameParts, "_") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This behavior is opaque. Can you please add a comment explaining what's being handled here, and why that handling is necessary? Comments like that will help all future maintainers grok the implementation.
// this ensure all columns, contentTypes are set to the newList | ||
newList := ToListable(oldList, newListName) | ||
|
||
// Restore to List base to M365 back store |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Restore to List base to M365 back store |
src/pkg/services/m365/api/lists.go
Outdated
newList := ToListable(oldList, newListName) | ||
|
||
// Restore to List base to M365 back store | ||
restoredList, err := c.Stable.Client().Sites().BySiteId(siteID).Lists().Post(ctx, newList, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: prefer multiline on func chains for code readability.
restoredList, err := c.Stable.Client().Sites().BySiteId(siteID).Lists().Post(ctx, newList, nil) | |
restoredList, err := c.Stable. | |
Client(). | |
Sites(). | |
BySiteId(siteID). | |
Lists(). | |
Post(ctx, newList, nil) |
src/pkg/services/m365/api/lists.go
Outdated
strings.HasPrefix(key, "@") || | ||
isReadOnlyField || | ||
strings.Contains(key, "LinkTitle") || | ||
strings.Contains(key, "ChildCount") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hardcoded strings should get const values, please. This applies to all cases in this PR, not only this line.
src/pkg/services/m365/api/lists.go
Outdated
@@ -11,6 +11,40 @@ import ( | |||
"github.com/alcionai/corso/src/pkg/services/m365/api/graph" | |||
) | |||
|
|||
var legacyColumns = map[string]struct{}{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your impulse to centralize these values. It's good for code readability and cleanliness. Looking at the usage of these maps, however, I think there's a couple extra protections that would be nice. In general, this suggestion comes from how using global maps can produce a smell, since alterations to those maps at runtime can be difficult to detect and debug.
For the most part, it seems like you're using the maps purely as a check for whether a key exists in a certain set. For those uses, I'd suggest getter funcs like hasKey(string) bool
.
In one other case, you're actually looking for a slice of the keys, and are hacking the map to do the same. In that case I'd suggest a func like keys() []string
.
Putting it together, you can easily get both cases with a type wrapper, like so:
type keySet map[string]struct {}
func (ks keySet) hasKey(k string) bool {...}
func (ks keySet) keys() []string {...}
var legacyColumns = keySet{...}
That makes it safe and easy for implementations to do the same check you're currently doing by instead calling if legacyColumns.hasKey(k) {...}
tests := []struct { | ||
name string | ||
getOrig func() models.ColumnDefinitionable | ||
checkNil bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can pack the assert call into the property itself here.
checkNil bool | |
expect assert.ValueAssertionFunc |
This lets you change the test value to:
expect: assert.Nil // or assert.NotNil
and verify the result like so
newCd := cloneColumnDefinitionable(orig)
require.NotEmpty(t, newCd)
test.expect(t, newCd.GetValidation())
@@ -68,6 +69,389 @@ func (suite *ListsUnitSuite) TestBytesToListable() { | |||
} | |||
} | |||
|
|||
func (suite *ListsUnitSuite) TestColumnDefinitionValidationSetWhenProvided() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For test naming, code standard is to follow golang's testable example naming schemes. see: https://go.dev/blog/examples#example-function-names
In short, it goes something like TestStructName_FuncName_subtestExplanation
.
so in this case you're testing:
func (suite *ListsUnitSuite) TestColumnDefinitionValidationSetWhenProvided() { | |
func (suite *ListsUnitSuite) TestColumnDefinitionable_GetValidation() { |
|
||
textColumn := models.NewTextColumn() | ||
|
||
txtColumnDef := models.NewColumnDefinition() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot of chaff code. Is there any way to centralize it, or parts of it, for ease of re-use across multipl tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good! Thank you for the updates.
src/internal/common/maps/keyset.go
Outdated
@@ -0,0 +1,21 @@ | |||
package maps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as a warning, this may collide with the golang maps
package, which we use elsewhere. I don't know a better name off the top of my head. Maybe keys
? Then you can change the value from keys.KeySet
to just Set, for keys.Set
?
suite.Run(t, &KeySetTestSuite{Suite: tester.NewUnitSuite(t)}) | ||
} | ||
|
||
func (suite *KeySetTestSuite) Test_HasKey() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: no underscore needed when naming the function under test directly. Underscores are for methods, variables, and extensions. eg:
func TestStruct()
func TestStruct_Method()
func TestFunc()
func TestStruct_hasSpecificProperty()
func TestStruct_Method_doesSomethingSpecific()
func TestFunc_doesSomethingSpecific()
func (suite *KeySetTestSuite) Test_HasKey() { | |
func (suite *KeySetTestSuite) TestHasKey() { |
adds lists restore handler to: - create list - create list items - delete list #### 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) #4754 #### Test Plan <!-- How will this be tested prior to merging.--> - [x] 💪 Manual - [x] ⚡ Unit test - [x] 💚 E2E
Quality Gate passedThe SonarCloud Quality Gate passed, but some issues were introduced. 1 New issue |
Does this PR need a docs update or release note?
Type of change
Issue(s)
#4754
Test Plan