53ea7d34e6
Start adding Textract + UUID changes * base * startclient * ts * short * tests
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package result
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"queryorchestration/internal/database/repository"
|
|
resultprocessor "queryorchestration/internal/query/result/processor"
|
|
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
|
"queryorchestration/internal/serviceconfig"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetValueByType(t *testing.T) {
|
|
_, err := getValueByType(resultprocessor.Type(-1), "example_val")
|
|
assert.Error(t, err)
|
|
pro, err := getValueByType(resultprocessor.TypeContextFull, "example_context")
|
|
require.NoError(t, err)
|
|
assert.NotNil(t, pro)
|
|
assert.Equal(t, "example_context", pro.GetStoreValue())
|
|
pro, err = getValueByType(resultprocessor.TypeJsonExtractor, "example_json")
|
|
require.NoError(t, err)
|
|
assert.NotNil(t, pro)
|
|
assert.Equal(t, "example_json", pro.GetStoreValue())
|
|
}
|
|
|
|
func TestGetValueWithVersion(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
pool, err := pgxmock.NewPool()
|
|
require.NoError(t, err)
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
cfg.DBPool = pool
|
|
cfg.DBQueries = repository.New(pool)
|
|
|
|
svc := New(cfg, &Services{})
|
|
|
|
params := &GetValueWithVersionParams{
|
|
Type: resultprocessor.TypeJsonExtractor,
|
|
QueryID: uuid.New(),
|
|
DocumentID: uuid.New(),
|
|
QueryVersion: 1,
|
|
}
|
|
|
|
value := "exaple_value"
|
|
pool.ExpectQuery("name: GetResultValueWithVersion :one").WithArgs(¶ms.QueryID, ¶ms.QueryVersion, ¶ms.DocumentID).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "value"}).
|
|
AddRow(&uuid.UUID{}, &value),
|
|
)
|
|
|
|
val, err := svc.GetValueWithVersion(ctx, params)
|
|
require.NoError(t, err)
|
|
v := jsonextractor.NewResult(value)
|
|
assert.Equal(t, v, val)
|
|
assert.Equal(t, value, v.GetStoreValue())
|
|
}
|