-
Notifications
You must be signed in to change notification settings - Fork 54
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
GO-3964 ListRelationsByValue RPC #1552
Merged
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cd1d4ee
GO-3964 ListRelationsByValue rpc
KirillSto fe9c4cd
GO-3964 Add error check on id2sbtype
KirillSto 439c4e0
GO-3964 Add QueryAndProcess WIP
KirillSto 2da1ad5
GO-3964 Fix tests
KirillSto 92999ad
GO-3964 Introduce details service
KirillSto 708b51e
GO-3964 Merge main
KirillSto bdfdbdb
GO-3964 Add mock
KirillSto 2c7139d
GO-3964 Add tests on service
KirillSto 2c5715e
GO-3964 Rename package
KirillSto f5c7561
GO-3964 Merge main
KirillSto 75f8364
GO-3964 Fix comments
KirillSto f03005c
GO-3964 Merge main
KirillSto b1d7177
GO-3964 Exclude unused import
KirillSto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package block | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/gogo/protobuf/types" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/anyproto/anytype-heart/core/domain" | ||
"github.com/anyproto/anytype-heart/pkg/lib/bundle" | ||
"github.com/anyproto/anytype-heart/pkg/lib/localstore/addr" | ||
"github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore" | ||
"github.com/anyproto/anytype-heart/pkg/lib/pb/model" | ||
"github.com/anyproto/anytype-heart/util/pbtypes" | ||
) | ||
|
||
const spaceId = "spaceId" | ||
|
||
func relationObject(key domain.RelationKey, format model.RelationFormat) objectstore.TestObject { | ||
return objectstore.TestObject{ | ||
bundle.RelationKeyId: pbtypes.String(key.URL()), | ||
bundle.RelationKeySpaceId: pbtypes.String(spaceId), | ||
bundle.RelationKeyLayout: pbtypes.Float64(float64(model.ObjectType_relation)), | ||
bundle.RelationKeyRelationKey: pbtypes.String(key.String()), | ||
bundle.RelationKeyRelationFormat: pbtypes.Int64(int64(format)), | ||
} | ||
} | ||
|
||
func TestService_ListRelationsWithValue(t *testing.T) { | ||
store := objectstore.NewStoreFixture(t) | ||
store.AddObjects(t, []objectstore.TestObject{ | ||
// relations | ||
relationObject(bundle.RelationKeyLastModifiedDate, model.RelationFormat_date), | ||
relationObject(bundle.RelationKeyAddedDate, model.RelationFormat_date), | ||
relationObject(bundle.RelationKeyCreatedDate, model.RelationFormat_date), | ||
relationObject(bundle.RelationKeyLinks, model.RelationFormat_object), | ||
relationObject(bundle.RelationKeyName, model.RelationFormat_longtext), | ||
relationObject(bundle.RelationKeyIsHidden, model.RelationFormat_checkbox), | ||
relationObject(bundle.RelationKeyIsFavorite, model.RelationFormat_checkbox), | ||
relationObject("daysTillSummer", model.RelationFormat_number), | ||
relationObject(bundle.RelationKeyCoverX, model.RelationFormat_number), | ||
{ | ||
bundle.RelationKeyId: pbtypes.String("obj1"), | ||
bundle.RelationKeySpaceId: pbtypes.String(spaceId), | ||
bundle.RelationKeyCreatedDate: pbtypes.Int64(time.Now().Add(-5 * time.Minute).Unix()), | ||
bundle.RelationKeyAddedDate: pbtypes.Int64(time.Now().Add(-3 * time.Minute).Unix()), | ||
bundle.RelationKeyLastModifiedDate: pbtypes.Int64(time.Now().Add(-1 * time.Minute).Unix()), | ||
bundle.RelationKeyIsFavorite: pbtypes.Bool(true), | ||
"daysTillSummer": pbtypes.Int64(300), | ||
bundle.RelationKeyLinks: pbtypes.StringList([]string{"obj2", "obj3"}), | ||
}, | ||
{ | ||
bundle.RelationKeyId: pbtypes.String("obj2"), | ||
bundle.RelationKeySpaceId: pbtypes.String(spaceId), | ||
bundle.RelationKeyName: pbtypes.String(addr.TimeToID(time.Now())), | ||
bundle.RelationKeyCreatedDate: pbtypes.Int64(time.Now().Add(-24*time.Hour - 5*time.Minute).Unix()), | ||
bundle.RelationKeyAddedDate: pbtypes.Int64(time.Now().Add(-24*time.Hour - 3*time.Minute).Unix()), | ||
bundle.RelationKeyLastModifiedDate: pbtypes.Int64(time.Now().Add(-1 * time.Minute).Unix()), | ||
bundle.RelationKeyCoverX: pbtypes.Int64(300), | ||
}, | ||
{ | ||
bundle.RelationKeyId: pbtypes.String("obj3"), | ||
bundle.RelationKeySpaceId: pbtypes.String(spaceId), | ||
bundle.RelationKeyIsHidden: pbtypes.Bool(true), | ||
bundle.RelationKeyCreatedDate: pbtypes.Int64(time.Now().Add(-3 * time.Minute).Unix()), | ||
bundle.RelationKeyLastModifiedDate: pbtypes.Int64(time.Now().Unix()), | ||
bundle.RelationKeyIsFavorite: pbtypes.Bool(true), | ||
bundle.RelationKeyCoverX: pbtypes.Int64(300), | ||
}, | ||
}) | ||
|
||
bs := Service{objectStore: store} | ||
|
||
for _, tc := range []struct { | ||
name string | ||
value *types.Value | ||
expectedKeys []string | ||
expectedCounters []int64 | ||
}{ | ||
{ | ||
"date object - today", | ||
pbtypes.String(addr.TimeToID(time.Now())), | ||
[]string{bundle.RelationKeyAddedDate.String(), bundle.RelationKeyCreatedDate.String(), bundle.RelationKeyLastModifiedDate.String(), bundle.RelationKeyName.String()}, | ||
[]int64{1, 2, 3, 1}, | ||
}, | ||
{ | ||
"date object - yesterday", | ||
pbtypes.String(addr.TimeToID(time.Now().Add(-24 * time.Hour))), | ||
[]string{bundle.RelationKeyAddedDate.String(), bundle.RelationKeyCreatedDate.String()}, | ||
[]int64{1, 1}, | ||
}, | ||
{ | ||
"number", | ||
pbtypes.Int64(300), | ||
[]string{bundle.RelationKeyCoverX.String(), "daysTillSummer"}, | ||
[]int64{2, 1}, | ||
}, | ||
{ | ||
"bool", | ||
pbtypes.Bool(true), | ||
[]string{bundle.RelationKeyIsFavorite.String(), bundle.RelationKeyIsHidden.String()}, | ||
[]int64{2, 1}, | ||
}, | ||
{ | ||
"string list", | ||
pbtypes.StringList([]string{"obj2", "obj3"}), | ||
[]string{bundle.RelationKeyLinks.String()}, | ||
[]int64{1}, | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
keys, counters, err := bs.ListRelationsWithValue(spaceId, tc.value) | ||
assert.NoError(t, err) | ||
assert.Equal(t, tc.expectedKeys, keys) | ||
assert.Equal(t, tc.expectedCounters, counters) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is it time for relationService?
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.
Yes 😌