github.com/weaviate/weaviate@v1.24.6/modules/qna-openai/ask/graphql_argument_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 ask
    13  
    14  import (
    15  	"testing"
    16  
    17  	"github.com/stretchr/testify/assert"
    18  	"github.com/tailor-inc/graphql"
    19  )
    20  
    21  func TestAskGraphQLArgument(t *testing.T) {
    22  	t.Run("should generate ask argument properly", func(t *testing.T) {
    23  		// given
    24  		prefix := "Prefix"
    25  		classname := "Class"
    26  		// when
    27  		ask := New(nil).askArgument(prefix, classname)
    28  
    29  		// then
    30  		// the built graphQL field needs to support this structure:
    31  		// ask {
    32  		//   question: "question?",
    33  		//   properties: ["prop1", "prop2"]
    34  		// }
    35  		assert.NotNil(t, ask)
    36  		assert.Equal(t, "QnATransformersPrefixClassAskInpObj", ask.Type.Name())
    37  		askFields, ok := ask.Type.(*graphql.InputObject)
    38  		assert.True(t, ok)
    39  		assert.NotNil(t, askFields)
    40  		assert.Equal(t, 2, len(askFields.Fields()))
    41  		fields := askFields.Fields()
    42  		question := fields["question"]
    43  		questionNonNull, questionNonNullOK := question.Type.(*graphql.NonNull)
    44  		assert.True(t, questionNonNullOK)
    45  		assert.Equal(t, "String", questionNonNull.OfType.Name())
    46  		assert.NotNil(t, question)
    47  		properties := fields["properties"]
    48  		propertiesList, propertiesListOK := properties.Type.(*graphql.List)
    49  		assert.True(t, propertiesListOK)
    50  		assert.Equal(t, "String", propertiesList.OfType.Name())
    51  	})
    52  }