update to use roots event constructor and new created at type.
This commit is contained in:
+21
-25
@@ -9,9 +9,7 @@ import (
|
||||
|
||||
// Helpers
|
||||
|
||||
func intPtr(i int) *int {
|
||||
return &i
|
||||
}
|
||||
func intPtr(i int) *int { ptr := i; return &ptr }
|
||||
|
||||
func expectEqualHeartwoodFilters(t *testing.T, got, want HeartwoodFilter) {
|
||||
t.Helper()
|
||||
@@ -61,11 +59,11 @@ func TestMarshalJSON(t *testing.T) {
|
||||
{
|
||||
name: "root fields only",
|
||||
filter: HeartwoodFilter{
|
||||
Root: roots.Filter{
|
||||
IDs: []string{"abc"},
|
||||
Kinds: []int{1},
|
||||
Since: intPtr(1000),
|
||||
},
|
||||
Root: roots.NewFilter(
|
||||
roots.WithIDs([]string{"abc"}),
|
||||
roots.WithKinds([]int{1}),
|
||||
roots.WithSince(1000),
|
||||
),
|
||||
},
|
||||
expected: `{"ids":["abc"],"kinds":[1],"since":1000}`,
|
||||
},
|
||||
@@ -88,9 +86,9 @@ func TestMarshalJSON(t *testing.T) {
|
||||
{
|
||||
name: "root and graph present",
|
||||
filter: HeartwoodFilter{
|
||||
Root: roots.Filter{
|
||||
IDs: []string{"abc"},
|
||||
},
|
||||
Root: roots.NewFilter(
|
||||
roots.WithIDs([]string{"abc"}),
|
||||
),
|
||||
Graph: []GraphFilter{
|
||||
{Kinds: []json.RawMessage{json.RawMessage(`1`)}},
|
||||
},
|
||||
@@ -128,11 +126,11 @@ func TestUnmarshalJSON(t *testing.T) {
|
||||
name: "root fields only",
|
||||
input: `{"ids":["abc"],"kinds":[1],"since":1000}`,
|
||||
expected: HeartwoodFilter{
|
||||
Root: roots.Filter{
|
||||
IDs: []string{"abc"},
|
||||
Kinds: []int{1},
|
||||
Since: intPtr(1000),
|
||||
},
|
||||
Root: roots.NewFilter(
|
||||
roots.WithIDs([]string{"abc"}),
|
||||
roots.WithKinds([]int{1}),
|
||||
roots.WithSince(1000),
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -155,9 +153,9 @@ func TestUnmarshalJSON(t *testing.T) {
|
||||
name: "root and graph present",
|
||||
input: `{"ids":["abc"],"graph":[{"kinds":[1]}]}`,
|
||||
expected: HeartwoodFilter{
|
||||
Root: roots.Filter{
|
||||
IDs: []string{"abc"},
|
||||
},
|
||||
Root: roots.NewFilter(
|
||||
roots.WithIDs([]string{"abc"}),
|
||||
),
|
||||
Graph: []GraphFilter{
|
||||
{Kinds: []json.RawMessage{json.RawMessage(`1`)}},
|
||||
},
|
||||
@@ -167,12 +165,10 @@ func TestUnmarshalJSON(t *testing.T) {
|
||||
name: "graph is removed from root extensions",
|
||||
input: `{"ids":["abc"],"graph":[{"kinds":[1]}],"search":"bitcoin"}`,
|
||||
expected: HeartwoodFilter{
|
||||
Root: roots.Filter{
|
||||
IDs: []string{"abc"},
|
||||
Extensions: map[string]json.RawMessage{
|
||||
"search": json.RawMessage(`"bitcoin"`),
|
||||
},
|
||||
},
|
||||
Root: roots.NewFilter(
|
||||
roots.WithIDs([]string{"abc"}),
|
||||
roots.WithExtension("search", json.RawMessage(`"bitcoin"`)),
|
||||
),
|
||||
Graph: []GraphFilter{
|
||||
{Kinds: []json.RawMessage{json.RawMessage(`1`)}},
|
||||
},
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ func EventToSubgraph(e roots.Event, p ExpanderPipeline) *EventSubgraph {
|
||||
|
||||
// Core pipeline functions
|
||||
|
||||
func newEventNode(eventID string, createdAt int, kind int, content string) *Node {
|
||||
func newEventNode(eventID string, createdAt int64, kind int, content string) *Node {
|
||||
eventNode := NewEventNode(eventID)
|
||||
eventNode.Props["created_at"] = createdAt
|
||||
eventNode.Props["kind"] = kind
|
||||
|
||||
+6
-6
@@ -15,13 +15,13 @@ var ids = map[string]string{
|
||||
"d": "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
|
||||
}
|
||||
|
||||
var static = roots.Event{
|
||||
CreatedAt: 1000,
|
||||
Kind: 1,
|
||||
Content: "hello",
|
||||
}
|
||||
var static = roots.NewEvent(
|
||||
roots.WithCreatedAt(1000),
|
||||
roots.WithKind(1),
|
||||
roots.WithContent("hello"),
|
||||
)
|
||||
|
||||
func newFullEventNode(id string, createdAt, kind int, content string) *Node {
|
||||
func newFullEventNode(id string, createdAt int64, kind int, content string) *Node {
|
||||
n := NewEventNode(id)
|
||||
n.Props["created_at"] = createdAt
|
||||
n.Props["kind"] = kind
|
||||
|
||||
Reference in New Issue
Block a user