Update state builder to fix root change
This commit is contained in:
parent
3f17e594ec
commit
831ac5150a
@ -48,7 +48,7 @@ func (s *stateBuilder) Build(tr objecttree.ObjectTree, oldState *State) (state *
|
|||||||
|
|
||||||
func (s *stateBuilder) processChange(change *objecttree.Change, rootId string, state *State) *State {
|
func (s *stateBuilder) processChange(change *objecttree.Change, rootId string, state *State) *State {
|
||||||
// ignoring root change which has empty model or startId change
|
// ignoring root change which has empty model or startId change
|
||||||
if change.Model == nil || state.LastIteratedId == change.Id {
|
if len(change.PreviousIds) == 0 || state.LastIteratedId == change.Id {
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -42,6 +42,7 @@ func TestStateBuilder_ProcessChange(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("changeId is equal to rootId", func(t *testing.T) {
|
t.Run("changeId is equal to rootId", func(t *testing.T) {
|
||||||
ch := &objecttree.Change{}
|
ch := &objecttree.Change{}
|
||||||
|
ch.PreviousIds = []string{"someId"}
|
||||||
ch.Model = &spacesyncproto.SettingsData{
|
ch.Model = &spacesyncproto.SettingsData{
|
||||||
Snapshot: &spacesyncproto.SpaceSettingsSnapshot{
|
Snapshot: &spacesyncproto.SpaceSettingsSnapshot{
|
||||||
DeletedIds: []string{"id1", "id2"},
|
DeletedIds: []string{"id1", "id2"},
|
||||||
@ -56,6 +57,7 @@ func TestStateBuilder_ProcessChange(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("changeId is not equal to lastIteratedId or rootId", func(t *testing.T) {
|
t.Run("changeId is not equal to lastIteratedId or rootId", func(t *testing.T) {
|
||||||
ch := &objecttree.Change{}
|
ch := &objecttree.Change{}
|
||||||
|
ch.PreviousIds = []string{"someId"}
|
||||||
ch.Model = &spacesyncproto.SettingsData{
|
ch.Model = &spacesyncproto.SettingsData{
|
||||||
Content: []*spacesyncproto.SpaceSettingsContent{
|
Content: []*spacesyncproto.SpaceSettingsContent{
|
||||||
{Value: &spacesyncproto.SpaceSettingsContent_ObjectDelete{
|
{Value: &spacesyncproto.SpaceSettingsContent_ObjectDelete{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user