Project sequence evidence through item mappings
This commit is contained in:
@@ -525,6 +525,82 @@ func TestLoadMainItemPlacementKeepsItsHelpersInTheItem(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectAcquiredDestinationsUsesMappedSequenceItemIndex(t *testing.T) {
|
||||
child := &composedDocument{}
|
||||
childScope := acquisitionScope{contributions: []acquiredContribution{{
|
||||
source: SourceInfo{ID: "nested-source"}, destination: Keys("settings"),
|
||||
}}}
|
||||
child.acquisition = []acquisitionScope{childScope}
|
||||
composed := &composedDocument{sequenceRanges: []sequenceRange{{
|
||||
sourceIndex: 0, path: Keys("records"), start: 0, end: 1,
|
||||
items: []sequenceItemProjection{{inputIndex: 0, outputIndex: 2}},
|
||||
}}}
|
||||
scope := acquisitionScope{contributions: []acquiredContribution{{
|
||||
source: SourceInfo{ID: "outer-source", placementMode: placementModeSequenceItem},
|
||||
destination: Keys("records"), nested: child,
|
||||
}}}
|
||||
sources := []SourceInfo{{ID: "outer-source"}, {ID: "nested-source"}}
|
||||
|
||||
projectAcquiredDestinations(composed, scope, sources)
|
||||
if got, want := sources[0].Destination.String(), "/records"; got != want {
|
||||
t.Errorf("outer source destination = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := sources[1].Destination.String(), "/records/2/settings"; got != want {
|
||||
t.Errorf("nested source destination = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectNestedEvidenceUsesMappedSequenceItemIndex(t *testing.T) {
|
||||
outer := historyApplication{
|
||||
value: parseCompositionDocument(t, "outer-source", "records: [{id: outer}]\n"),
|
||||
sequences: []sequenceHistoryContribution{{
|
||||
path: Keys("records"), mode: sequenceHistoryMapped,
|
||||
items: []sequenceItemProjection{{inputIndex: 0, outputIndex: 2}},
|
||||
}},
|
||||
}
|
||||
outer.sequencesByPath = indexSequenceHistoryContributions(outer.sequences)
|
||||
nestedRoot := parseCompositionDocument(t, "nested-source", "settings: {value: nested}\n")
|
||||
nestedOrigin := Origin{Layer: LayerBase, Locations: []Location{{SourceID: "nested-source"}}}
|
||||
nested := &composedDocument{
|
||||
root: nestedRoot, applications: []historyApplication{{value: nestedRoot}},
|
||||
origins: map[string]Origin{"/settings/value": nestedOrigin},
|
||||
}
|
||||
scope := acquisitionScope{contributions: []acquiredContribution{{
|
||||
source: SourceInfo{ID: "outer-source"}, destination: Keys("records"), nested: nested,
|
||||
}}}
|
||||
composed := &composedDocument{
|
||||
applications: []historyApplication{outer},
|
||||
sequenceRanges: []sequenceRange{{
|
||||
sourceIndex: 0, path: Keys("records"), start: 0, end: 1,
|
||||
items: []sequenceItemProjection{{inputIndex: 0, outputIndex: 2}},
|
||||
}},
|
||||
origins: make(map[string]Origin),
|
||||
}
|
||||
|
||||
projectNestedEvidence(composed, scope)
|
||||
if got, want := composed.applications[1].path.String(), "/records/2"; got != want {
|
||||
t.Fatalf("nested history application path = %q, want %q", got, want)
|
||||
}
|
||||
if origin := composed.origins["/records/2/settings/value"]; len(origin.Locations) != 1 || origin.Locations[0].SourceID != "nested-source" {
|
||||
t.Fatalf("nested origin = %#v", origin)
|
||||
}
|
||||
query := Keys("records").Index(2).Key("settings").Key("value")
|
||||
if operation, relevant := applicationOperationPath(composed.applications[1], query, nil); !relevant || operation.String() != query.String() {
|
||||
t.Fatalf("nested historical query = %s, %v", operation.String(), relevant)
|
||||
}
|
||||
replayed := parseCompositionDocument(t, "lower", "records: [{id: first}, {id: middle}, {id: last}]\n")
|
||||
for _, application := range composed.applications {
|
||||
applyHistoryApplication(&replayed, application, new(mappingIndex))
|
||||
}
|
||||
if value, present := documentAtPath(replayed, query); !present || value.Text != "nested" {
|
||||
t.Fatalf("replayed nested value = %#v, %v", value, present)
|
||||
}
|
||||
composed.applications[1].path.segments[0].key = "detached"
|
||||
if got := nested.applications[0].path.String(); got != "" {
|
||||
t.Fatalf("projected nested history path aliases its source: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestItemImportCanJoinAnAuthoredListUnderRegisteredComposition(t *testing.T) {
|
||||
t.Parallel()
|
||||
type config struct {
|
||||
|
||||
Reference in New Issue
Block a user