github.com/weaviate/weaviate@v1.24.6/test/acceptance/objects/network_refs_test.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package test
    13  
    14  // func TestCanAddSingleNetworkRef(t *testing.T) {
    15  // 	networkRefID := "711da979-4b0b-41e2-bcb8-fcc03554c7c8"
    16  // 	thingID := assertCreateThing(t, "TestThing", map[string]interface{}{
    17  // 		"testReference": []interface{}{
    18  // 			map[string]interface{}{
    19  // 				"beacon": "weaviate://RemoteWeaviateForAcceptanceTest/things/" + networkRefID,
    20  // 			},
    21  // 		},
    22  // 	})
    23  
    24  // 	t.Run("it can query the resource again to verify the cross ref was added", func(t *testing.T) {
    25  // 		thing := assertGetThingEventually(t, thingID)
    26  // 		list := thing.Schema.(map[string]interface{})["testReference"]
    27  // 		require.NotNil(t, list, "cross-ref is present")
    28  // 		cref := list.([]interface{})[0].(map[string]interface{})
    29  // 		assert.Equal(t, cref["beacon"], "weaviate://RemoteWeaviateForAcceptanceTest/things/"+networkRefID)
    30  // 	})
    31  
    32  // 	t.Run("an implicit schema update has happened, we now include the network ref's class", func(t *testing.T) {
    33  // 		schema := assertGetSchema(t)
    34  // 		require.NotNil(t, schema.Things)
    35  // 		class := assertClassInSchema(t, schema.Things, "TestThing")
    36  // 		prop := assertPropertyInClass(t, class, "testReference")
    37  // 		expectedDataType := []string{"TestThingTwo", "RemoteWeaviateForAcceptanceTest/Instruments"}
    38  // 		assert.Equal(t, expectedDataType, prop.DataType, "prop should have old and newly added dataTypes")
    39  // 	})
    40  
    41  // 	t.Run("it can query the reference through the graphql api", func(t *testing.T) {
    42  // 		result := graphql.AssertGraphQL(t, helper.RootAuth,
    43  // 			"{  Get { Things { TestThing { TestReference { ... on RemoteWeaviateForAcceptanceTest__Instruments { name } } } } } }")
    44  // 		things := result.Get("Get", "Things", "TestThing").AsSlice()
    45  // 		assert.Contains(t, things, parseJSONObj(`{"TestReference":[{"name": "Talkbox"}]}`))
    46  // 	})
    47  // }
    48  
    49  // func TestCanPatchNetworkRef(t *testing.T) {
    50  // 	t.Parallel()
    51  
    52  // 	thingID := assertCreateThing(t, "TestThing", nil)
    53  // 	assertGetThingEventually(t, thingID)
    54  // 	networkRefID := "711da979-4b0b-41e2-bcb8-fcc03554c7c8"
    55  
    56  // 	op := "add"
    57  // 	path := "/schema/testReference"
    58  
    59  // 	patch := &models.PatchDocument{
    60  // 		Op:   &op,
    61  // 		Path: &path,
    62  // 		Value: []interface{}{
    63  // 			map[string]interface{}{
    64  // 				"beacon": "weaviate://RemoteWeaviateForAcceptanceTest/things/" + networkRefID,
    65  // 			},
    66  // 		},
    67  // 	}
    68  
    69  // 	t.Run("it can apply the patch", func(t *testing.T) {
    70  // 		params := things.NewThingsPatchParams().
    71  // 			WithBody([]*models.PatchDocument{patch}).
    72  // 			WithID(thingID)
    73  // 		patchResp, err := helper.Client(t).Things.ThingsPatch(params, nil)
    74  // 		helper.AssertRequestOk(t, patchResp, err, nil)
    75  // 	})
    76  
    77  // 	t.Run("it can query the resource again to verify the cross ref was added", func(t *testing.T) {
    78  // 		patchedThing := assertGetThing(t, thingID)
    79  // 		list := patchedThing.Schema.(map[string]interface{})["testReference"]
    80  // 		require.NotNil(t, list, "cross-ref is present")
    81  // 		cref := list.([]interface{})[0].(map[string]interface{})
    82  // 		assert.Equal(t, cref["beacon"], "weaviate://RemoteWeaviateForAcceptanceTest/things/"+networkRefID)
    83  // 	})
    84  
    85  // 	t.Run("an implicit schema update has happened, we now include the network ref's class", func(t *testing.T) {
    86  // 		schema := assertGetSchema(t)
    87  // 		require.NotNil(t, schema.Things)
    88  // 		class := assertClassInSchema(t, schema.Things, "TestThing")
    89  // 		prop := assertPropertyInClass(t, class, "testReference")
    90  // 		expectedDataType := []string{"TestThingTwo", "RemoteWeaviateForAcceptanceTest/Instruments"}
    91  // 		assert.Equal(t, expectedDataType, prop.DataType, "prop should have old and newly added dataTypes")
    92  // 	})
    93  // }
    94  
    95  // func parseJSONObj(text string) interface{} {
    96  // 	var result interface{}
    97  // 	err := json.Unmarshal([]byte(text), &result)
    98  
    99  // 	if err != nil {
   100  // 		panic(err)
   101  // 	}
   102  
   103  // 	return result
   104  // }