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