github.com/weaviate/weaviate@v1.24.6/test/modules/sum-transformers/sum_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 import ( 15 "os" 16 "testing" 17 18 "github.com/stretchr/testify/assert" 19 "github.com/weaviate/weaviate/entities/models" 20 "github.com/weaviate/weaviate/test/helper" 21 graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql" 22 "github.com/weaviate/weaviate/test/helper/sample-schema/books" 23 ) 24 25 func Test_SUMTransformers(t *testing.T) { 26 helper.SetupClient(os.Getenv(weaviateEndpoint)) 27 tests := []struct { 28 name string 29 class *models.Class 30 }{ 31 { 32 name: "with module config for sum-transformers module", 33 class: books.ClassContextionaryVectorizerWithSumTransformers(), 34 }, 35 { 36 name: "without module config", 37 class: books.ClassContextionaryVectorizer(), 38 }, 39 } 40 for _, tt := range tests { 41 t.Run(tt.name, func(t *testing.T) { 42 booksClass := tt.class 43 helper.CreateClass(t, booksClass) 44 defer helper.DeleteClass(t, booksClass.Class) 45 46 t.Run("add data to Books schema", func(t *testing.T) { 47 for _, book := range books.Objects() { 48 helper.CreateObject(t, book) 49 helper.AssertGetObjectEventually(t, book.Class, book.ID) 50 } 51 }) 52 53 t.Run("query Books data with nearText", func(t *testing.T) { 54 result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, ` 55 { 56 Get { 57 Books(where: { 58 operator: Equal 59 path:["title"] 60 valueText: "Dune" 61 }){ 62 title 63 _additional { 64 summary (properties:["description"]) { 65 property 66 result 67 } 68 } 69 } 70 } 71 } 72 `) 73 books := result.Get("Get", "Books").AsSlice() 74 expected := []interface{}{ 75 map[string]interface{}{ 76 "title": "Dune", 77 "_additional": map[string]interface{}{ 78 "summary": []interface{}{ 79 map[string]interface{}{ 80 "property": "description", 81 "result": "Dune is a 1965 epic science fiction novel by American author Frank Herbert." + 82 "It is the first novel in the Dune series by Frank Herbert, and the first in the \"Dune\" series of books." + 83 "It was published in the United States by Simon & Schuster in 1965.", 84 }, 85 }, 86 }, 87 }, 88 } 89 assert.ElementsMatch(t, expected, books) 90 }) 91 }) 92 } 93 }