1package authoring23import (4 "strings"5 "testing"67 "github.com/FelineStateMachine/atlas/format/vnext"8)910func TestAssembleSeedsDeclaredFeatureSetContracts(t *testing.T) {11 project := contractTestProject()12 project.FeatureSets = append(project.FeatureSets, FeatureSetContract{13 ID: "areas", Title: "Sample Areas", SemanticType: "region", Geometry: "area",14 })15 volume, err := assemble(project, nil)16 if err != nil {17 t.Fatal(err)18 }19 world := volume.Worlds[0]20 if len(world.FeatureSets) != 2 {21 t.Fatalf("feature sets = %d, want two declared empty sets", len(world.FeatureSets))22 }23 places := world.FeatureSets[1]24 if places.ID != "sample-region/set/places" || len(places.Properties) != 1 || len(places.Features) != 0 {25 t.Fatalf("places contract = %+v", places)26 }27 if !hasGeometryClaim(places.Claims, "point") {28 t.Fatalf("places claims = %+v, want point contract", places.Claims)29 }30 wantFieldID := vnext.IDFromName(project.SchemaNamespace, "feature.places.kind")31 if places.Properties[0].ID != wantFieldID {32 t.Fatalf("field ID = %s, want source-independent %s", places.Properties[0].ID, wantFieldID)33 }34}3536func TestAssembleChecksRequiredPropertiesAfterFusion(t *testing.T) {37 project := contractTestProject()38 geometry := vnext.Geometry{Kind: vnext.GeometryPoint, Parts: []vnext.GeometryPart{{Rings: [][]vnext.Position{{{1, 1}}}}}}39 first := observation{SourceOrder: 0, Source: "primary", NativeID: "one", FeatureSet: "places", Title: "Sample Place", Geometry: geometry, Values: map[string]vnext.Value{}}40 second := observation{SourceOrder: 1, Source: "secondary", NativeID: "one", FeatureSet: "places", Title: "Sample Place", Geometry: geometry, Values: map[string]vnext.Value{"kind": vnext.StringValue("sample")}}41 if _, err := assemble(project, []observation{first}); err == nil || !strings.Contains(err.Error(), "omits required property kind") {42 t.Fatalf("assemble = %v, want required-property refusal", err)43 }44 volume, err := assemble(project, []observation{first, second})45 if err != nil {46 t.Fatal(err)47 }48 feature := volume.Worlds[0].FeatureSets[0].Features[0]49 if len(feature.Properties) != 1 || feature.Properties[0].Value.String != "sample" || len(feature.Provenance) != 2 {50 t.Fatalf("fused feature = %+v", feature)51 }52}5354func contractTestProject() Project {55 return Project{56 Schema: ProjectSchema, SchemaNamespace: "example.invalid/atlas/sample-region", ID: "sample-region", Title: "Sample Region",57 Target: Target{World: "sample-region", Title: "Sample Region", CoordinateSpace: CoordinateSpace{58 ID: "sample-space", Kind: "projected", Unit: "metre", Definition: "sample grid", Extent: [4]float64{0, 0, 10, 10},59 }},60 FeatureSets: []FeatureSetContract{{61 ID: "places", Title: "Sample Places", SemanticType: "place", Geometry: "point",62 Properties: []PropertyContract{{ID: "kind", Name: "Kind", Type: "string"}},63 }},64 Presentation: Presentation{ID: "default", Title: "Default"},65 }66}